C# 中的 Selenium Grid 与 Nunit 并行执行

Selenium Grid in C# Parallel execution with Nunit

我刚刚为 selenium 网格 2 进行了设置。集线器和节点已启动并且 运行正在运行。我正在使用 Selenium webdriver + C# + Nunit 来 运行 我的测试,我现在想做以下事情:

1) 将测试用例分布在不同节点之间(并行),例如节点1 运行宁测试x和节点2 运行宁测y

2) 我需要能够为每个节点配置浏览器和平台类型,我现在能做的是制作一个设置功能,它对所有节点使用相同的平台和浏览器,那么我如何通过分配每个节点所需的功能来实现这一点。

The problem is when i run the coming code i find that the tests run simultaneously not parallel.

我的代码快照:

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Safari;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Remote;
using NUnit;
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;


namespace GridTest
{
    [TestFixture]
    [Parallelizable]
    public class Test_Grid
    {
        IWebDriver driver;

        [SetUp]
        public void Setup()
        {

            /////IE Setup/////////
            var capabilities = new DesiredCapabilities("internet explorer", string.Empty, new Platform(PlatformType.Any));
            capabilities.SetCapability("ignoreProtectedModeSettings", true);

            driver = new RemoteWebDriver(new Uri("http://localhost:4445/wd/hub"),capabilities);

         }

        //Search google test 
        [Test]
        [Parallelizable]
        public void GoogleSearch()
        {
            string homepage = "http://www.google.com";
            //Navigate to the site
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            driver.Navigate().GoToUrl(homepage);

        }

        [Test]
        [Parallelizable]
        public void BingSearch()
        {
            //var driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.bing.com");

        }


      [TearDown]
       public void Teardown()
        {

           driver.Quit();
        }
    }
}

我没有使用 c# 或 nunit,但我有多个分布 java/testng 测试的网格设置。

我所做的是对每个 class 进行一次测试。然后将它们编译成具有这些参数的 xml 测试套件:parallel="tests" thread-count="14"

此外,请确保您的网格节点具有指定数量的实例。

简单...但您不会喜欢这个答案。 :-(

NUnit 尚不支持 运行在夹具中并行测试方法。它只有 运行 个并行的独立灯具。

因此,您需要使用 OneTimeSetUp 为 select 正确的浏览器运行 在灯具级别并行建模那些您想要的东西。

更新 - 2019 年 9 月 27 日

上面的回答是我三年多前写的,当时是真的!人们,请阅读这些问题和答案的日期,因为除非被删除,否则它们将永远留在这里。

答案发布几个月后,NUnit 添加了并行 运行 单个测试用例(方法)的能力。有关受支持功能的当前信息的最佳来源是 NUnit 文档,而不是 SO!大多数工具都是如此。

NUnit 支持 method-level 并行化。您必须设置 ParallelScope.All.

我已经开发了一个工作项目,它 运行s 在不同的浏览器上使用 NUnit 并行(method-level)。

如果您的项目有 2 个测试装置,每个测试在一个文件中有 15 个测试,并且您想 运行 并行执行所有 30 个测试。然后使用以下命令:

nunit3-console.exe xxxtests.dll --workers=30

https://github.com/atmakur/WebTestingFramework