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
Related
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
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.
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
I have a PHP project written in PHPUnit using Selenium.
The project is structured as below:
PHPProjectName
Source Files
(doesn't contain anything)
Selenium Test Files
contains all my selenium test php files - extending the class PHPUnit_Extensions_SeleniumTestCase
Include Path
c:\program files\PHP
c:\program files\PHP\PEAR\PHPUnit
I then run start the Selenium server manually by running java -jar selenium-server-standalone-2.24.1.jar
The php script to execute all my selenium test php files works fine.
But now I want to use Jenkins as a test management tool to build and execute my PHPunit tests in this folder. I guess the steps are:
Install Jenkins
Write a build script for the PHPunit tests
Execute the build script through Jenkins
Are the steps correct? Has anyone done or know how to set this up?
Thanks very much,
I have done this many times with various platforms. Your steps are generally correct and should work, however managing the server is not always so simple. The Selenium RC server gets unstable if left open for too long, so you will have to manage it somehow.
You could set up a second Jenkins job which runs once or twice a day to reset your server. The better option however would be to write a simple test framework which closes any open servers and then launches a new server instance before running the tests. You could also use a cron job to reset the server of course, but if you have Jenkins installed it will be easier to do this via a jenkins job.
The best option of course is to switch to Webdriver, but that could take some work depending on how complex your tests are.
We have a similar setup to what you describe. We have Jenkins run a job to restart the Selenium server periodically:
#!/bin/bash
# startselenium.sh: Start Selenium up and also start headless screen.
Xvfb :99 -ac &
export DISPLAY=:99
java -jar /opt/selenium/selenium-server-standalone-2.19.0.jar &
Sebastian Bergmann maintains a bunch of templates for using Jenkins with PHP here:
http://jenkins-php.org/
Included is the necessary Ant script to run PHPUnit (which is really simple and just calls PHPUnit):
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="phpunit" failonerror="true"/>
</target>
And the necessary 'phpunit.xml' file:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php"
backupGlobals="false"
backupStaticAttributes="false"
strict="true"
verbose="true">
<testsuites>
<testsuite name="ProjectName">
<directory suffix="Test.php">tests/unit/</directory>
<directory suffix="Test.php">tests/integration/</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="build/coverage" title="BankAccount"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
<exclude>
<file>src/bootstrap.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
You have to install the selenium plugin in jenkins, then a selenium server will automatically start on jenkins, which will create a hub. Now on the client you have to start a node which connects to this hub.
Note: The jenkins selenium server is always the same version as the selenium plugin from jenkins. So if the selenium plugins name is
selenium plugin 3.1.0 then it runs on selenium server 3.1.0.
After installing the jenkins selenium plugin, then you can find a new option for selenium grid, click on it and you will get more informations:
Now you have to start a jenkins selenium standalone server like this:
Windows (create a .bat file with the following content and execute it, change relevant parts accordingly):
start java -jar -Dwebdriver.gecko.driver="C:\Webdrivers\GeckoDriver\geckodriver.exe" -Dwebdriver.chrome.driver="C:\Webdrivers\ChromeDriver\chromedriver.exe" selenium-server-standalone-<VERSION>.jar -role node -hub http://<YOUR_JENKINS_MACHINE_IP>:<PORT>/grid/register
In my case, I used:
start java -jar -Dwebdriver.gecko.driver="C:\Webdrivers\GeckoDriver\geckodriver.exe" -Dwebdriver.chrome.driver="C:\Webdrivers\ChromeDriver\chromedriver.exe" selenium-server-standalone-3.1.0.jar -role node -hub http://172.25.201.100:4444/grid/register
Make sure to correct the paths to geckodriver and chromedriver to their actual location.
Now the node should connect to the hub and you can start your tests.
More infos:
https://github.com/SeleniumHQ/selenium/wiki/Grid2
I want to run all the scripts one by one sequentially. I've created a suite file and included scripts in suite. When I run a suite, the scripts run in parallel in multiple browsers. I would like to run them one after the another in a single browser.
You can run a suite file from a single browser by changing the Threads in the ant target.
<target name="runbrowsertests">
<sahi suite="../userdata/scripts/demo/demo.suite"
browserType="firefox"
baseurl="http://sahi.co.in/demo/"
sahihost="localhost"
sahiport="9999"
failureproperty="sahi.failed"
haltonfailure="false"
threads="1"
>
<report type="html" />
</sahi>
</target>
If it still doesn't work, edit browser_types.xml (Click "configure" link on dashboard). Change <capacity> to 1 for the browser that you want to run the tests with. Restart Sahi.