示例功能1:
Scenario: Record Creation for different Users
Given "User 1" is created a record
And "User 2" is created a record
And "User 3" is created a record
Then admin is able to check all the record IDs
示例特性2:
Scenario: Record Creation for guest User
Given "guest User 1" is created a record
Then admin is able to check all the record IDs
这里,我在第2、3和5步中有一个Common Specflow步骤,并将从第2、3和4步中获得一些唯一ID。在第5步中,我需要验证从第2、3和3步中生成的所有唯一ID。
示例步骤定义:
[Given(@"""(.*)"" is created a record")]
public void GivenIsCreatedARecord(string username)
{
var recordRef=<<some Logic >>;
ScenarioContext.Current["Record Ref"] = recordRef;
}
我已经分析并使用ScenarioContext在所有步骤之间共享信息。在这里,我在Scenario Context中设置了Record Ref值,并在最后一步验证(var expectedID=ScenarioContext.Current["Record Ref"]
)中访问它。但是,已实现的逻辑对于功能2工作良好,而用户3id正在为功能1更新(因为,相同的方法被执行了3次)。
有没有办法将User1 ID、User2 ID和Uuser 3 ID保存在某个列表中,并且可以在验证步骤中访问相同的内容(所有ID信息只需要在场景中访问)?
发布于 2018-05-31 20:18:18
您可以使用方案大纲
Scenario Outline: Record Creation for different Users
Given '<user>' is created a record
Then admin is able to check all the record IDs
Examples:
|user |
|User 1|
|User 2|
|User 3|
测试代码
private Dictionary<string,SomeType> usersResult= new Dictionary<string,SomeType>();
[Given(@"""(.*)"" is created a record")]
public void GivenIsCreatedARecord(string username)
{
var recordRef=<<some Logic >>;
usersResult.add(username,recordRef);
//other stuff
}
https://stackoverflow.com/questions/50622790
复制相似问题