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.
Related
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.
I am trying to do some cross browser testing on selenium by connecting to browser stack so that I can test on multiple browsers at the same time.
At the moment I am using a testng xml file to set up my browsers for testing (see code below) and running my tests from there in parallel.
I will possibly be doing this for at least 15 different browser/device types and was wondering if it is a good idea to continue using this approach. Or will selenium grid be better? Any suggestions will be appreciated :)
testng xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="2" name="test.java" verbose="1" annotations="JDK" parallel="tests" >
<test name="Test - Chrome">
<parameter name="browser" value="chrome"/>
<parameter name="browserVersion" value="74.0 beta"/>
<parameter name="os" value="OS X"/>
<parameter name="osVersion" value="Mojave"/>
<parameter name="resolution" value="1024x768"/>
<classes>
<class name="EndToEnd"/>
</classes>
</test>
<test name="Test - Firefox">
<parameter name="browser" value="firefox"/>
<parameter name="browserVersion" value="66"/>
<parameter name="os" value="OS X"/>
<parameter name="osVersion" value="Mojave"/>
<parameter name="resolution" value="1024x768"/>
<classes>
<class name="EndToEnd"/>
</classes>
</test>
</suite>
set up class:
#BeforeTest
#Parameters({"browser", "browserVersion", "os", "osVersion", "resolution"})
public void setUp(String browser, String browserVersion, String os, String osVersion, String resolution) throws Exception
{
DesiredCapabilities capability= new DesiredCapabilities();
capability.setCapability("browser", browser);
capability.setCapability("browser_version", browserVersion);
capability.setCapability("os", os);
capability.setCapability("os_version", osVersion);
capability.setCapability("resolution", resolution);
capability.setCapability("browserstack.local", "true");
capability.setCapability("browserstack.localIdentifier", "Test123");
driver = new RemoteWebDriver(new URL(URL), capability);
}
To be honest I would setup the hub with different nodes capabilities and just let the grid to distribute that across the nodes rather than having it in test NG.
There is a good article here , which might help you understand better .
https://dzone.com/articles/selenium-grid-tutorial-setup-and-example-of-cross
There are two parts to the question here.
The selenium grid comes into picture only when trying to setup the infrastructure needed for your browser/mobile automation. When I say infrastructure I mean the following :
Browser flavor and version/ Mobile device flavor and version
OS version
Apart from setting up the infrastructure needs for automation, the grid also lets you do remote execution (so that your local machine can be freed from executing test automation actions on browser)
If you would need to run your tests on different browser+OS combinations, then TestNG suite xml is perhaps the right and recommended way of doing it.
When you express your browser flavor/version/platform combinations as values via the testng xml file, and then use that to construct your DesiredCapabilities what you are essentially doing here is constructing the english statement "I would like to run this test on a firefox browser version 66 running on an OSX machine".
The grid on the other hand is meant to answer to questions such as
I can run your test that is intended to run on firefox browser version 66 running on OSX machine.
I currently dont have any machine associated with me, that can support Internet Explorer on Windows 10 (because I dont have any machines like that with me)
The distribution of the test is the responsibility of Grid.
Specifying the requirements for cross browser automation via a test would be the responsibility of a test case. Here TestNG enables you to specify this requirement via your test case, by providing various different means of parameterizing the intent (Suite xml file is one such means)
I have a selenium test which tests my target web application.
I want to run the same test on Jenkins concurrently on Nightly and Staging environments.
What is the better way to do that? I am ok to approach it on Jenkins or on Selenium Grid or any other way.
I explored Selenium Grid but they talk of executing different tests parallel on multiple envs. But my specific requirement is that I have to run SAME TEST CONCURRENTLY on the same browser instance or on different browser instance.
Ex: Consider this test, com.myorg.myapp.myTest.testLogin(String envURL)
I would like to run this test concurrently on Chrome (for ex) by passing Nightly and Staging URLs.
At present I am running first set of tests on Nightly followed by the same tests on Staging. This takes almost a day. I need to do them concurrently to save time.
You can create a testNG xml and add the same test to different suites likes this.
<suite name="mySuite" parallel="tests">
<test name="thread1">
<classes>
<class name="test.sample.MyTest"/>
</classes>
</test>
<test name="thread2">
<classes>
<class name="test.sample.MyTest"/>
</classes>
</test>
...
...
<test name="threadN">
<classes>
<class name="test.sample.MyTest"/>
</classes>
</test>
</suite>
If you need to pass the environment add the following and access it from the code of a test as described here (http://testng.org/doc/documentation-main.html#parameters)
<parameter name="env" value="staging"/>
This is a simple solution yet quite ugly and harder to maintain if you need a lot of threads. Another way is to create your XML in code by implementing IAlterSuiteListener. See TestNG Parallel execution with selenium for the code sample.
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..
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.