【发布时间】:2018-02-03 02:02:24
【问题描述】:
TLDR - 编写相互跟随并共享数据的 specFlow 场景的最佳方式是什么?例如场景 A - 创建一个用户,然后场景 B 使用该用户登录(登录需要在创建用户场景中指定的用户名和密码)。
大家好,
在尝试找出在网站上为典型的注册用户表单编写场景的最佳方法,然后是测试登录的场景时,我让自己陷入了困境。
我尝试创建一个单独的类的实例来存储我的注册表单的所有详细信息,当它到达这一步时(认为这是上下文注入)。例如
[Binding]
public class AdmissionsPortalFeaturesSteps : BaseStep
{
private UserDetails userDetails;
我遇到的问题是以下场景需要在前一个场景中生成的密码,而我无法通过类似...的方式访问它
userDetails.Password
这是我目前无法使用的,因为我想将密码值从第一个场景传递到第二个场景......(请注意,如果该字段设置为“随机”,则会在我的c#代码)
Scenario: Create a new user via the Admissions Portal
Given I will navigate to the Admissions Portal login page
When I click the Create an Account link
Then I will be on the ontrack: prospect - Register page
Given I have entered the following values on the registration page
| fieldName | value |
| Title | random |
| Firstname | random |
| Middlename | random |
| Surname | random |
| DOB | random |
| Gender | random |
| EmailAddress | random |
| MobileNumber | 0 |
| Password | random |
| SecurityQuestion | random |
| SecurityAnswer | random |
And I click on the Register button
Then I will be on the Login page
And I will get a popup confirming my registration details
Then I close the browser window
Scenario: I am able to login to the Admissions Portal with a newly created user
Given I will navigate to the Admissions Portal login page
And I enter a username and password and click to login
Then I will be on the ontrack: prospect - Home page
Then I close the browser window
目前我看到我有以下选项
- 扩展第一个场景以包括登录以及使用上下文注入在步骤之间共享数据。
- 在我的登录步骤中重复包含表格的注册步骤。
- 编写一个新的更短的步骤,在没有表格的情况下生成我的用户,并在两种情况下都使用它(我可能想稍后指定具有在表单中设置的特定值的场景,但我承认我最好放弃它)。李>
或者其他我没有想到的...
非常感谢,
【问题讨论】:
标签: c# automated-tests specflow