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

问题描述 投票:2回答:3

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

1)在不同节点(Parallelism)之间分配测试用例,例如运行测试x的节点1和运行测试y的节点2

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

问题是,当我运行即将到来的代码时,我发现测试同时运行并不是并行的。

我的代码快照:

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# selenium selenium-webdriver nunit selenium-grid
3个回答
3
投票

容易一个......但你不会喜欢这个答案。 :-(

NUnit尚不支持并行运行夹具中的测试方法。它只能并行运行各个灯具。

因此,您需要使用OneTimeSetUp选择正确的浏览器来建模您想要在夹具级别并行运行的那些内容。


0
投票

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

我所做的是每节课进行一次测试。然后将它们编译成具有以下参数的xml测试套件:parallel =“tests”thread-count =“14”

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


0
投票

NUnit支持方法级并行化。你必须设置ParallelScope.All。

我开发了一个使用NUnit在不同浏览器上并行(方法级)运行的工作项目。

如果你的项目有2个测试夹具,每个测试包含15个文件,你想要并行运行所有30个测试。然后使用以下命令:

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

https://github.com/atmakur/WebTestingFramework

© www.soinside.com 2019 - 2024. All rights reserved.