TestNG XML with groups and packages not working - selenium

I am working on a set of selenium tests I want to run using a TestNG XML.
<suite name="MATS">
<parameter name="browser" value="firefox" />
<parameter name="platform" value="windows" />
<test name="mats_test">
<groups>
<run>
<include name = "mats" />
</run>
</groups>
<packages>
<package name="com.sel.tests.app.set1.*" />
<package name="com.sel.tests.app.set2.*" />
<package name="com.sel.tests.app.set3.*" />
</packages>
</test>
</suite>
Directly under each of those packages there are multiple classes with the #Test(groups = { "mats" }) annotation on top. However, I get this output:
MATS
Total tests run: 0, Failures: 0, Skips: 0
Update: Ok, so cleaning the project didn't work so I imported it again in a new workspace after which it seems to be working. Closing the question. Thanks everyone.

If you're working in IntelliJ Idea try to select in main menu Run -> Edit Configurations. On left side select "TestNG" configuration, on right side select "In whole project" radio button and Working Directory: as $MODULE_DIR$ (or play with that)

Related

Classes in TestNg POM framework are not getting executed in Sequence

I am creating Simple Page Object Model framework in Selenium Java.
One .java class is one scenario.
So if i write this in TestNg.xml it works fine for one scenario.
**<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="1" name="Test Simple Suite" parallel="false">
<listeners>
<listener class-name="com.proj.Listener.Listeners"></listener>
</listeners>
<test thread-count="1" name="Test Basic Scenario1" parallel="false">
<classes>
<class name="TC001_SampleCase"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->**
However, when i write second class, it also start the execution of the same. Expected is, it should execute in sequence. Following testNg executes both classed in parallel
**<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="1" name="Test Simple Suite" parallel="false">
<listeners>
<listener class-name="com.proj.Listener.Listeners"></listener>
</listeners>
<test thread-count="1" name="Test Basic Scenario1" parallel="false">
<classes>
<class name="TC001_SampleCase"/>
<class name="TC002_SampleCase"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->**
Would be really helpful, if anyone from the community can help on this issue. Thanks!
Also note, in both classes i have given priorities to #Test.
TC001_SampleCase consists 20 #Test given Priority from 1 to 20
TC002_SampleCase consists 15 #Test given Priority from 21 to 35
TestNg version: 7.3
Selenium version: 3.141.59
Can you try removing the Parallel Tag from Suite line. Just keep as below and try.
<suite thread-count="1" name="Test Simple Suite">
To executed test cases sequentially using testng.xml files, please pass
preserve-order="true"

how to run single test case from jenkins

I have 10 test cases in testng suite,i need to execute single or individual test cases from jenkinks,can any one help me out how to execute single test case from jenkins,i tried maven surfire commands mvn -Dtest=TestCircle test include test command into golas and executed but its not working,please refer data and correct me how to set goals in jenkins for execute single test case.
"mvn clean compile install -DPICK_CONFIGURATION_FROM="JENKINS" -DEXECUTION_MODE="Remote" -Dtest=TestCircle#EAConsoleLandingPageTest test -DPLATFORM="WEB" -DOPERATING_SYSTEM="WINDOWS" -DBROWSER="chrome" -DCOMPUTERNAME="Test" -DTEST_ENVIRONMENT="RUNFC" -DPLAN_ID="" -DTEST_TYPE="Smoke" -DGRID_URL="http://localhost:4444/wd/hub""
Below is the sample test suite:
classes>
<class
name="com.ea.automation.tests.EAConsoleLandingPageTest">
<methods>
<include name="clickOnGetStartedBtn" />
<include name="selectProjectFromLandingPage" />
<include name="clickOnEAConsoleIcon" />
<include name="verifyRequestProjectAccess" />
<include name="verifyProjectAccess" />
<include name="verifyHomePageRedierecting" />
</methods>
</class>
<class
name="com.ea.automation.tests.EAConsoleSelfServiceTest">
<methods>
<include name="clickOnCreateNewproject" />
<include name="verifyProjectUserAcess" />
<include name="switchProjects" />
<include name="clickOnProjectSettings" />
</methods>
</class>
<class
name="com.ea.automation.tests.EAConsoleNotificationAppTest">
<methods>
<include name="selectProject" />
<include name="clickOnNotification" />
<include name="checkAllWdgetNotifications" />
</methods>
</class>
<class
name="com.ea.automation.tests.EAConsoleSupportAppTest">
<methods>
<include name="clickOnSupportApp" />
<include name="checkCreateTicket" />
<include name="clickOnCloseErrorMessageModel" />
<include name="clickOnSupportFromApp" />
<include name="clickOnSupportEmail" />
</methods>
</class>
<class
name="com.ea.automation.tests.EAConsoleSDKDownloadsAppTest">
<methods>
<include name="selectProject" />
<include name="clickOnSDKDownloads" />
</methods>
</class>
The approach I am suggesting is not preferable. Because the sole purpose of running Jenkins is to run a suite of test cases and not individual ones. But you could implement your idea in the following way.
Add three string parameters to the Jenkins job. One parameter points to the testng xml file name, second parameter points to the class name, and the third parameter points to the test name.
Create and have another testng.xml file in your project repo. Rename this file as small.xml
So the first Build parameter should be small.xml
Jenkins has the capability to execute shell script before the maven build starts.
So we are going to fetch the arguments that we used as Jenkins Build parameters inside the shell script to modify the small.xml file and modify the pom.xml file to point to the small.xml.
sed command in a shell script will help to replace the existing text in pom.xml and small.xml file. You could search this on the internet.
I had implemented this approach in one of the projects that I worked on for picking different suite files based on the Jenkins build parameters. This approach works. So during runtime, based on the Jenkins Build Parameters you pass, the corresponding tests will be run by Jenkins.

