Parallel Browser Execution Possible in Cucumber (Java / Maven)? - selenium

Parallel Browser Execution Possible in Cucumber (Java / Maven)?
For example I know its definately possible using TestNG when Cucumber is not involved, but is it even possible embedding Java, Cucumber, jUnit and TestNG together?
I have tried the following TestNG.xml file which points a runner class which then point to multiple feature files but have had no success :/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Automation_Scripts" verbose="2" parallel="classes" thread-count="2">
<listeners>
<listener class-name="Framework.utilities.RetryListner"></listener>
</listeners>
<test name="Automation Tests">
<packages>
<package name="TestFramework.ncc.*"></package>
</packages>
</test>
</suite>

There are no built in capabilities in cucumber for this as far as I know, but I have seen an approach where different sets of Cucumber scenarios are run by different junit classes which are then run in parallel.
Defining which scenarios are run by which class can be achieved by using either tags or defining different features for he different runner classes.
There is a maven plugin that seems to automate that approach: https://github.com/temyers/cucumber-jvm-parallel-plugin

This can be done using TestNG using cucumber.
For achieving this, you have to have independent test runners for each feature file.
eg:
TestRunnerA points to feature A in some folder
TestRunnerB points to feature B in some folder or the same
Specify the exact file in features (in cucumber options) if all features are in same folder.
And then you can specify them as separate testsin testNG xml and they will run parallely.
A sample of it can be seen here
Link

Jithu Paul answer is how this is typically approached, and this is mainly because each runner class needs to have slightly unique cucumber options for outputting test results (i.e. unique JSON file names). This roundabout way is due to not being able to parameterise Java annotations. However you can rename cucumber options dynamically using java reflection.
This project has a good example:
https://github.com/workpeter/ARGOS
In particular the runner class. As of today its located here:
https://github.com/workpeter/ARGOS/blob/master/src/test/java/integrationTests/cucumber/Runner.java

Related

Execute multiple testng.xml simultaneously

I need to run my tests in parallel but , tried to parallelize them and unfortunately it doesn't look very stable!
My new idea is to run different .xml ( one for each browser) but i need to do that in parallel
is there any way to make this stuff?
Right now i start my session by using ant
You could try with:
java org.testng.TestNG -suitethreadpoolsize 3 testng1.xml testng2.xml testng3.xml
Depending on your suite, you could also add the parallel parameter:
<suite name="My suite" parallel="tests" thread-count="5">
Check more info here.

Copied Selenium script on different local machine not running using testng.xml

I have selenium test script written on one of my local machine and it works fine on it using testng.xml
I have copied the same script to different local machine and am trying to execute it using testng.xml by right clicking on testng.xml and selecting run as testng suite but nothing happens.
No error is shown neither script is executed or browser is instantiated.
There is no error in the project. I have added all the requred jar files.
Can any one help me with any pointer.
<?xml version="1.0" encoding="UTF-8"?>
<suite name="XXXXX">
<test name="testScripts">
<parameter name="superAdmin" value="superAdmin"/>
<parameter name="participant" value="participant"/>
<classes>
<class name="testScripts.ParticipantSide" />
</classes>
</test>
Running testng.xml from run as > configuration and specifying the suite, runs the scripts
It is running by manually specifying the suite to execute. It is still not running directly via path right click on testng.xml > Run As > TestNg Suite
Try to add the full path of your class as local machine is different. Try to build and compile or clean the entire source code and try again. Because testNG.xml seems to be the correct one.
Facing this very similar issue after I updated TestNG yesterday. In my case, I haven't copied Selenium Suite from anywhere, it was built from scratch on the very same machine that I am using at the moment.
But after I updated TestNG yesterday, I now have to go through Run > Run Configuration > path\to\testng.xml (in Suite field) and then Run it.
It doesn't work if I simply right click on testng.xml and do Run As > TestNG Suite

Is it possible to run several TestNG suite files in one configuration in IntelliJ IDEA? [duplicate]

This question already has answers here:
Can TestNG run multiple suites?
(5 answers)
Closed 5 years ago.
I have several TestNG suite files across my multi-module java project, it's structure looks like this:
project\
module1\src\test\resources\
suite1.xml
suite2.xml
module2\src\test\resources\
suite3.xml
Is it possible to create run configuration including all these suites in IntelliJ IDEA?
I am able to create separate configuration for each of them via Run/Debug Configurations - TestNG - Configuration - Suite, but I don't see a way to select multiple files there.
I cannot merge all test suites into single suite because some tests use Before/After Suite methods.
I am using IntelliJ IDEA 14.1.2 Community edition, TestNG 6.1.1.
TestNG per se supports the execution of multiple suite files - you can run java org.testng.TestNG suite1.xml suite2.xml suite3.xml
I haven't found a way to specify multiple suite.xmls in IntelliJ, so I created a master suite using the undocumented suite-files tag. It looks like this:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1" >
<suite-files>
<suite-file path="suite1.xml"/>
<suite-file path="suite2.xml"/>
</suite-files>
</suite>
This suite file is runnable by IntelliJ and should include all tests, with their correct before/after methods.

