I am using TestNG + WebDriver for my automation project but order of test execution is not working as expected have specified the order for each method below is the method signature and notation
#Test(dependsOnMethods="verifyElementsOnProfileScreen",alwaysRun = true)
public void verifyMySelfProfileVisibility(){
TestSuit the I have using :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="regressionSuite" parallel="none">
<parameter name="ApplicationOpt" value="web"></parameter>
<parameter name="Browser" value="firefox"></parameter>
<test name="Test">
<classes>
<!-- Login Module -->
<class name="Tests.Login.LoginApp"/>
<method>
<include name ="loginUser"></include>
</method>
<!-- Portal Module -->
<class name="Tests.Profile.ProfileModule">
<method>
<include name="verifyElementsOnProfileScreen"></include>
<include name="verifyMySelfProfileVisibility"></include>
</method>
</class>
<class name="Tests.Profile.participantAuditLog">
<method>
<include name="verifyAuditLogForCreateProfileEvent"></include>
<include name="verifyAuditLogForUpdateContactInfoEvnet"></include>
<include name="verifyAuditLogForUpdatePrivacyDirective"></include>
</method>
</class>
</classes>
</test> <!-- Test -->
</suite> <!-- regressionSuite -->
Do you mean Classes which specified in testng.xml file not executing in specified order.. then please use preserve-order= "true"
<suite name="MySuite" preserve-order= "true">
<test name="MyTest">
If you want to specify order of methods execution in Class then use priority
#Test( priority = 1 )
group-by-instances="true" also useful if you face situation like execution order of priority methods of different classes are not as expected..
<suite thread-count="2" verbose="10" name="testSuite" parallel="tests">
<test verbose="2" name="MytestCase" group-by-instances="true">
Thank You,
Murali
Related
Is there any way to run these two xml files parallel?
test1.xml
<?xml version="1.0" encoding="UFT-8">
<suite name="Runner">
<listeners>
<listener class-name = "package1.Tester"/>
</listener>
<parameter name = "Excel name" value = "Excel1"/>
<test name = "Excel" parallel = "tests" thread-count="1" verbose = "2">
<classes>
<class name = "package2.Run"/>
</classes>
</test>
</suite>
test2.xml
same as test1.xml only the parameter value differs from Excel1 to Excel2
1 You have an issue in testNG XML:
Instead of <?xml version="1.0" encoding="UFT-8"> (note UFT is typo, also ? missed) should be <?xml version="1.0" encoding="UTF-8"?>.
2 Once you fix this, just create 2 files test1.xml, test2.xml as you want and create a new runSuites.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Run-all-testNG-files">
<suite-files>
<suite-file path="test1.xml"/>
<suite-file path="test2.xml"/>
</suite-files>
</suite>
when i run with testng.xml then IE browser opens with the message "This is the initial start page for the WebDriver server."
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "testng.org/testng-1.0.dtd"> <suite name="abc"> <groups> <run> <!-- include name = "HC"></include> --> <!--include name = "Reg"></include> --> <include name = "test"></include> </run> </groups> <test name="regression"> <classes> <class name="A"></class> <class name="B"></class> <class name="C"></class> </classes> </test> </suite> <!-- Suite -->
I am using maven with testng 6.14.3.
Here is my code structure:
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="set-3" parallel="tests" thread-count="10">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
</listeners>
<test name="Customer Tests">
<groups>
<run>
<include name="abc"/>
</run>
</groups>
<classes>
<class name="apps.Test1_BeforeTest_Of_Test2"></class>
<class name="apps.Test2"></class>
</classes>
</test>
</suite>
Test1_BeforeTest_Of_Test2.java
public class Test1_BeforeTest_Of_Test2{
#BeforeTest(groups = {"abc"})
public void test1Method() throws Exception {
}
#AfterTest(groups={"abc"})
public void test1AfterMethod() throws Exception {
}
}
Test2.java
public class Test2{
#Test(groups = {"abc"})
public void test2Method(){
}
}
During my run, Test1_BeforeTest_Of_Test2 class fails. So, Test2 is marked as skipped.
But, when I look at the testng-failed.xml that is generated at the end of the run, the failed #BeforeTest class (Test1_BeforeTest_Of_Test2) is not included/listed:
testng-failed.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite thread-count="10" name="Failed suite [set-3]" parallel="tests">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
</listeners>
<test name="Customer Tests(failed)">
<groups>
<run>
<include name="abc"/>
</run>
</groups>
<classes>
<class name="apps.Test2">
<methods>
<include name="test2Method"/>
</methods>
</class>
</classes>
</test>
</suite>
Is this expected behaviour? Or a bug/gap in testng-failed.xml?
Ideally, when we re-run the failed tests, we expect the #BeforeTest to run as well, because it is pre-req for Test 2.
TestNG currently seems to be honouring configurations to be considered in the testng-failed.xml if its part of the skipped test method's test class i.e., the configuration (which is perhaps what has caused a test to be skipped) needs to reside in the same java class as your skipped method for TestNG to consider it to be included.
In your example, that's not the case and the configuration method exists in a different test class (which is perfectly valid).
This looks like a bug in TestNG to me.
I have submitted a bug on your behalf on the TestNG project and will get it fixed in the upcoming version (7.5.0).
Defect : https://github.com/cbeust/testng/issues/2611
When I execute below code, TestNG executes first MyTest1, after that it moves to MyTest2; it does not executes all 4 classes simultaneously.
<suite name="MySuite" parallel="tests" thread-count="6">
<test name="MyTest1">
<classes>
<class name="ParllelTestNG.Test1"></class>
<class name="ParllelTestNG.Test2"></class>
</classes>
</test>
<test name="MyTest2">
<classes>
<class name="ParllelTestNG.Test3"></class>
<class name="ParllelTestNG.Test4"></class>
</classes>
</test>
</suite>
Is anything wrong with this code?
Are MyTest1 & MyTest2 executing in parallel??
This is because you have written parallel=test in below line
<suite name="MySuite" parallel="tests" thread-count="6">
Change parallel="tests" to parallel="classes"
I have a module A which runs through pom.xml and accesses a testng.xml which in turn calls a specific class.This class displays a list of things for the user to choose from.
I am taking the user value through bufferRead.The bufferRead does not detect the value entered by the User.
ie
Enter the test u want to run
1.Test1
2.Test2
3.Test3
1
(control never goes to the next line)
There goes my pom.xml
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>`
This is my testng.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><suite allow-return-values="false" configfailurepolicy="skip" data-provider-thread-count="10" group-by-instances="false" junit="false" name="Suite" parallel="false" preserve-order="true" skipfailedinvocationcounts="false" thread-count="5">
<test allow-return-values="false" group-by-instances="false" junit="false" name="Test" preserve-order="true" skipfailedinvocationcounts="false">
<classes>
<class name="com.org.Console1"<methods>
<include name="main" />
</methods>
</class>
</classes>
</test> <!-- Test -->
This is my java code that runs
System.out.println("Which tests do you want to run");
String input = bufferRead.readLine();