1

我正在为密码管理页面编写测试套件。对于这些场景,大多数人实际上不应该更改密码,但有些人会这样做。我使用了该标签@changePassword,以便我可以选择是否运行这些场景。

我遇到的问题是尽可能不编写重复的步骤。

简化示例场景:

@changePassword
Scenario: successful change
  Given the Manage Password page is loaded
  And a new password is generated
  When the old password is entered
  And the new password is entered
  And the confirm password is entered
  And the OK button is clicked
  Then the password has changed

Scenario: failed change (missing confirm)
  Given the Manage Password page is loaded
  And a new password is generated
  When the old password is entered
  And the new password is entered
  And the OK button is clicked
  Then the password change fails

两个版本之间的大部分步骤是相同的​​,我关心的主要差异是And a new password is generated步骤。在第一种情况下,我希望将新密码保存为用户密码。在第二种情况下,我希望最后丢弃新密码。

类似的东西:(伪代码)

And /^a new password is generated$/ do
  old password = user's password
  new password = generate random new password
  confirm password = new password
  if tag @changePassword is present
    user's password is set as the new password
  end
end

有没有办法让这成为可能?我可以写第二步之类的And a new password to be saved is generated东西,但为了可读性和非技术精通的同事,使用相同的步骤是更好的选择。(我过去发现使用不同的短语来描述类似的过程,这对用户完成完全相同的事情,这会造成混乱。如果可能的话,尽量避免工作场所的混乱。)

旁注:将 Cucumber 与 Ruby(与 Watir)一起使用,如果这有什么不同的话(是吗?)

4

1 回答 1

2

这是一个丑陋的解决方案,但是您可以使用标记的钩子来设置变量,然后在方法中根据该变量的值保存/不保存的 if 语句吗?

于 2012-05-22T16:08:16.063 回答