如何测试需要输入安全短语中的两个随机字符的表单?

发布于 2024-09-02 00:08:04 字数 1327 浏览 2 评论 0原文

我需要测试一个两阶段登录系统,该系统首先询问您的电子邮件地址和密码,然后向用户提供两个包含 [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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怕倦 2024-09-09 00:08:05

经过一番折腾,我终于想通了。在这里记录下来,以便可以帮助处于相同情况的其他人。在general_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

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:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文