gpt4 book ai didi

c# - 将参数从 SetUpFixture 传递给 TestFixture OneTimeSetUp

转载 作者:行者123 更新时间:2023-11-30 21:42:15 25 4
gpt4 key购买 nike

我目前正在使用 C#、nunit 和 Selenium 构建一个自动化项目,我正在尝试拥有一个安装类,它将在任何 TestFixture 之前初始化 selenium webdriver将运行并且在所有这些都结束并尝试从每个 TestFixture OneTimeSetUp 属性中的 TestFixture 获取该 webdriver 时,是否可以完成或我应该将 selenium 类更改为静态以便能够在每个 TestFixture 设置中获取驱动程序字段吗?

所以基本结构是这样的:

[SetUpFixture]
public class Test
{
[OneTimeSetUp]
public void Init()
{
_driver = new Driver();
}
}

[TestFixture]
public class FirstTest
{
[OneTimeSetUp]
public void Init()
{
xxxxxxxxxx - here I need to initialize a class with the driver from the setup class
}
}

最佳答案

就目前的情况而言,NUnit 可以为您完成此操作的唯一方法是使用静态变量。但如果您并行测试多个驱动程序,这将无法正常工作。

一个真正的解决方案(需要新的 NUnit 功能)是允许设置装置将信息保存在 TestContext 中,然后您的个人装置可以访问这些信息。

一种解决方法是在 fixture onetimesetup 中创建一个新的驱动程序,但前提是它尚未创建。这也需要一个静态变量,但您可以对其进行设置,以便为您支持的每种驱动程序类型提供一个单独的静态变量。

关于c# - 将参数从 SetUpFixture 传递给 TestFixture OneTimeSetUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42689275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com