Cucumber 如何测试需要从安全短语中输入两个随机字符的表单?
我需要测试一个两阶段登录系统,该系统首先询问您的电子邮件地址和密码,然后向用户提供包含[a-zA-Z0-9]的两个选择列表。下拉列表旁边的标签采用“从安全短语中选择字符X”的形式,其中X是来自已知安全短语的随机字符索引 我不希望为了验收测试而存根代码,那么有没有可能用Cumber编写一个匹配器,在我们知道整个短语的情况下,在两个列表中分别选择所需的字符 以下是我到目前为止的场景和涉及的步骤:Cucumber 如何测试需要从安全短语中输入两个随机字符的表单?,cucumber,bdd,webrat,Cucumber,Bdd,Webrat,我需要测试一个两阶段登录系统,该系统首先询问您的电子邮件地址和密码,然后向用户提供包含[a-zA-Z0-9]的两个选择列表。下拉列表旁边的标签采用“从安全短语中选择字符X”的形式,其中X是来自已知安全短语的随机字符索引 我不希望为了验收测试而存根代码,那么有没有可能用Cumber编写一个匹配器,在我们知道整个短语的情况下,在两个列表中分别选择所需的字符 以下是我到目前为止的场景和涉及的步骤: Scenario: valid login email, password and secret phr
Scenario: valid login email, password and secret phrase takes me to the dashboard
Given I am not logged in
When I log in as "admin@example.com"
Then I should be on the dashboard page
And I should see "Your Dashboard"
When /^I log in as "([^\"]*)"$/ do |login|
visit path_to('Login page')
fill_in "Email", :with => login
fill_in "Password", :with => "Password123"
click_button "Log in"
response.should contain("Please verify some characters from your security phrase")
select "a", :from => "Select character X of your security phrase"
select "b", :from => "Select character Y of your security phrase"
click_button "Submit"
end
例如,如果安全短语为'Secret123',X=3,Y=8,则上述必须产生以下等价物:
select "c", :from => "Select character 3 of your security phrase"
select "2", :from => "Select character 8 of your security phrase"
实际页面中的数字X和Y分别位于span#svc_1和span#svc_2内
谢谢,经过一番折腾,我终于明白了。将其记录在此处,以便在相同情况下帮助其他人。通常情况下_steps.rb:
When /^I log in as "([^\"]*)"$/ do |email|
visit path_to('Login page')
fill_in "Email", :with => email
fill_in "Password", :with => "password"
click_button "Log in"
response.should contain("Please verify some characters from your secret phrase")
select_correct_secret_phrase_char("span#sec_1")
select_correct_secret_phrase_char("span#sec_2")
click_button "Submit"
end
def select_correct_secret_phrase_char(css_selector)
response.should have_selector(css_selector) do |scope|
select "Secret1"[(scope.text.to_i)-1].chr, :from => "Select character #{scope.text} of your security phrase"
end
end
经过一番胡闹,我终于明白了。将其记录在此处,以便在相同情况下帮助其他人。通常情况下_steps.rb:
When /^I log in as "([^\"]*)"$/ do |email|
visit path_to('Login page')
fill_in "Email", :with => email
fill_in "Password", :with => "password"
click_button "Log in"
response.should contain("Please verify some characters from your secret phrase")
select_correct_secret_phrase_char("span#sec_1")
select_correct_secret_phrase_char("span#sec_2")
click_button "Submit"
end
def select_correct_secret_phrase_char(css_selector)
response.should have_selector(css_selector) do |scope|
select "Secret1"[(scope.text.to_i)-1].chr, :from => "Select character #{scope.text} of your security phrase"
end
end