Before posting this I checked a lot on this site and on google to figured out my problem.
I am testing my web application which is principally coded in PHP using Symfony2 framework.
I am using Selenium to do my functional tests. All I want to do for the moment is to run my functional tests in parallel on my local machine using Selenium Grid. What I do is recording the test on Selenium IDE and export the test case in phpunit format. I tried to use selenium grid but my phpunit tests are still running sequentially.
What I did:
1) java -jar selenium-server-standalone-2.24.1.jar -role hub
2) java -jar selenium-server-standalone-2.24.1.jar -role node -hub http://localhost:4444/grid/register -browser "browserName=firefox,maxInstances=2,maxSession=2"
3) ant
There is in my build.xml a phpunit target:
<target name="phpunit" description="Run unit tests">
<exec executable="phpunit" failonerror="true"/>
</target>
In my phpunit.xml this part of code is present:
<testsuites>
<testsuite name="LoginSuite">
<file suffix="Test.php">../../src/Tests/FunctionalTests/LoginSuite_testLoginTest.php</file>
</testsuite>
</testsuites>
And my LoginSuite_testLoginTest.php looks like this:
<?php
namespace Tests\FunctionalTests;
use Tests\FunctionalTests\SetUpTest;
class LoginSuite_testLoginTest extends SetUpTest
{
public function testLogin()
{
$this->open("/home");
$this->click("link=Login");
$this->type("id=username", "test.user#gmail.com");
$this->type("id=password", "test");
$this->click("id=_submit");
$this->waitForPageToLoad("30000");
}
public function testLogin2()
{
$this->open("/home");
$this->click("link=Login");
$this->type("id=username", "test.user2#gmail.com");
$this->type("id=password", "test");
$this->click("id=_submit");
$this->waitForPageToLoad("30000");
}
}
?>
At the third step when I launch ant command I am getting a jetty error 500 Problem accessing /selenium-server/driver/
If instead of doing:
java -jar selenium-server-standalone-2.24.1.jar -role node -hub http://localhost:4444 /grid/register -browser "browserName=firefox,maxInstances=2,maxSession=2"
I do the same command without -browser informations it launches my tests but not in parallel..., so strange.
I saw that to launch phpunit tests in parallel we have to create our own script to do it. So in this case do I need selenium grid or not?? I am very confused. Thanks for your help.
There is a parallel wrapper for phpunit command line https://github.com/siivonen/parallel-phpunit so you don't need to write it. You need to have Selenium Hub (with some nodes connected to it) running somewhere. Then you run your tests pointing to that location and the Hub will proxy the calls to free nodes.
We use parallel-phpunit and Selenium Grid with four nodes connected to a hub. Our CI runs 30 minutes of Selenium tests in 3 minutes.
There could be different issues. One is, while running pre recorded steps, you should add seleniumProtocol=Selenium in "browser" argument, because by default it will be the webdriver.
Related
I'm using nightwatch to run tests in parallel. I would like to be able to run multiple tests at a time in different selenium processes. How can I accomplish that?
What I did is create a selenium hub:
java -jar /opt/selenium-server-standalone-2.53.0.jar -Dwebdriver.chrome.driver=/usr/bin/chromedriver -Dwebdriver.chrome.bin=/usr/bin/google-chrome -log /home/jenkins-user/log/selenium.log -role hub &
And when each test runs, I create a node:
java -jar /opt/selenium-server-standalone-2.53.0.jar -Dwebdriver.chrome.driver=/usr/bin/chromedriver -Dwebdriver.chrome.bin=/usr/bin/google-chrome -log /home/jenkins-user/log/selenium.log -role node -browser browserName=chrome -hub http://localhost:4444/grid/register &
Unfortunately, this prevents me from running nightwatch tests in parallel.
What am I doing wrong?
Why do you want to start multiple selenium processes? You should not do that.
Check my answer for similar question: Running multiple nightwatch instances
How to run Selenium Test Cases parallely without using TestNG or JUnit.
Currently i am using the command
Client(Node) command :
java -jar selenium-server-standalone-2.35.0.jar -role node -hub
Protocol://host:4444/grid/register -browser browserName=firefox,platform=WINDOWS maxInstances=3.
But its not working.
I Need to execute one/many test cases parelley(at a time 5) in Firefox
Java -jar selenium-server-standalone-2.35.0.jar -role node -hub Protocol://host:4444/grid/register -browser browserName=firefox,platform=WINDOWS maxInstances=3.
But its not working.
It won't work. By running the above command you are setting up selenium grid to run 3 instances of test IF and When it gets 3 requests. You need to write the logic to pass three instances of tests pointing to the hub in parallel for the node to work its magic.
To run tests in parallel using java, you need to create logic using multithreading. You should take care to
make your classes thread safe
Specify which tests to run
Create a report of testing so that others can know what your test is doing
Or you can use JUnit or testNG which will do most of these for you.
You could do it using Maven Surefire, which has parallel running capability. You would only want to use TestNG if you need to parameterize. Surefire creates a pretty ok test report also.
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 fear this is a very trivial question. But I'm having some trouble getting selenium Grid2 to run multiple test against a single node, from my understanding this should be possible by setting maxSessions.
This is my setup:
-Hub runs completly standard
-Node runs firefox with 5instances and 5 sessions enabled.
I've created 6 dummy tests using MBUNIT and added [Paralizable] to make them run side by side.
This is what I've done to test:
1: Start 2 nodes and run all tests (they run in parallel one on each node)
2: Turn off nodeA and run all tests
In step 2 is where i get stuck, i expected the last node would run 2 tests at once since the maxSessions is set to 5 but this doesn't happen, it only runs 1.
I suspect I've used a wrong parameter when starting the hub or node somewhere but right now i can't figure it out. anybody who want to help a newbie at Grid2? :)
This is roughly my code, very basic just for playing around:
[TestFixture]
public class RemoteTest
{
[Test]
[Parallelizable]
public void StartClose()
{
DesiredCapabilities cap = DesiredCapabilities.Firefox();
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), cap);
driver.Navigate().GoToUrl("http://www.google.dk");
driver.Quit();
}
}
Commands used:
java -jar selenium-server-standalone-2.14.0.jar -role hub
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://192.168.0.26:4444/grid/register
no question is trivial :)
To start a server (use the following command)
java -jar selenium-server-standalone-2.14.0.jar -role hub
To start a Node (use the following command)
java -jar selenium-server-standalone-2.14.0.jar -role node -hub
http://localhost:4444/grid/register
Incase if u had tried to start a node with browsers as well (check the following command)
-browser browserName=firefox,version=3.6,maxInstances=5,platform=LINUX
maxInstances --> Signify the Max instances of same browser that can run on a Grid node
Selenium Grid: MaxSessions vs MaxInstances
If you specify capabilities in your test case that do not exist on your grid then there will be no match and the test will fail to run.
Please avoid running the tests from the Nodes and instead run tests from hub. I tried the same experiment where I ran the tests from the server (HUB) and I registered a node for running parallel test cases and everything worked perfect.
When using only Selenium server it was possible to run the tests in the single browser window with the setting
-java -jar selenium-server-standalone-2.2.0.jar -singleWindow
When switched to grid 2, -singleWindow parameter is not working anymore.
Help is really appreciated.
Made it happen by running the following line:
java -jar selenium-server-standalone-2.2.0.jar -role webdriver -singleWindow -hub http://192.168.1.149:4444/grid/register -port 5557
Seems like the order of the parameters is important.