How to configure TestNG testng.xml to ensure that one group runs at the end of all the other groups?

I have multiple test groups in my test suite (a,b,c, etc).
If I have to make a group 'z' run at the end of all other groups (the list is not fixed and can grow), how do I do it through testng.xml?
TestNG documentation suggests using the below in testng.xml:
<test name="My suite">
<groups>
<dependencies>
<group name="z" depends-on="a b c" />
</dependencies>
</groups>
</test>
But in my case a,b,c are not fixed. There can be tens of groups which I can't explicitly list in testng.xml everytime a new group is added.
This is how my current testng.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods" thread-count="5">
<test name="App tests">
<groups>
<run>
<exclude name="smoke"/>
<exclude name="rest"/>
</run>
</groups>
<packages>
<package name="apps.webdriver.*"></package>
</packages>
</test>
</suite>
Please let me know if there is a way to achieve this.
I can think of "grouping" tests in terms of classes/packages. Your z group will be in a separate class while a,b,c....will be in different class.

Not getting report of TestNG in ReportNG

I am executing testng in eclipse and I want generate the report in reportNG. For that I have inlcuded guice-3.0,reportng-1.1.3,velocity-dep-1.4 jar files and added listeners in xml file Also I have disable the default TestNG listener in eclipse.
After all that I am not getting the report in ReportNG. What else I have to do?
This is the xml code....
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Registration" verbose="1" preserve-order="true">
<parameter name="Suitename" value="Registration" />
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Search">
<classes>
<class name="com.tcs.medmantra.reg.Search"/>
</classes>
</test>
</suite>
Thanks in advance.....
You have to first run the tests by running the testng.xml as TestNG suite.
Then after that refresh the project.
Now goto the test-output folder -->html-->index.html (Open with Web Browser).

Selenium: running testsuite in parallel using grid

I am trying to execute the same testsuite in parallel on an arbitrary number of selenium-grid nodes.
The test suite was created with the selenium IDE and exported as testng using the batch-converter
The idea is to create the test-suite once and then launch an arbitrary number of nodes that run that particular suite in parallel
Right now, I got 1 hub running + 2 remote-controls connected to that hub
My testng.xml looks like this
<suite name="mysuite1" verbose="20" annotations="JDK" parallel="tests" thread-count="20" >
<parameter name="selenium.host" value="localhost"></parameter>
<parameter name="selenium.port" value="4444"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.restartSession" value="false"></parameter>
<test name="mytest1" preserve-order="true">
<parameter name="selenium.port" value="5557"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.url" value="http://localhost:8080"></parameter>
<classes>
<class name="my.testsuite1" />
<class name="my.testsuite2" />
</classes>
</test>
The target I'm using in the build.xml looks like this
<target name="run-parallel" depends="compile" description="Run-Parallel">
<echo>${host}</echo>
<java classpathref="runtime.classpath" classname="org.testng.TestNG" failonerror="true">
<sysproperty key="java.security.policy" file="lib/testng.policy"/>
<sysproperty key="webSite" value="${webSite}" />
<sysproperty key="seleniumHost" value="${host}" />
<sysproperty key="seleniumPort" value="${port}" />
<sysproperty key="browser" value="${browser}" />
<arg value="-d" />
<arg value="${basedir}/target/reports" />
<arg value="-suitename" />
<arg value="suite1" />
<arg value="-parallel"/>
<arg value="tests"/>
<arg value="-threadcount"/>
<arg value="20"/>
<arg value="testng.xml"/>
</java>
My problem:
When I execute the testsuite above, only one remote-control executes the test while my second remote-control remains idle.
I know that I currently address the remote-controls directly using the "selenium.port", but I am searching for a way to avoid this rigid way of assigning tests to remote-controls
When I add additional elements, all the classes listed within the elements (my.testsuite1-4) are executed in a random order.
<test name="mytest2" preserve-order="true">
<parameter name="selenium.port" value="5558"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.url" value="http://localhost:8080"></parameter>
<classes>
<class name="my.testsuite3" />
<class name="my.testsuite4" />
</classes>
My question:
How can I define a testsuite properly so that it is scheduled on any number of running remote-controls?
Thanks!
All of your tests should access the Selenium Grid hub. The hub is responsible for dispatching to nodes based upon the requested capabilities. Once you run tests in parallel, you lose the ability to define execution order. Each test should be isolated. This includes any data you may need on your backend, such as DB modifications.