0

我需要自动化注册表单并创建一个新帐户,然后使用相同的帐户详细信息使用新创建的帐号和密码登录。我需要在一个场景中执行此操作。

功能:创建新用户并获取用户名、密码并尝试使用这些详细信息登录。

 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.
4

3 回答 3

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.

于 2016-06-03T20:39:27.460 回答
0

我不会在一种情况下这样做,除非它是一个流程。我不会去 xyz.com,也不会点击东西,因为那不是“行为”。页面对象会帮助你。

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

然后我会创建适当的步骤

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
于 2016-06-04T00:01:23.530 回答
0

简单的答案是您不必在一种情况下执行此操作。

你在这里做两件事:

  1. 注册
  2. 登录中

让我们先处理第二个。

要登录,我们必须注册,所以我们会得到一个类似的场景

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

但是我们如何注册呢?

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

现在我们如何实现这个

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

当这可行时,我们现在可以实现

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

我们可以这样做,因为我们已经通过让我们的“注册”场景工作来创建注册的能力。

现在我们可以登录了

这就是 BDD 与 Cucumber 的工作原理。您致力于实现一些行为(通常在何时,例如注册)。然后您使用该行为(在 Givens 中),这样您就可以到达一个可以实施一些新行为的地方(登录)

希望那有帮助

更详细一点:

create_new_user、register 方法称为辅助方法。这些是编写更简单的步骤定义的关键。在 ruby​​ 中,您可以将它们定义如下

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

World SignupStepHelper # makes it possible to call the methods in you step defs.
于 2016-06-08T13:09:25.760 回答