4
votes

I tried to make some tests for PHP Unit & Selenium server. I have an ubelieveable issue and i don't know why.

I am using the latest Selenium stand server 2.42.2. When i run the server, it shows this:

root@test:/home/jakub# java -jar /usr/local/bin/selenium-server-standalone-2.42.2.jar
Jun 30, 2014 4:32:53 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
16:32:53.398 INFO - Java: Oracle Corporation 24.51-b03
16:32:53.399 INFO - OS: Linux 3.12-1-amd64 amd64
16:32:53.413 INFO - v2.42.2, with Core v2.42.2. Built from revision 6a6995d
16:32:53.508 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver 
registration is skipped: registration capabilities Capabilities [{platform=WINDOWS,  
ensureCleanSession=true, browserName=internet explorer, version=}] does not match
with    
current platform: LINUX
16:32:53.563 INFO - RemoteWebDriver instances should connect to: 
http://test.jacon.cz:4444/wd/hub
16:32:53.564 INFO - Version Jetty/5.1.x
16:32:53.565 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
16:32:53.566 INFO - Started HttpContext[/selenium-server,/selenium-server]
16:32:53.566 INFO - Started HttpContext[/,/]
16:34:07.013 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@7cbae009
16:34:07.014 INFO - Started HttpContext[/wd,/wd]
16:34:07.022 INFO - Started SocketListener on 0.0.0.0:4444
16:34:07.023 INFO - Started org.openqa.jetty.jetty.Server@17056563

It seems that Selenium server is running correctly. But when I try to run simple test in php, using PHPUnit, it says it can't connect to Selenium server.

root@test:/home/jakub# /usr/local/bin/phpunit --verbose sel.php
PHPUnit 4.1.3 by Sebastian Bergmann.

SS

Time: 73 ms, Memory: 3.25Mb

There were 2 skipped tests:

1) loginTest::testLoginTrue
The Selenium Server is not active on host http://test.jacon.cz at port 4444.

2) loginTest::testLoginFalse
The Selenium Server is not active on host http://test.jacon.cz at port 4444.

OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 0, Skipped: 2.

I checked via netstat -apn | grep 4444 if the Selenium server is listening on port 4444 and it is listening. Does someone know how to fix this problem? I googled, but without any results.

And btw. here is the code of the test in php:

<?php
class loginTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected $captureScreenshotsOnFailure = TRUE;
protected $screenshotsPath = '';
    protected $screenshotsUrl = '';

protected function SetUp()
  {
  $this->setBrowser('chrome');
  $this->setBrowserUrl('http://test.jacon.cz/');
  //$this->setPort(4444);
  //$this->setTimeout(2);
  $this->setHost("http://test.jacon.cz");
}

public function testLoginTrue()
  {
      $this->url('/sms');
  $this->byName('username')->value('Kristyna');
  $this->byName('password')->value('*****');
  $this->byCssSelector('form')->submit();
      $url = $this->url();
  $this->assertEquals('Statistics', $this->title(), 'Přihlášení neproběhlo');
  $this->assertStringEndsWith('sms/', $this->url(), 'Přihlášení neproběhlo');
  }

     public function testLoginFalse()
  {
  $this->url('/sms');
  $this->byName('username')->value('abcdefgh');
  $this->byName('password')->value('123456');
  $this->byCssSelector('form')->submit();
      $url = $this->title();
  $this->assertEquals('Login to SM', $this->title(), 'Přihlášení proběhlo');
  }
}
?>

Hope you could help. Thanks.

3
I haven't had the same problem, but I have had better luck extending PHPUnit_Extensions_SeleniumTestCase instead of PHPUnit_Extensions_Selenium2TestCase. - Kryten
Thanks for tip, but without any achievement. - Netheme
Are you trying to run Selenium Grid? - SiKing
No i am running standard selenium standalone server without any parameteres in run command. - Netheme

3 Answers

2
votes

There was problem in wrong installation of PHPUnit. Everything is working fine now, thanks a lot for all tips & answers.

1
votes

Not positive about php...but.

Selenium Standalone is the "GRID" server. You have to register the same server as a hub and node for it to pick up and execute on a browser. I would also recommend you create a config file that you pass in...currently it says windows and the platform is really linux.

So you start the standalone to allow GRID to function.

    java -jar /usr/local/bin/selenium-server-standalone-2.42.2.jar -role hub

And then register a hub as the same machine it is running on...with a config file to indicate what should be available.

    java -jar /usr/local/bin/selenium-server-standalone-2.42.2.jar -role node -hub http://localhost:4444/grid/register

You should be able to open the console at http://test.jacon.cz:4444/grid/console once it is started. In general you want parameters in a config file because that's how you specify the browsers to register and the number of concurrent runs.

GRID Reference: https://code.google.com/p/selenium/wiki/Grid2

0
votes

I have been doing something very similar, but in Python. But I did not have to run the Selenium server. All I had to do was just do download selenium module and I was good to go. It might be the same in PHP perhaps? I don't really know what the server would be for, all you need is the driver that simulates the browser, or is Python running the server somewhere itself?