how to get the reports using testNG with selenium grid? - selenium

i am running the scripts using selenium grid with TestNG. In testng we are seperating scripts with removing dependency.Format is like that:
<suite name="Suite" parallel="true">
<test name="Test" preserve-order="false">
<classes>
<class name="test.TestCase1"/>
<class name="test.TestCase2"/>
</classes>
</test>
<test name="Test" preserve-order="false">
<classes>
<class name="test.TestCase3"/>
<class name="test.TestCase4"/>
</classes>
</test>
</suite>
problem is that testng reports only about the last two testcases. Can any one help us how to get reports from all reports ???????. Also testcase1 will effect the testcase2.

From above config xml i can say that your results are overwritten by test 2 as the test name are the same. For instance you must provide unique test name value as below:
<suite name="Suite" parallel="true">
<test name="Test-1" preserve-order="false">
<classes>
<class name="test.TestCase1"/>
<class name="test.TestCase2"/>
</classes
</test>
<test name="Test-2" preserve-order="false">
<classes>
<class name="test.TestCase3"/>
<class name="test.TestCase4"/>
</classes>
</test>
</suite>
Furthermore if you are running in parallel without taking care of thread safety then there is a chance of error-prone behavior. You can utilize ISFW to reduce your efforts.

Related

Avoid dependency in Integration Testing

In integration testing scenario, I have an object creation if the object creation is successful I have Record CRUD operation but if object creation fails then record operation should be skipped. To maintain these integration scenarios I have configured my testng.xml file like this : -
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestNG" verbose="1" >
<test name="Object Testing" preserve-order="true">
<classes>
<class name="com.settings.test.employee.PostObject" />
<class name="com.settings.test.employee.GetObject" />
<class name="com.settings.test.employee.DeleteObject" />
</classes>
</test>
<test name=" Record Testing" preserve-order="true">
<classes>
<class name="com.settings.test.employee.PostObject" />
<class name="com.settings.test.employee.PostRecord" />
<class name="com.settings.test.employee.GetRecord" />
<class name="com.settings.test.employee.GetRecordByID" />
<class name="com.settings.test.employee.DeleteObject" />
</classes>
</test>
</suite>
In this approach unneccessary i am doing the same operation again and again which increases time of execution and code size.
I need to maintain this dependency at a class level not outside of the class, please suggest me some approach on how I can make it happen?.
Please use dependsOnGroups or dependsOnMethods so that you can control when it will be executed.
You can use below links as an example
https://www.journaldev.com/21389/testng-dependency-dependsonmethods-dependsongroups

"Executing a test in testNG based on condition"

