如何测试需要输入安全短语中的两个随机字符的表单?
我需要测试一个两阶段登录系统,该系统首先询问您的电子邮件地址和密码,然后向用户提供两个包含 [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 "[email protected]"
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内。
谢谢,
I need to test a two-stage login system which first asks for your email address and password and then presents the user with two select lists containing [a-zA-Z0-9]. The labels beside the drop down's are of the form 'Select character X from your security phrase', where X is a random character index from a known security phrase.
I'd rather not stub the code for an acceptance test, so is it possible to write a matcher in cucumber which will, given that we know the whole phrase, select the required character in each of the two lists?
Here is the scenario I have so far and the steps involved:
Scenario: valid login email, password and secret phrase takes me to the dashboard
Given I am not logged in
When I log in as "[email protected]"
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
For example, if the security phrase is 'Secret123', X = 3 and Y = 8, the above would have to produce the equivalent of:
select "c", :from => "Select character 3 of your security phrase"
select "2", :from => "Select character 8 of your security phrase"
The numbers X and Y in the actual page are inside span#svc_1 and span#svc_2 respectively.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一番折腾,我终于想通了。在这里记录下来,以便可以帮助处于相同情况的其他人。在general_steps.rb中:
After a lot of messing about I finally figured it out. Documenting it here so it can help someone else in the same situation. In general_steps.rb: