简体   繁体   中英

Selenium Grid in C# Parallel execution with Nunit

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

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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