0

I need to automate a registration form and create a new account and then use the same account details to login with newly created account number and password.I need to do this in one scenario.

Feature: create new user and capture the username, password and try to login with those details.

 Scenario: test
    Given I am on xyz.com
    When I click on register
    Then I will enter required details for registration
    Then I will click on submit
    And I will enter new account details to login to test.
Samantha
  • 357
  • 2
  • 7
  • 17

3 Answers3

0

I hope that can help you

Feature: a sample of test

  Scenario: test
    Given I am on "xyz.com"
    When I click on register
    Then I will enter required details for registration
    Then I will click on submit
    And I will enter new account details to login to test
#############Steps
Given(/^I am on "([^"]*)"$/) do |website|
  visit website
end

When(/^I click on register$/) do
  find(:xpath, "registerbutton").click
end

Then(/^I will enter required details for registration$/) do
  @username = "xpto"
  @password = "xptopassword"

  fill_in('camp_name', with: @username)
  fill_in('camp_name', with: @password)
  fill_in('othercamps', with: "etcs")
  #repeat for all the camps
end

Then(/^I will click on submit$/) do
  find(:xpath, "submit_button").click
end

Then(/^I will enter new account details to login to test$/) do
  visit "www.myloginpage.com"
  fill_in("camp_username", with: @username)
  fill_in("camp_password", with: @password)
  find(:xpath, "login_button").click
  page.should have_content ("LoggedPAge")
end

You can use the selenium IDE (extension of firefox) to find all xpath.

I don't like that solution, for a better implementation my recommendation is to read about page objects (siteprism) and scenario outline (cucumber) it's a start for a better code.

0

I would not do that in one scenario unless it is one flow. And I wouldn't go to xyz.com, and I wouldn't click on things because that isn't 'behavior. Page objects will help you.

Scenario: Register a new account
Given I do not have an account
When I register a new account
Then I can use those credentials to access the site

Then I'd create appropriate steps

Given(/^I do not have an account%/) do
  @credentials = get_unique_credentials
  @browser = Watir::Browser.new :firefox
end

When(/^I register a new account$/) do
  visit RegistrationPage do |page|
    page.name = @credentials[0]
    page.password = @credentials[1]
    page.register
  end
end

Then(/^I can use those credentials to access the site$/) do
  visit LoginPage do |page|
    page.name = @credentials[0]
    page.password = @credentials[1]
    page.login
  end
  on HomePage do |page|
    expect(page.something).to exist
  end
end
Dave McNulla
  • 2,006
  • 16
  • 23
0

The simple answer is that you don't have to do this in one scenario.

You are doing two things here:

  1. Registering
  2. Signing in

Lets deal with the second first.

To sign in we have to be registered so we get a scenario like

Scenario: Sign in
  Given I am registered
  When I sign in
  Then I should be signed in

But how do we register?

Scenario: Register
  Given I am a new user
  When I register
  Then I should be registered

Now how do we implement this

Given "I am a new user" do
  @i = create_new_user
end

When "I register" do 
  register as: @i
end

Then "I should be registered" do
  # Go look at something to see that we are registered
end

When this works we can now implement

Given "I am registered" do
  @i = create_new_user
  register as: @i
end

We can do this because we have created the ability to register by getting our 'Register' scenario to work.

And now we can work on signing in

This is how BDD with Cucumber works. You work on implementing a bit of behaviour (generally in a When, e.g. registering). Then you use that behaviour (in Givens) so you can get to a place where you can work on implementing some new behaviour (signing in)

Hope thats helps

A bit more detail:

The methods create_new_user, register are called helper methods. These are key to writing simpler step definitions. In ruby you might define them as follows

module SignupStepHelper
  def register
    ...
  def create_new_user
    ...
end

World SignupStepHelper # makes it possible to call the methods in you step defs.
diabolist
  • 3,990
  • 1
  • 11
  • 15