Parallelisation in TestNG not working - selenium

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"

Related

in testng.xml run as testng suit triggers IE browser & run each test manually it runs with chrome. Why so?

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 -->

How to run test cases in different Java classes in a new window every time using TestNG and Selenium

I have 15 test methods in 3 Java classes (Selenium Script). I want to run each Test class with new window. I am using TestNg framework.
Here is the code of TestNG:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Fanfight Test" thread-count="10" parallel="methods">
<listeners>
<listener class-name="com.fanfight.test_case.ListenerClass">
</listener>
</listeners>
<test name="User Login" parallel="false">
<classes>
<class name="com.fanfight.test_case.UserLogin"></class>
</classes>
</test>
<test name="Contest Creation" parallel="false" >
<classes>
<class name="com.fanfight.test_case.ContestCreation"></class>
</classes>
</test>
<test name="User Profile Test" parallel="false" >
<classes>
<class name="com.fanfight.test_case.UserProfileTest"></class>
</classes>
</test>
<test name="Menu Bar Test" parallel="false">
<classes>
<class name="com.fanfight.test_case.MenuBarTest">
</class>
</classes>
</test>
<test name="Home Page Elements" parallel="false" >
<classes>
<class name="com.fanfight.test_case.HomePageElementTest"></class>
</classes>
</test>
</suite>
Without using parallel="false" my script is running in alphabetical order due to which selenium unable to find the path and execution got stuck.
Also please suggest how to make execution continue even after getting an exception during execution.
Add a setup and tear down method in each of the 3 test classes. The setup method should launch the browser and teardown method should close that browser instance.
class TestOne {
WebDriver driver;
#BeforeClass
public void setup(){
driver = new ChromeDriver();
}
#Test
public void testCase1(){
}
//.... Other test methods
#AfterClass
public void tearDown(){
driver.quit();
}
You can also create a parent class having just the setup and tear down methods , pseudo coded above. All 3 of your test class shall extend this parent class. It will be an optimised approach as the driver instantiation and destruction is now centralised to a single class.
And finally , change the parallel attribute in the suite tag of your testNG xml, in order to make them run parallel.
<suite name="Fanfight Test" thread-count="10" parallel="classes">

Test method not run with sequence in testng

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

TestNG Parameter behaving inconsistently when executed multiple time

I want to run multi-browser testing. For that, this is my testng.xml
<suite name="MultiBrowsreTest" parallel="tests">
<test name="T1" >
<parameter name="browser" value="firefox"/>
<classes>
<class name="com.core.My"/>
</classes>
</test>
<test name="T2" >
<parameter name="browser" value="chrome"/>
<classes>
<class name="com.core.My"/>
</classes>
</test>
</suite>
And Here is my Java program.
public class My {
HH h ;
#Test
#Parameters("browser")
public void my1(String browser){
h = new HH();
h.browser = browser;
System.out.println("Browser: "+h.browser);
}
}
When I run the program,it gives me different output all the time. i.e.
1:
Browser: firefox
Browser: firefox
2:
Browser: chrome
Browser: firefox
3:
Browser: chrome
Browser: chrome
4:
Browser: firefox
Browser: chrome
Can someone please suggest me the solution so that I will get consistent result
parallel=true executes all tests at a time(in parallel) and hence whichever test it gets first is executed first.So, test order is not maintained and hence different outputs every time.
Make parallel = none, and it will follow the order as mentioned in testng xml.
<suite name="MultiBrowsreTest" parallel="none">

Maven issue:Regarding Testng

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();