TLDR - 编写specFlow场景的最佳方法是相互连接并共享数据?例如场景A - 创建一个用户,然后使用该用户登录场景B(登录将需要在创建用户场景中指定的用户名和密码)。如何编写遵循对方并共享数据的specflow场景?
大家好,
我得到自己在一点咸菜在试图找出最好的方式来写一个网站上一个典型的用户注册形式的情况下,随后的场景来测试登录。
我试图创建一个单独的类的实例来存储我的登记表的所有细节,当它达到这一步(认为这是上下文注射液)。例如
[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
目前,我看到,我有以下选择
- 扩展第一个场景,包括登录,以及和共享使用上下文注入步骤之间的数据。
- 在我的登录步骤中重复包含表格的注册步骤。
- 写一个新的更短的步骤,生成我的用户没有表,并在这两种情况下使用这个(我可能要稍后指定与表单中设置特定值的情况,但承认,我可能会更好抛弃它)。
或者别的东西,我还没有想过......
非常感谢,
感谢您的支持。是的,这听起来像个好主意。需要整理一下,所以会在适当的时候添加Before和After。 – Konzy262
我将为Selenium管理添加一些支持代码。 – Fran