Reputation: 73
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
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 :
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
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
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