Niknolty
Niknolty

Reputation: 93

Selenium-PHPUnit, Selenium Grid

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", "[email protected]");
    $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", "[email protected]");
    $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.

Upvotes: 0

Views: 1940

Answers (2)

Stan
Stan

Reputation: 3461

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.

Upvotes: 0

user1132305
user1132305

Reputation: 165

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.

Upvotes: 0

Related Questions