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.
Related
I was creating a demo framework for Open MRS Application using POM design. The credentials for the Application are "admin/Admin123"
I created the following 3 Classes:
1) Login tests: Which contains all the Login (1 +ve and 2 -ve scenarios) and Logout test (Total 4 #Tests)
2) Register Patient test: Which will register a patient and also verify if the patient has been registered successfully (Total 3 +ve #Tests)
3) Capture Vitals test: Which will Capture Vitals of the patient registered above and verify if the details captured are correct. (Total 2 +ve #Tests)
I'm planning to add a few more Classes which will contain tests related to Adding Visits, adding Allergies etc.
There is a dependency between the classes i.e. only execute the Register patient test if the #Test for Login passes. Similarly, execute the remaining tests like capture vitals, adding visits, adding allergies only if the Register patient test passes. However, there is no dependency between the capture vitals, adding visits and adding allergies and can run in parallel.
This is how it looks from a top-level:
class Login
#Test T_001_LoginTest
#Test T_002_LogoutTest
class RegisterPatient
#Test T_003_RegisterNewPatient
#Test T_004_ConfirmPatientRegisteredUsingPatientID (dependent on T_003)
#Test T_005_ConfirmPatientRegisteredUsingPatientName (dependent on T_003)
class CaptureVitalsTest
#Test T_006_CreateAVisitAndCaptureVitals (dependent on T_001 and T_003)
#Test T_007_VerifyVitals (dependent on T_006)
What I have done so far is added defined group "login" for class Login and group "registerpatient" for class Register. For class RegisterPatient, I've added dependsOnGroup "login". Similarly, for class CaptureVitals, I've added dependsOnGroups for both "login" and "registerpatient". I've also set alwaysRun = true for the #Test Methods which have "dependsOnMethods" dependency.
Below is my testng.xml file
<suite name="Open MRS Automation" parallel="tests">
<listeners>
<listener class-name="com.utils.CustomListener" />
</listeners>
<test thread-count="5" name="Login Test">
<classes>
<class name="com.testcases.LoginTest" />
</classes>
</test> <!-- Test -->
<test thread-count="5" name="Register Patient Tests">
<classes>
<class name="com.testcases.RegisterPatientTest" />
</classes>
</test>
<test thread-count="5" name="Capture Vitals Tests">
<classes>
<class name="com.testcases.CaptureVitalsTest" />
</classes>
</test>
</suite>
What would be the right approach in setting initial sequential and then parallel execution of the tests? Any help would be appreciated! Thanks.
You should give Testcases method name by numbers.
you must be using excel sheet for data provider format that will help you run test cases according to Testcases number
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
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/
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.
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.