Selenium Problem

Hi, I’ve tried reading the Selenium RC doc and they’re still waiting for an example of using Selenium RC with PHP.

So here I am. I’m reading Agile Web Application Development with Yii 1.1 and PHP5 and I’m on the Selenium part page 46.

The problem I have is that I have a Virtual Private Server and I’m working on my laptop.

This is what I’ve done step by step on the VPS:


java -jar selenium-server.jar -port 4650

  1. Edit

protected/tests/WebTestCase.php

and added:


define('TEST_BASE_URL','http://test1.mypersonaldomain.com/demo/index-test.php/');

  1. protected/test/phpunit.xml

    deleted:


<browser name="internet Exploere" browser="*iexplore" />

  1. Added

date_default_timezone_set('America/Los_Angeles');

to


index-tests.php

because of php5.3

  1. Follow the book:

   $cd protected/tests/

   $phpunit functional/SiteTest.php

And this is the output I got after running


phpunit functional/SiteTest.php

:


PHPUnit 3.4.15 by Sebastian Bergmann.


EEE


Time: 0 seconds, Memory: 7.00Mb


There were 3 errors:


1) SiteTest::testIndex

PHPUnit_Framework_Exception: Could not connect to the Selenium RC server.


/var/www/yii/yii-1.1.3.r2247/framework/test/CWebTestCase.php:61


2) SiteTest::testContact

PHPUnit_Framework_Exception: Could not connect to the Selenium RC server.


/var/www/yii/yii-1.1.3.r2247/framework/test/CWebTestCase.php:61


3) SiteTest::testLoginLogout

PHPUnit_Framework_Exception: Could not connect to the Selenium RC server.


/var/www/yii/yii-1.1.3.r2247/framework/test/CWebTestCase.php:61


FAILURES!

Tests: 3, Assertions: 0, Errors: 3.

The output for running selenium (


java -jar selenium-server.jar -port 4650

):


10:04:38.506 INFO - Java: Free Software Foundation, Inc. 4.3.2

10:04:38.507 INFO - OS: Linux 2.6.32.16-linode28 i386

10:04:38.512 INFO - v2.0 [a2], with Core v2.0 [a2]

10:04:38.649 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4650/wd/hub

10:04:38.650 INFO - Version Jetty/5.1.x

10:04:38.651 INFO - Started HttpContext[/,/]

10:04:38.653 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@59f00

10:04:38.654 INFO - Started HttpContext[/wd,/wd]

10:04:38.654 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]

10:04:38.654 INFO - Started HttpContext[/selenium-server,/selenium-server]

10:04:38.656 INFO - Started SocketListener on 0.0.0.0:4650

10:04:38.656 INFO - Started org.openqa.jetty.jetty.Server@a36f00

What I think may have gone wrong:

  1. I didn’t define the custom port in the test case, which lead to the question how do I do that? (Selerium RC doesn’t have a php example).

  2. The port maybe in used. I’ve already did a netstat -a and I don’t think it’s in use.

  3. Base on starting the Selerium RC and it’s output, the program thinks that I will be running it using 127.0.0.1 url. Maybe I should change the test_base_url to 127.0.0.1?

Anyway, this post sorta helped me sort out my ideas of what the hell is going on. I’m going to go test 2-3. I have no idea how to do 1.

If anyone have any idea, please point me toward the right direction.

Thank you in advance for your time.

The test case where it failed


/var/www/yii/yii-1.1.3.r2247/framework/test/CWebTestCase.php:61

is:




        public function __call($name,$params)

        {

                if(is_array($this->fixtures) && isset($params[0]) && ($record=$this->getFixtureManager()->getRecord($name,$params[0]))!==false)

                        return $record;

                else

                        return parent::__call($name,$params);

        }



The Line 61 is:


return parent::__call($name,$params);


Progress:

I’ve added 4444 tcp port in my iptables now and I believe it can connect now. The problem now is:




PHPUnit 3.4.15 by Sebastian Bergmann.


EEE


Time: 1 second, Memory: 7.00Mb


There were 3 errors:


1) SiteTest::testIndex

PHPUnit_Framework_Exception: Response from Selenium RC server for getNewBrowserSession(*firefox, http://test2.anthonydoan.com:4650/demo/index-test.php).

Failed to start new browser session: java.lang.RuntimeException: Firefox 3 could not be found in the path!

Please add the directory containing ''firefox-bin' or 'firefox'' to your PATH environment

variable, or explicitly specify a path to Firefox 3 like this:

*firefox3/blah/blah/firefox-bin.




/var/www/yii/yii-1.1.3.r2247/framework/test/CWebTestCase.php:61


2) SiteTest::testContact