Trying to automate with Selenium in parallel, but multiple webdriver instances freak out

So I'm trying to create a java program that uses Selenium to automate a WebDriver to perform tasks on a website. At the moment, I'm using it for work in order to automate an annoying task where the user has to upload files to our database. I've already successfully made a program which automates this, and saved myself hours of manual work.
Now I'm trying to get the program to run multiple browsers in parallel. I want to do this in order to speed up the rate at which I can upload files because most of the time is lost waiting for pages to load.
I've tested this with a much simpler version of my program and have managed to speed up simple tasks by 2-10 times by having tens to hundreds of threads open with their own WebDrivers.
The problem is, whenever I run more than 1 WebDriver the entire thing begins to randomly freak out at times, and at other times not work at all. I tried to use 'PhantomJSDriver' along with the latest 'PhantomJS.exe', however at times it would work, and most of the times it would do nothing. The same program that runs flawlessly with one driver running breaks down when they are ran in parallel.
I've been trying to find reasons as to why this happens and ways around it, but I haven't found anything definite that I can use.
How can I go about automating web browsing in parallel with Selenium if possible, and if not, where should I look to in order to do this?
This is what you need, it is called "Selenium Grid"
http://selenium-grid.seleniumhq.org/
Actually using Grid you can automate the tests in parallel using a same machine or by using multiple machines (here machines in the sense of individual computers).
I hope this link will show you how to run a tests in parallel in same machine.
In the above given link the user said to create a five different programs to run in parallel. If you want to run single program in parallel, then just use TestNg or Junit to trigger multiple instance.
This is the sample TestNg config code to run a test in parallel. Here i ran two threads. So it will invoke the TestNg #Test method of a given class file com.test.workflow.device.testcase20 in two threads.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite1" parallel="test" thread-count="2">
<test name="Testcase20" >
<classes>
<class name="com.test.workflow.device.testcase20"/>
</classes>
</test>
</suite>
By using above xml file you can acheive parallelism in webdriver using grid.
You could try with Sahi http://sahi.co.in/. It can run multiple instances of browsers in parallel.
Do look at how Sahi does file uploads though. http://sahi.co.in/w/_setFile
It's possible to run selenium instances concurrently. When selenium runs browser instances, it opens the connection on port 7055 by default.
So, if you want to run multiple instances, you have to run them on different ports.
I would suggest that you build a driver for each browser and let your code know that you use more than multiple drivers. Other suggestion as already described above, using Selenium Grid is the best solution available:
https://sqa.stackexchange.com/questions/5431/how-to-open-multiple-browsers-using-webdriver
https://github.com/SeleniumHQ/selenium/wiki/Grid2
if you use webdriver , try maven-surefire-plugin :
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<forkCount>4</forkCount>
</configuration>
</plugin>
</plugins>
in code use option 'forkCount' value 4 - number of processors. 4 processors = 4 JVM. U can start webdriver for each JVM !
link info http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html

ReportNG does not provide any report

I heard that ReportNG creates a better report than TestNG's normal report. I tried to create ReportNG report, but failed. I am using Eclipse and I have downloaded ReportNG and added reportng-1.1.3.jar and velocity-dep-1.4.jar into classpath and written testng-suite.xml as below:
<suite name="SA" verbose="10">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
...
</suite>
when I executed I could see the TestNG default report rather than ReportNG report. What else should I do to get ReportNG's report (like extend any class or implement listeners or write snippet of code)?
Also I heard that I have to use the command, useDefaultListeners="false" , but where should I include in the testng-suite.xml? Everyone is telling about ANT but I don't personally like it to use. So is there any way to include the above command into testng-suite.xml?
I am the author of ReportNG. You don't need to write any Java code to get it to work. You just need to be able to register listeners with TestNG from whichever tool you use.
I've only used ReportNG from Ant but other people have got it working with other build systems such as Maven and Gradle. I don't know if there is anything Selenium-specific that would prevent it from working. Are you getting any error messages? The first thing I would check is to make sure that the ReportNG JAR is on the classpath.
I didn't even realise that you could specify TestNG listeners in the testng.xml file. However, I have just modified my sample reports to specify the listeners in this way rather than in the Ant build file and it works fine, so the problem is probably in the way you are configuring TestNG from Selenium.
How are you launching from Eclipse? You should be right-clicking on that XML file and select "Run as... TestNG suite". I'm assuming that's what you're doing.
Using default listeners should not have any impact on the problem you are seeing, I am guessing that some people use this because if they use ReportNG, they don't care about any of the other listeners that TestNG generates. Having said that, if you ever want to do this from Eclipse, you can simply edit the launch configuration that was created when you launched your suite as indicated above and add "-usedefaultlisteners false" to the parameters box.
To disable defaultlisteners ,
Goto Eclipse Project-> Properties -> TestNG -> Disable deafult listeners.
After running you will end up with following error:
java.lang.NoClassDefFoundError: com/google/inject/Module
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.getMethods(Unknown Source)
to solve this, download google-guice-3.0.zip and paste guice-3.0.jar into your classpath.
Now run and check the report in workspace/test-output/html.