我需要测试一个两阶段登录系统,它首先询问您的电子邮件地址和密码,然后向用户显示两个包含 [a-zA-Z0-9] 的选择列表。下拉列表旁边的标签形式为“从您的安全短语中选择字符 X”,其中 X 是来自已知安全短语的随机字符索引。
我宁愿不为验收测试存根代码,所以是否可以在黄瓜中编写一个匹配器,鉴于我们知道整个短语,它会在两个列表中的每一个中选择所需的字符?
这是我到目前为止的场景和所涉及的步骤:
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 内。
谢谢,