i have a testNG xml which will execute a (one)test case 2 times. the difference between each time is the test level parameter. so i have to execute the test case with 2 different parameter (2 user).
Now i will be creating new xml (suite of xml) from which i will call the existing xml. i will define a new parameter in suite xml for the User.
Expectation is if suite xml parameter="user2", then the child xml should execute the test case only once which has parameter as user2.
i tried beanshell scripting and found it useful for method-selector. but i want to make decision for test level and not method level.
Below is the testNG.xml which calls the test case 2 times with different user value. TestCase will be called first time with User="USER1" and second time with User="USER2".
<?xml version="1.0"?>
<suite name="TestLoad">
<test verbose="10" name="TestForUser1" preserve-order="true">
<parameter name="User" value="USER1"/>
<classes>
<class name="com.dummy.test.TestCase"/>
</classes>
</test>
<test verbose="10" name="TestForUser2" preserve-order="true">
<parameter name="User" value="USER2"/>
<classes>
<class name="com.dummy.test.TestCase"/>
</classes>
</test>
</suite>
Below is the Suite of xml which i will be newly creating to call many testng.xml described as above.
<?xml version="1.0"?>
<suite name="suiteOfXml">
<parameter name="User" value="USER1"/>
<suite-files>
<suite-file path="TestLoad.xml"/>
<suite-file path="TestStage.xml"/>
</suite-files>
</suite>
Expectation is something like:
if the suiteOfXml has User="USER1" then each testNG xml should run the TestCase only once with User=USER1.
if the suiteOfXml has User="USER2" then each testNG xml should run the TestCase only once with User=USER2.
if the suiteOfXml has User="ALL" then each testNG xml should run the TestCase twice. once with User=USER1 and next time with User=USER2.
I cannot make any changes to the TestCase (java class level). condition should be made at xml only.
Kindly provide a possible solution. Thanks in advance
Here's what you need to be doing to get past this issue (You dont need a suite of suites etc., )
Create an implementation of the TestNG listener interface org.testng.IAlterSuiteListener within which you basically read the value of the parameter and then based on it, you decide which <test> should be created and how it would look like etc.,
You create a suite xml file that only contains the parameter which would help you decide what <test> should be there and also a reference to the newly created listener from the previous step.
That should do. Using this approach you can basically do all the things that you have listed out.
Here's how a sample listener would look like (In this example, we are getting the packages to be executed via a JVM argument and then based on that, we are building our <test> tag)
package com.rationaleemotions.wordpress;
import org.testng.IAlterSuiteListener;
import org.testng.xml.XmlPackage;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
import java.util.Collections;
import java.util.List;
public class SimpleSuiteAlterer implements IAlterSuiteListener {
#Override
public void alter(List suites) {
XmlSuite suite = suites.get(0);
XmlTest xmlTest = new XmlTest(suite);
xmlTest.setName("CommandLine_Test");
String packages = System.getProperty("package", suite.getParameter("package"));
XmlPackage xmlPackage = new XmlPackage(packages);
xmlTest.setXmlPackages(Collections.singletonList(xmlPackage));
}
}
And here's how the suite xml would look like
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Package-Suites" verbose="2">
<parameter name="package" value="com.rationaleemotions"/>
<listeners>
<listener class-name="com.rationaleemotions.wordpress.SimpleSuiteAlterer"/>
</listeners>
</suite>
For a more detailed explanation and some code samples, refer to my blog post https://rationaleemotions.com/building_dynamic_testng_suites/

Next test case is not getting triggered when current test case got failed using selenium webdriver

I have a testing.xml file as below
<suite name="Suite1" parallel="none" thread-count="2" >
<test name="Test1">
<classes>
<class name="com.fb.case1" />
<class name="com.fb.case2" />
</classes>
</test>
</suite>
And when I execute the above file, the test case "com.fb.case1" is failing because of an element not visible exception (Waited for the element on UI for 40 sec). Because of this failure, the next test case i.e "com.fb.case2" is not triggered.
From the console, I can see that test case com.fb.case1 has failed and displayed as
report classcom.fb.case1

Jenkins TestNG result integration

I have lots of longrunning separate tests, grouped by functionality in suites in some xml files.
<suite name="Suite1" thread-count="1" parallel="false" verbose="1">
<test name="A" preserve-order="true">
<classes>
...
</classes>
</test>
<test name="B" preserve-order="true">
<classes>
...
</classes>
</test>
</suite>
My problem is, I'd like to generate some kind of html/xml result from grouping the results based on their test name / tag.
For example, I have these tests from A to E, and the result groups woudl be :
A,B,C
B,D,E
I know I could create a separate suite for the tasks (A,B,C) but in that case B would execute again in the second suite, which is not desirable since they are long running... So the idea would be to run every test once, but generate combined reports based on their name/tag.
Is there a plugin for this ? Or how could I achieve this ?
You can make your own reporter which will be generated the expected result.
The default reporter could be a good start.

How to run selective tests from testng.xml

I have testng.xml in which I have large number of <test> tag. I want to execute some of them not all and I don't want to comment the rest
e.g In my testng.xml, there are three tests
<test name="testA">
</test>
<test name="testB">
</test>
<test name="testC">
</test>
I want to execute testA and testC only and i don't want to comment the testB
Any suggestion..?
Add a command line switch of: -testnames=testA,testC
I don't think that can be done. If there are specific tests you do not want to run then you can check out Iannotationtransformer to set the enabled value = false to set specific tests not to run.