2

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

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

7 Comments

can i make a customization for which node to run which tests ??
You can use OneTimeSetUp to tailor how and where the tests in each fixture instance runs. Sorry I can't put my answer into Selenium terminology... it's not my thing. :-)
why is Nunit running only 2 fixtures in parallel , or is it a grid issue ?
If you only have two cores, then NUnit will default to running two worker threads in parallel. You can change that using either the LevelOfParallelism attribute or the --workers command-line option.
i've been waiting for 2 days for this answer charlie and i figured it out just yesterday :-) , anyway many thanks for your help :)
|
0

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.

1 Comment

so it's the same as Nunit for making the tests run in parallel you have to create one test per class ? , if i'm having multiple tests within the same class then they will run sequentially not parallel, am i right ??
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.