Skip to content

TestNG Configuration

Hemanth Sridhar edited this page Apr 25, 2017 · 11 revisions

TestNG Configuration Tutorial to use WebAppFramework effectively

Mandatory : Use Selenium grid

Run your tests in different browsers

  • In order to run in chrome, add value chrome for browser parameter for the xml below

  • In order to run in firefox, add value firefox for browser parameter for the xml below

  • In order to run in safari, add value safari for browser parameter for the xml below

  • In order to run in edge, add value Microsoft Edge for browser parameter for the xml below

  • In order to run in IE, add value internet explorer for browser parameter for the xml below

    <suite name="Google Test"> <test name="Regression Testing"> <parameter name="Product Name" value="Google"></parameter> <parameter name="Application URL" value="http://www.google.com/"></parameter> <parameter name="Platform" value="ANY"></parameter> <parameter name="browser" value="chrome"></parameter> <parameter name="Remote Url" value="http://localhost:4444/wd/hub"></parameter> <classes> <class name="org.google.modules.SearchModuleTest" ></class> </classes> </test> </suite>

Ensure that while you are setting up the node, java -Dwebdriver.chrome.driver=path till the chromedriver executable is provided. Above applies for geckodriver, safari, edge, IE

Running TestNG tests in parallel

If parallel=methods is given, all the tests mentioned in the class(in testng.xml) will run in parallel. But by just specifying parallel=methods the tests won't run in parallel. We also need to provide thread-count="5". thread-count provides the amount of threads that needs to spawned concurrently.

Also, in order to ensure that more than 5 threads are spawned, the node needs to have maxInstances=10. maxInstances is a parameter in selenium grid that defines the maximum number of sessions that can be run in a VM for every invocation.

<suite name="Google Test" parallel="methods" thread-count="8"> <test name="Regression Testing"> <parameter name="Product Name" value="Google"></parameter> <parameter name="Application URL" value="http://www.google.com/"></parameter> <parameter name="Platform" value="ANY"></parameter> <parameter name="browser" value="chrome"></parameter> <parameter name="Remote Url" value="http://localhost:4444/wd/hub"></parameter> <classes> <class name="org.google.modules.SearchModuleTest" ></class> </classes> </test> </suite>

Running classes in parallel

provide parallel = classes In the below example, SearchModuleTest and LoginModuleTest runs in parallel.

<suite name="Google Test" parallel="classes" thread-count="8"> <test name="Regression Testing"> <parameter name="Product Name" value="Google"></parameter> <parameter name="Application URL" value="http://www.google.com/"></parameter> <parameter name="Platform" value="ANY"></parameter> <parameter name="browser" value="chrome"></parameter> <parameter name="Remote Url" value="http://localhost:4444/wd/hub"></parameter> <classes> <class name="org.google.modules.SearchModuleTest" ></class> <class name="org.google.modules.LoginModuleTest" ></class> </classes> </test> </suite>

Distribution of tests

provide parallel = tests If parallel=tests is given, then test tags runs in parallel. By using the below technique we can achieve cross browser testing and cross platform testing.

<suite name="Google Test" parallel="classes" thread-count="8"> <test name="In chrome"> <parameter name="Product Name" value="Google"></parameter> <parameter name="Application URL" value="http://www.google.com/"></parameter> <parameter name="Platform" value="ANY"></parameter> <parameter name="browser" value="chrome"></parameter> <parameter name="Remote Url" value="http://localhost:4444/wd/hub"></parameter> <classes> <class name="org.google.modules.SearchModuleTest" ></class> <class name="org.google.modules.LoginModuleTest" ></class> </classes> </test> <test name="In firefox"> <parameter name="Product Name" value="Google"></parameter> <parameter name="Application URL" value="http://www.google.com/"></parameter> <parameter name="Platform" value="ANY"></parameter> <parameter name="browser" value="firefox"></parameter> <parameter name="Remote Url" value="http://localhost:4444/wd/hub"></parameter> <classes> <class name="org.google.modules.SearchModuleTest" ></class> <class name="org.google.modules.LoginModuleTest" ></class> </classes> </test> <test name="In MAC Sierra"> <parameter name="Product Name" value="Google"></parameter> <parameter name="Application URL" value="http://www.google.com/"></parameter> <parameter name="Platform" value="MAC"></parameter> <parameter name="browser" value="chrome"></parameter> <parameter name="Remote Url" value="http://localhost:4444/wd/hub"></parameter> <classes> <class name="org.google.modules.SearchModuleTest" ></class> <class name="org.google.modules.LoginModuleTest" ></class> </classes> </test> <test name="In Windows 10"> <parameter name="Product Name" value="Google"></parameter> <parameter name="Application URL" value="http://www.google.com/"></parameter> <parameter name="Platform" value="WIN_10"></parameter> <parameter name="browser" value="Microsoft Edge"></parameter> <parameter name="Remote Url" value="http://localhost:4444/wd/hub"></parameter> <classes> <class name="org.google.modules.SearchModuleTest" ></class> <class name="org.google.modules.LoginModuleTest" ></class> </classes> </test> </suite>

Guidelines

  • Ensure that the browser is set up in the node properly. (java -D key=value pair)
  • Always give the hub url as the value for the Remote URL parameter to give control to the Hub completely.

Next topic : MediaConfig.properties

Clone this wiki locally