简体   繁体   English

是否可以在 Nunit 3 中并行运行测试用例(而非测试)?

[英]Is it possible to run TestCases (not Tests) in Parallel in Nunit 3?

I would like to run multiple test cases in a test in parallel.我想在一个测试中并行运行多个测试用例。 At the moment, when I do this, a browser per test case is opened but the tests seem to all try to run in the same browser.目前,当我这样做时,每个测试用例都会打开一个浏览器,但测试似乎都试图在同一个浏览器中运行。 It then goes on to just open new browsers and keep testing sequentially.然后它继续打开新的浏览器并继续按顺序进行测试。 What am I doing wrong?我究竟做错了什么? Thanks in advance!提前致谢!

[TestFixture]
public class AuthorisationTests : BaseTests
{
    [Test, Parallelizable(scope: ParallelScope.Children)]
    [TestCase("AccountAdministration")]
    [TestCase("AdvancedConfiguration")]
    [TestCase("AdvancedEntry")]
    [TestCase("AdvancedReporting")]
    [TestCase("BasicConfiguration")]
    [TestCase("DataEntry")]
    [TestCase("Reporting")]
    [TestCase("Revenue")]
    [TestCase("SysAdmin")]
    public void logged_in_user_should_be_able_to_access_only_appropriate_pages(string userType)
    {

The code used to initialise the driver:用于初始化驱动程序的代码:

        [SetUp]
    public void BeforeEach()
    {
        new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig());
        driver = new ChromeDriver();

        _loginPage.GoToLoginPage();
        driver.Manage().Window.Maximize();
    }

I believe you need to setup the webdriver in such a way, that it would run each test on different thread.我相信您需要以这种方式设置 webdriver,它会在不同的线程上运行每个测试。 This is how you can do it:你可以这样做:

ThreadLocal<IWebDriver> driver = new ThreadLocal<IWebDriver>();

Then all the commands where you access the driver object change a bit:然后,您访问driver object 的所有命令都会发生一些变化:

driver.Value = new ChromeDriver();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM