【问题标题】:When I call SpecFlow hook [BeforeScenario] test class non static properties in the test class value is not saved当我调用 SpecFlow 钩子 [BeforeScenario] 测试类非静态属性中的测试类值未保存
【发布时间】:2014-12-07 11:30:42
【问题描述】:

我想在我的测试类中初始化我的 WebDriver 属性,当我想在场景中使用它时它是“Null”。

在此处的示例中,当我尝试导航到某个 url 时,我得到了 null 异常。

例子:

[BeforeScenario]
    private void BeforeScenario()
    {
        TestInitilaize();
    }

[TestInitialize]
    public void TestInitilaize()
    {
        InitializeTest();
    }

protected virtual void InitializeTest()
    {
        WebDriver = new FirefoxDriver();
    }

[Given(@"Some Given")]
    public void GivenMethod()
    {
        WebDriver.Navigate().GoToUrl("www.someurl.com");
    }

【问题讨论】:

    标签: c# selenium hook specflow


    【解决方案1】:

    问题可能是您的[BeforeScenario] 方法是私有的。你检查过这个方法实际上是在调试器中调用的吗?

    【讨论】:

    • 是的,调试器正在调用该方法。
    • 你是对的,因为它是私有的,但我认为因为我有一个继承,它适用于基类,当我将它更改为公共时,[BeforeScenario] 被调用了两次,但值已保存,我可以在我的 specflow 步骤中使用它。
    猜你喜欢
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多