首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >当同一个方法多次执行时,如何获取ScenarioContext?

当同一个方法多次执行时,如何获取ScenarioContext?
EN

Stack Overflow用户
提问于 2018-05-31 19:02:22
回答 1查看 81关注 0票数 0

示例功能1:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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。

示例步骤定义:

代码语言:javascript
复制
    [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信息只需要在场景中访问)?

EN

回答 1

Stack Overflow用户

发布于 2018-05-31 20:18:18

您可以使用方案大纲

代码语言:javascript
复制
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|

测试代码

代码语言:javascript
复制
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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50622790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档