PHPUnit_Framework_Exception: Response from Selenium RC server for getNewBrowserSession(*firefox, http://test2.anthonydoan.com:4650/demo/index-test.php).

Failed to start new browser session: java.lang.RuntimeException: Firefox 3 could not be found in the path!

Please add the directory containing ''firefox-bin' or 'firefox'' to your PATH environment

variable, or explicitly specify a path to Firefox 3 like this:

*firefox3/blah/blah/firefox-bin.




/var/www/yii/yii-1.1.3.r2247/framework/test/CWebTestCase.php:61


3) SiteTest::testLoginLogout

PHPUnit_Framework_Exception: Response from Selenium RC server for getNewBrowserSession(*firefox, http://test2.anthonydoan.com:4650/demo/index-test.php).

Failed to start new browser session: java.lang.RuntimeException: Firefox 3 could not be found in the path!

Please add the directory containing ''firefox-bin' or 'firefox'' to your PATH environment

variable, or explicitly specify a path to Firefox 3 like this:

*firefox3/blah/blah/firefox-bin.




/var/www/yii/yii-1.1.3.r2247/framework/test/CWebTestCase.php:61


FAILURES!

Tests: 3, Assertions: 0, Errors: 3.



Now the question is this is a VPS server. I can’t run firefox on it. How do use firefox on my laptop instead.

What I think the solution is:

Selenium IDE?

Thank you again in advance.

Hi, excuse my english… im working on that too… if somebody can help here… it will be welcome! :D

  1. Select host and port in phpunit.xml



<browser name="Firefox" browser="*firefox" host="192.168.4.20" port="4444" timeout="30000" />



  1. I managed to get firefox working (can’t find the page that mentioned this fix)

At least in my system /bin/firefox is a shell script. Since Selenium first tries to find firefox-bin, by adding a symbolic link pointing to the binary executable, firefox can be started from Selenium. In my system the binary is located in /usr/lib/firefox.

/Tommy

Edit:

Selecting host is of course optional. I just did that for testing (Windows/IE) when I wasn’t able to start FF on the local system.

It has nothing to do with the port and others. Please don’t go further towards the wrong direction:)

I had the same error and found the reason and solution,

Reason:

[list=1]

[*]Assume you are using the latest version of Gii which creates AJAX based validation,

[*]Selenium invokes waitForElement() for AJAX based message and waitForPageToload() for standard page refresh,

[/list]

Solution:

  • change form validation to non-ajax based: ‘enableClientValidation’=>false in form views, or

  • somehow change phpunit to invoke waitForElement() instead of waitForPageToload() in Selenium RC

I think you shoud use phpunix 3.5+, I use phpunit 3.5.13, working good.

I had the same problem, what solved it for me was:

  1. Upgrading Pear to the latest version.

  2. Upgrading phpunit to the latest version (at least 3.5).

  3. Tri’s post (including the host, port and timeout params in phpunit.xml).

  4. Commenting out the Internet Exploder line in phpunit.xml (I use Firefox on Mac OS).

I should also mention that to get the tests to pass, I had to change occurrences of ‘$this->click(…)’ to ‘$this->clickAndWait(…)’:

Hi, i have the same problem, i think that selenium dosen’t find firefox on my client machine i try this:




        <browser name="Firefox" browser="*firefox" host="192.168.1.128/Application" port="4444" timeout="30000" />






        <browser name="Firefox" browser="*firefox" host="192.168.1.128" port="4444" timeout="30000" />



where 192.168.1.128 is ip of my local machine (Mac osx) and 192.168.1.129 is my server ubuntu, but i have always this error


sessionId led to start new browser session: Browser not supported: doesn't exist; perhaps this session was already stopped?



i have install the selenium and phpunit on my server, and launch java on my server by terminal


I tried installing PHPUnit on MAMP on my mac. The installation is successful. I started as a super user selenium, which seems to have started. PHPUnit when I try nothing happens.

i try to install Firefox on Ubuntu and when launch Phpunit have


Preparing Firefox profile...

and then same error

:wacko: :wacko:


i try set this in phpunit.xml


<selenium>

<browser name="Firefox" browser="*firefox /usr/lib/firefox"  />

</selenium>