【问题标题】:Context Injection for parallel execution用于并行执行的上下文注入
【发布时间】:2018-07-02 04:49:02
【问题描述】:

我已经设法构建了一些不使用页面对象模型结构的相当简单的测试。 Specflow 步骤将只调用驱动程序方法(例如在页面上查找元素并断言文本是正确的)。

测试使用 NUnit 作为运行程序,我通过将 [Parallelizable(ParallelScope.Fixtures)] 添加到解决方案的程序集类来设法添加并行执行。这很好用,但是从 NUnit 出来的报告有点乱,我想要更多有用的信息(例如屏幕截图)。

我已经在解决方案中添加了范围报告,虽然这适用于按顺序运行测试,但在并行运行时会出现错误消息。

The FeatureContext.Current static accessor cannot be used in multi- 
threaded execution. Try injecting the feature context to the binding 
class.

Context.Current 步骤用于创建范围报告。我一直在阅读 Specflow 站点上与多线程相关的文档,但我在理解这个概念和弄清楚如何将 FeatureContext 注入绑定类时遇到了问题。我正在尝试从网站上遵循这个示例:

[Binding]
public class StepsWithScenarioContext : Steps
{
    [Given(@"I put something into the context")]
    public void GivenIPutSomethingIntoTheContext()
    {
      this.ScenarioContext.Set("test-value", "test-key");
    }
}

我也一直在尝试遵循其他示例,但我还没有看到任何有关如何将 ScenarioContext 与 driver.findElement(By.Id("blah")) 之类的东西一起使用的文档。

任何帮助将不胜感激,我对测试自动化相当陌生。

【问题讨论】:

    标签: automated-tests bdd specflow


    【解决方案1】:

    您需要在 Steps 类中有一个属性: ScenarioContext _scenarioContext。 在构造函数中,您将ScenarioContext scenarioContext 添加为参数并使用以下方法对其进行初始化:

    _scenarioContext = scenarioContext
    

    简单示例:

    class Steps
    ScenarioContext _scenarioContext;
    public Steps (ScenarioContext scenarioContext)
    {
      _scenarioContext = scenarioContext;
    }
    

    只有我不知道,它将如何与继承一起工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多