Selenium run same test on different platforms in parallel - selenium

I have three classes with different tests that I want to execute on chrome browser. The most important thing is that I want to run in parallel on Windows and macOS. How should I do it on Selenium 4 with Hub - > node setup?
My testng file looks like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Suite 1" parallel="classes" verbose="1" >
<test name="Test windows and macOS">
<classes>
<class name="test1"/>
<class name="test2"/>
<class name="test3"/>
</classes>
</test>
</suite>
When test is executed tests are running only on Windows with two browser windows.
Selenium documentation doesn't explain how to do this.

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"

i am unable to run cucumber jvm test in selenium grid in parallel

I am testing cucumber jvm with Test NG XML for selenium grid parallel execution on both firefox and chrome.
In TestNG XML,i have given class file as Cucumber runner.java file and this java file contains the path of my features.
When I ran my testNg.xml, I am not getting any response and i can see blank test NG reports.
Note: i tried the same script in Junit cucumber in grid for chrome and working fine.
Added annotation #parameter("BrowserName") on test case.java file which need to be tested on both chrome and firefox.
TestNG.xml
<!-- package name Test1,Cucumber runner file name= runner>
<suite name="Test1" verbose="3" parallel="tests" thread-count="2">
<test name="Run on Firefox">
<parameter name="browserName" value="firefox"/>
<classes>
<class name="Test1.runner"/>
</classes>
</test>
<test name="Run on chrome">
<classes>
<parameter name="browserName" value="chrome"/>
<class name="Test1.runner"/>
</classes>
</test>
</suite>
and please tell me the details steps to integrate with jenkin. Jenkins integrate with cucumber jvm for grid -parallel testing.
My last question, I am new to grid, i would like to know that we can see all the browsers running on multiple node or we cant see any thing other than results when running via Jenkins.
Thanks,
Senthil
First of all, put '' tag above '' in Chrome section.
Secondly, to execute your tests through Jenkins you can use following link: http://moduscreate.com/integrating-bdd-cucumber-test-suites-jenkins-3-steps/
Thirdly, to view the browsers/instances running on Grid, navigate to following URL on hub machine 'http://localhost:4444/console' and further click on 'Console' link. You will be able to see all the nodes connected to Hub and also the different instances running on nodes..

How to run parallel test cases in selenium grid?

I have only one test case and i want to run that particular test case on two different machines say one in windows and other linux. How can i configure my nodes or selenium framework so that it can run my test case parallely on different machines at the same time.I have done following changes in my framework to run it on single machine.
DesiredCapabilities cap = new DesiredCapabilities();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.ANY);
driver = new RemoteWebDriver(new URL(nodeURL), cap);
Step 1 - create two runnable JAR files (my own approach) containing the one test for linux and one test for windows. Possibly differentiate by this line:
cap.setPlatform(Platform.LINUX);
and
cap.setPlatform(Platform.WINDOWS);
Capabilities taken from head, so pleasde doublecheck
Step 2 - start hub and two nodes
Step 3 - run the two JARs from your computer (assuming the JAR will have configured where the hub is). The hub will assign tests to nodes automatically
If you have additional questions, ask me ;)
I think you can try TestNG.
On my approach I have two parameters: OS and BROWSER.
With testng.xml you can create your testsuite with those parameters like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Your_suite" verbose="2" **parallel**="tests" >
<test name='Your_Test_Name'>
<parameter name='os' value='**WINDOWS**'/>
<parameter name='browser' value='CHROME'/>
<classes>
<class name='tests.AnyTest'/>
</classes>
</test>
<test name='Your_Test_Name'>
<parameter name='os' value='**LINUS**'/>
<parameter name='browser' value='FIREFOX'/>
<classes>
<class name='tests.AnyTest'/>
</classes>
</test>
</suite>
So I can run my test on windows, linux, macOS, android or iphone, and the most important thing, I don't have to change my code.
Hope it helps.

Using TestNG to file Selenium test - But NOT Parallel

This is my first question here, and I will be very happy to be helped.
I have been using TestNG as a part of my framework for a long time now.
And the question I have today is about the testng.xml configuration - to NOT run tests in parallel. And NO, none of my tests are dependent, they are all independent. But, this is for my requirement.
My testng.xml file looks like this:
<suite name="Smoke Test Suite" verbose="3" parallel="tests" thread-count="2">
<test name="Run on Firefox" preserve-order="true">
<parameter name="browser" value="firefox"/>
<classes>
<class name="com.test1"/>
<class name="com.test2"/>
<class name="com.test3"/>
<class name="com.test4"/>
</classes>
</test>
<test name="Run on IE9" preserve-order="true">
<parameter name="browser" value="iexplore"/>
<classes>
<class name="com.test1"/>
<class name="com.test2"/>
<class name="com.test3"/>
<class name="com.test4"/>
</classes>
</test>
<test name="Run on Google Chrome" preserve-order="true">
<parameter name="browser" value="chrome"/>
<classes>
<class name="com.test1"/>
<class name="com.test2"/>
<class name="com.test3"/>
<class name="com.test4"/>
</classes>
</test>
I want the Tests to run in Parallel, but the classes to run one after the other.
What I am currently seeing is that when the test is fired off, I have 8 instance of FF, IE9 and Chrome open up. How can I configure it so that "test1" is executed, the browser is closed, new instance opened and then "test2" is run and so forth?
The reason for me having to do this is that, my app has multiple windows opened during each test. And IE9 (being the evil browser it is) does not know how to handle the situation, panics and loses focus on the window midway through the test. It has been suggested, and I have found the same - that it is best to have one instance of IE9 running with nothing else interrupting it.
Suggestions and solutions will be gratefully accepted.
NOTE: All classes are in the same package.
Thanks,
-Alister
You can create Three objects for DefaultSelenium in your #Before method.One for IE, One for FF and One for chrome.
If you are using webdriver you can create 3 separate drivers for the same.
You could use three separate suites (xml files) then add them one after the other in the command line. That has the effect of running them in sequence.

unable to run selenium2 suite in testNG

I am not able to run test suite in eclipse with testNG for selenium2.
TestNG appears to run, but the Total tests run is always 0.
I am able to run this test from eclipse directly with selenium2 (run as->java application).
I am able to test the testNG for a small program with #Test, #BeforeMethod,#AfterMethod annotations
kindly help me
xml file contents
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="WikiPedia test" verbose="3" parallel="methods" >
<test name="wiki">
<classes>
<class name="com.programs.WebDriverTest" />
</classes>
</test>
</suite>
You need to Run As...TestNG Test, not as Java application.