Fenomenoq
Fenomenoq

Reputation: 73

Selenium grid or TestNG XML for parallel cross browser testing

I am trying to do some cross browser testing on selenium by connecting to browser stack so that I can test on multiple browsers at the same time.

At the moment I am using a testng xml file to set up my browsers for testing (see code below) and running my tests from there in parallel.

I will possibly be doing this for at least 15 different browser/device types and was wondering if it is a good idea to continue using this approach. Or will selenium grid be better? Any suggestions will be appreciated :)

testng xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="2" name="test.java" verbose="1" annotations="JDK" parallel="tests" >
    <test name="Test - Chrome">
        <parameter name="browser" value="chrome"/>
        <parameter name="browserVersion" value="74.0 beta"/>
        <parameter name="os" value="OS X"/>
        <parameter name="osVersion" value="Mojave"/>
        <parameter name="resolution" value="1024x768"/>
        <classes>
            <class name="EndToEnd"/>
        </classes>
    </test>

    <test name="Test - Firefox">
        <parameter name="browser" value="firefox"/>
        <parameter name="browserVersion" value="66"/>
        <parameter name="os" value="OS X"/>
        <parameter name="osVersion" value="Mojave"/>
        <parameter name="resolution" value="1024x768"/>
        <classes>
            <class name="EndToEnd"/>
        </classes>
    </test>
</suite>

set up class:

@BeforeTest
    @Parameters({"browser", "browserVersion", "os", "osVersion", "resolution"})
    public void setUp(String browser, String browserVersion, String os, String osVersion, String resolution) throws Exception
    {
        DesiredCapabilities capability= new DesiredCapabilities();
        capability.setCapability("browser", browser);
        capability.setCapability("browser_version", browserVersion);
        capability.setCapability("os", os);
        capability.setCapability("os_version", osVersion);
        capability.setCapability("resolution", resolution);
        capability.setCapability("browserstack.local", "true");
        capability.setCapability("browserstack.localIdentifier", "Test123");
        driver = new RemoteWebDriver(new URL(URL), capability);
    }

Upvotes: 1

Views: 868

Answers (2)

Krishnan Mahadevan
Krishnan Mahadevan

Reputation: 14736

There are two parts to the question here.

The selenium grid comes into picture only when trying to setup the infrastructure needed for your browser/mobile automation. When I say infrastructure I mean the following :

  1. Browser flavor and version/ Mobile device flavor and version
  2. OS version

Apart from setting up the infrastructure needs for automation, the grid also lets you do remote execution (so that your local machine can be freed from executing test automation actions on browser)

If you would need to run your tests on different browser+OS combinations, then TestNG suite xml is perhaps the right and recommended way of doing it.

When you express your browser flavor/version/platform combinations as values via the testng xml file, and then use that to construct your DesiredCapabilities what you are essentially doing here is constructing the english statement "I would like to run this test on a firefox browser version 66 running on an OSX machine".

The grid on the other hand is meant to answer to questions such as

  1. I can run your test that is intended to run on firefox browser version 66 running on OSX machine.
  2. I currently dont have any machine associated with me, that can support Internet Explorer on Windows 10 (because I dont have any machines like that with me)

The distribution of the test is the responsibility of Grid. Specifying the requirements for cross browser automation via a test would be the responsibility of a test case. Here TestNG enables you to specify this requirement via your test case, by providing various different means of parameterizing the intent (Suite xml file is one such means)

Upvotes: 1

teddym6
teddym6

Reputation: 88

To be honest I would setup the hub with different nodes capabilities and just let the grid to distribute that across the nodes rather than having it in test NG.

There is a good article here , which might help you understand better .

https://dzone.com/articles/selenium-grid-tutorial-setup-and-example-of-cross

Upvotes: 1

Related Questions