Selenium Grid in C# Parallel execution with Nunit

陌路散爱 提交于 2019-12-12 18:08:18

问题


i just made the setup for selenium grid 2. The hub and the nodes are up and running. I'm using Selenium webdriver + C# + Nunit to run my tests, i want now to do the following:

1) Distribute the test cases among different nodes(Parallelism), for example node 1 running test x and node 2 running test y

2) I need to be able to configure the browser and the platform type for each node, what i'm able to do now is that i make one setup function and it uses the same platform and browser for all the nodes, so how can i achieve that by assigning each node's desired capabilities.

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

Snapshot of my code:

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();
        }
    }
}

回答1:


Easy one... but you won't like the answer. :-(

NUnit does not yet support running the test methods in a fixture in parallel. It only runs individual fixtures in parallel.

So you need to model those things you want run in parallel at the fixture level, using OneTimeSetUp to select the correct browser.

UPDATE - 27 Sep 2019

I wrote the above answer over three years ago, when it was true! People, pleaseread the dates on these questions and answers, since they stay here forever unless removed.

A few months after the answer was posted, NUnit added the ability to run individual test cases (methods) in parallel. Best source of current info about supported features is the NUnit docs, not SO! That's true for most tools.




回答2:


I am not using c# or nunit, but I have multiple grids setup that distribute java/testng tests.

What I have done is make one test per class. Then compile them into xml test suites that have these parameters: parallel="tests" thread-count="14"

Also, make sure that your grid nodes have specified number of instances.




回答3:


NUnit supports method-level parallelization. You have to set the ParallelScope.All.

I have developed a working project which runs parallely (method-level) on different browsers using NUnit.

If your project has 2 test fixtures with 15 each tests in a file and you want to run all the 30 tests parallely. Then use the below command:

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

https://github.com/atmakur/WebTestingFramework



来源:https://stackoverflow.com/questions/38993258/selenium-grid-in-c-sharp-parallel-execution-with-nunit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!