Home > Quality Assurance > Selenium RC and PHP

Selenium RC and PHP

March 29th, 2009

As requested here is a how to for setting up the selenium Remote control with the PHP driver.  Selenium RC is an open source automation tool which can run test scripts recorded from Selenium IDE which is a firefox plugin for recording the automated tests.  With this setup you will be able to record test in the selenium IDE and export them in PHP or you can skip the recording step completely and write the test in PHP and then play back or run the tests in the browser of your choice.

1. Setup XAMPP on your system:

  • Download the latest version of xampp.
  • Install with default settings.
  • Add the following to the PATH environment variable: C:\xampp\php

2. Download Firefox. (Needed for the selenium IDE)

3. Download the Selenium IDE firefox plugin. You can drag and drop the download file on an open firefox window to install.

4. Download the Selenium RC and extract to: C:\selenium

5. Install PHP UNIT:

  • Open a command line interface and navigate to: C:\xampp\php
  • Type: pear channel-discover pear.phpunit.de
  • Type: pear channel-discover pear.symfony-project.com
  • Type: pear install phpunit/PHPUnit

6. Use the Selenium IDE to record some test scripts and export them in php format to: C:\xampp\htdocs\selenium

7. Start the selenium RC server:

  • Open the command line interface and navigate to: C:\selenium\selenium-remote-control-1.0-beta-2\selenium-server-1.0-beta-2\
  • Type:  java -jar selenium-server.jar

8. Run/playback the recorded test:

  • Open a new command line interface and navigate to: C:\xampp\htdocs\selenium\
  • Type: phpunit testname.php

Ensure that the class name in the php test script is the same as the filename.

Now you can record tests in selenium IDE, export them in a php format and run them using the selenium RC and phpunit.

Good Luck and happy testing.

JodyT Quality Assurance , , , ,

  1. phpdeveloper
    April 21st, 2009 at 06:39 | #1

    It is showing me error like
    //error
    PHPUnit 3.2.15 by Sebastian Bergmann.

    E

    Time: 24 seconds

    There was 1 error:

    1) testMyTestCase(test1)
    RuntimeException: Could not connect to the Selenium RC server.

    FAILURES!
    Tests: 1, Errors: 1.

  2. phpdeveloper
    April 21st, 2009 at 06:40 | #2

    I’m exporting the test case code from selenium ide as php format

  3. JodyT
    April 23rd, 2009 at 05:22 | #3

    Hi phpdeveloper, sounds like you don’t have the RC server running, did you follow step 7?

  4. phpdeveloper
    April 24th, 2009 at 23:18 | #4

    Ya.I’ve followed all steps.
    Server is also get started but any how after some time it shows the following error on server::

    C:\selenium\selenium-remote-control-1.0-beta-1\selenium-server-1.0-beta-1>java -
    jar selenium-server.jar
    11:43:13.888 INFO – Java: Sun Microsystems Inc. 11.3-b02
    11:43:13.888 INFO – OS: Windows XP 5.1 x86
    11:43:13.888 INFO – v1.0-beta-1 [2201], with Core v1.0-beta-1 [1994]
    11:43:14.106 INFO – Version Jetty/5.1.x
    11:43:14.106 INFO – Started HttpContext[/selenium-server/driver,/selenium-server
    /driver]
    11:43:14.122 INFO – Started HttpContext[/selenium-server,/selenium-server]
    11:43:14.122 INFO – Started HttpContext[/,/]
    11:43:14.153 INFO – Started SocketListener on 0.0.0.0:4444
    11:43:14.153 INFO – Started org.mortbay.jetty.Server@13e205f
    11:45:37.126 INFO – Checking Resource aliases
    11:45:37.126 INFO – Command request: getNewBrowserSession[*chrome, https://hs53.
    mychurchworks.com/] on session null
    11:45:37.126 INFO – creating new remote session
    11:45:37.391 INFO – Allocated session d345cf7b716248b7859678653031a2ff for https
    ://hs53.mychurchworks.com/, launching…
    11:45:37.532 INFO – Preparing Firefox profile…
    11:46:01.085 WARN – GET /selenium-server/driver/?cmd=getNewBrowserSession&1=%2Ac
    hrome&2=https%3A%2F%2Fhs53.mychurchworks.com%2F HTTP/1.0
    java.lang.RuntimeException: Firefox refused shutdown while preparing a profile
    at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.wai
    tForFullProfileToBeCreated(FirefoxChromeLauncher.java:290)
    at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.lau
    nch(FirefoxChromeLauncher.java:143)
    at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.lau
    nchRemoteSession(FirefoxChromeLauncher.java:329)
    at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSessi
    on(BrowserSessionFactory.java:312)
    at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession
    (BrowserSessionFactory.java:113)
    at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession
    (BrowserSessionFactory.java:78)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowse
    rSession(SeleniumDriverResourceHandler.java:653)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(Se
    leniumDriverResourceHandler.java:410)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleComman
    dRequest(SeleniumDriverResourceHandler.java:388)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(Selen
    iumDriverResourceHandler.java:135)
    at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
    at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
    at org.mortbay.http.HttpServer.service(HttpServer.java:909)
    at org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
    at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:982)
    at org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
    at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
    244)
    at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
    at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
    Caused by: org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher$Fil
    eLockRemainedException: Lock file still present! C:\DOCUME~1\raise11\LOCALS~1\Te
    mp\customProfileDird345cf7b716248b7859678653031a2ff\parent.lock
    at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.wai
    tForFileLockToGoAway(FirefoxChromeLauncher.java:247)
    at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.wai
    tForFullProfileToBeCreated(FirefoxChromeLauncher.java:288)
    … 18 more

  5. phpdeveloper
    April 24th, 2009 at 23:19 | #5

    Thanx for your reply Jody T…

  6. Ilude
    April 27th, 2009 at 07:25 | #6

    phpdeveloper,

    It looks like FireFox is failing to create the temp profile that Selenium creates. Take a look at the ‘WARN’ (do a search for 11:46:01.085) and look through the output. You’ll see ‘Firefox refused shutdown while preparing a profile’, and then do a search for ‘Caused by:’ which is showing what is causing the problem.

    My recommendation would be to go into C:\Documents and Settings\raise11\Local Settings\Temp and delete as much from there as possible, especially the folder listed (customProfileDird345cf7b716248b7859678653031a2ff).

    That should allow FireFox to operate normally, and should let your testcase run smoothly.

  7. phpdeveloper
    April 27th, 2009 at 23:26 | #7

    Hey I got the solution.
    It was due to export file generated code.

    Thanx for your valuable reply..

    Again thanx frnds….

  8. phpdeveloper
    April 28th, 2009 at 02:13 | #8

    I don’t know that worked for some time and now again it has started showing same error….

  9. arbitmind
    April 29th, 2009 at 12:39 | #9

    Hey..
    I followed the exact same steps but when I run the
    C:\xampp\htdocs\selenium\phpunit testname.php
    it gives me ‘phpunit’ is not recognized as an internal or external command, :-( ( distraught

  10. JodyT
    April 29th, 2009 at 14:26 | #10

    Hi arbitmind, either phpunit is not installed (step 5) or the php folder has not been added to your path environment variable (step 1). Keep in mind as well that when you modify the path environment variable in windows you will need to restart you command line interface.

    Anybody who is not sure how to modify the environment variable may find this useful: http://support.microsoft.com/kb/310519

  11. JodyT
    April 29th, 2009 at 14:36 | #11

    phpdeveloper,

    Sorry to hear your still having this issue. I would agree with Ilude that there is an issue with firefox creating the temp profile that is causing the error. One solution maybe to create an alternative firefox profile and specify that the selenium server use that particular profile rather than creating the temp profile.

    Directions to create a profile are here: http://support.mozilla.com/en-US/kb/Managing+Profiles

    After you create the profile you need to start the selenium server with the following command to use it:
    java -jar selenium-server.jar -firefoxProfileTemplate “PATH TO PROFILE”

    I hope this helps.

  12. Jrussell
    May 6th, 2009 at 16:31 | #12

    I have the same issue with Firefox.

    If I’m reading it right it creates a new session and establishes a lock. Then shortly after that it blows up because there is a lock present. That’s fine, but it gives the name of the lock causing the problem as the same one created in the current session.

    This just started happening one day and I can’t think of anything that might have set it off.

  13. June 30th, 2009 at 07:35 | #13

    Hello

    I have a problem with my script, maybe you can help me.

    I am working with Selenium RC and PHP. I created a function, but i received an error.

    The function is:

    function mess($title, $message)

    {

    echo “$title”.”\n”;
    $fp = fopen(“resultados.doc”,”a”);
    fwrite($fp, “\n”.”$title”);

    if ($this->isTextPresent(“$message”))
    {
    echo “$message”.”\n”;
    $fp = fopen(“resultados.doc”,”a”);
    fwrite($fp, “\n”.”$message”);
    }
    else
    {
    echo “No se registra el mensaje”.”\n”;
    $fp = fopen(“resultados.doc”,”a”);
    fwrite($fp, “\n”.”No se registra el mensaje”);
    $errores++;
    }

    }

    The message error is:

    Using $this when not in object context in [file] on line 35.

    Line 35 is: if ($this->isTextPresent(“$message”))

    I don t know how use this object.

    Thanks!!

    Germán.

  14. JodyT
    July 18th, 2009 at 20:57 | #14

    @Germán
    This is more an issue with object oriented programming with PHP and I’m probably not the right guy to ask but…. your function should work as long as it is in the same class as your test script.

  15. iceman
    September 5th, 2009 at 08:27 | #15

    Hi JodyT:

    i execute WebTest.php(test script sample from http://www.phpunit.de ) to make sure selenium-server is working yet, i got information “RunteimExpection: Could not connect to the Selenium RC server”. Please help me to slove this problem!!!

    i go detail about my steps:

    1. installed XAMPP package

    2.use command line mode(shell) from XAMPP control panel to install phpunit by “pear channel-discover pear.phpunit.de” and “pear install phpunit/PHPUnit”.

    3. install Test_Selenium by “pear install Testing_Selenium-beta”.

    4.download and unzip selenium RC to locate at C:\selenium-server

    5.use command line to startup selenium server by java -jar selenium-server.jar,the result is:

    C:\selenium-server\selenium-server>java -jar selenium-server.jar
    01:44:27.706 INFO – Java: Sun Microsystems Inc. 14.1-b02
    01:44:27.707 INFO – OS: Windows Vista 6.0 x86
    01:44:27.721 INFO – v1.0-SNAPSHOT [2569], with Core v1.0-SNAPSHOT [2313]
    01:44:27.819 INFO – Version Jetty/5.1.x
    01:44:27.821 INFO – Started HttpContext[/selenium-server/driver,/selenium-server
    /driver]
    01:44:27.824 INFO – Started HttpContext[/selenium-server,/selenium-server]
    01:44:27.825 INFO – Started HttpContext[/,/]
    01:44:27.870 INFO – Started SocketListener on 0.0.0.0:4444
    01:44:27.871 INFO – Started org.mortbay.jetty.server@14ed9ff

    6.create a file WebTest.php,

    setBrowser(‘*firefox’);
    $this->setBrowserUrl(‘http://www.example.com/’);
    }

    public function testTitle()
    {
    $this->open(‘http://www.example.com/’);
    $this->assertTitleEquals(‘Example Web Page’);
    }
    }
    ?>
    7.use command line to execute phpunit WebTest.php, the result is:

    PHPUnit 3.3.17 by Sebastian Bergmann.

    E

    Time: 0 seconds

    There was 1 error:

    1) testTitle(WebTest)
    RuntimeException: Could not connect to Selenium RC server

    FAILURES!
    Tests: 1, Assertions: 0, Errors: 1.

    Who can help to fix this problem????????

  16. November 3rd, 2009 at 23:54 | #16

    it works great!!! Thanks Jody…

  17. November 17th, 2009 at 06:47 | #17

    Anyobdy who had many mysterious problems trying to set this up with Selenium RC’s 1.0.1 beta 2, should give 1.0.1 release a try. For me these instructions never worked with 1.0.1b2 but with the 1.0.1 version things worked on the 1st try. Thanks Jody for this tutorial.

  18. Lena
    February 2nd, 2010 at 07:07 | #18

    Hey Jody :)

    I’m on step 7 – trying to start the Selenium RC server.

    When I execute java -jar selenium-server.jar
    my interface is stopping at the following point:

    C:\selenium\selenium-remote-control-1.0.1\selenium-server-1.0.1>java -
    jar selenium-server.jar
    11:43:13.888 INFO – Java: Sun Microsystems Inc. 11.3-b02
    11:43:13.888 INFO – OS: Windows Vista 6.0 amd64
    11:43:13.888 INFO – v1.0.1 [2696], with Core v@version@ [@revision@]
    11:43:14.106 INFO – Version Jetty/5.1.x
    11:43:14.106 INFO – Started HttpContext[/selenium-server/driver,/selenium-server
    /driver]
    11:43:14.122 INFO – Started HttpContext[/selenium-server,/selenium-server]
    11:43:14.122 INFO – Started HttpContext[/,/]
    11:43:14.153 INFO – Started SocketListener on 0.0.0.0:4444
    11:43:14.153 INFO – Started org.mortbay.jetty.Server@13e205f

    Any ideas why it wont finish?

    Thanks,

    ~Lena

  19. Shrikant
    February 11th, 2010 at 03:13 | #19

    first execute
    >pear upgrade-all
    then
    >pear install phpunit/PHPUnit
    >phpunit yourphpfilenamewithoutextention

  20. Shrikant
    February 11th, 2010 at 22:45 | #20

    how we can run selenium php scrip on Eclipse?

  21. Shrikant
    February 12th, 2010 at 01:56 | #21

    I have worked with phpunit by using cmd prompt

  22. ajay
    February 24th, 2010 at 01:13 | #22

    hi,
    i am new to use the selenium PHP , i want to install the seleinium on Linux fedora o/s, so will you please give me installation steps for this 1.
    also i want to know how to do data driven testing in the Selenium.
    if you know some site ,which will useful for me , please reply back to my mail ID.
    waiting for your reply.

  23. Satish
    March 11th, 2010 at 00:07 | #23

    Can you please elaborate the pre requisites, steps & procedure in instaling and using SeleniumRC with PHP.

  24. JodyT
    March 27th, 2010 at 19:53 | #24

    FYI.. I updated the how to just a bit as there is a little change in the phpunit installation.

    JodyT

  25. JodyT
    March 27th, 2010 at 20:02 | #25

    @Shrikant
    I have never used Eclipse with Selenium PHP scripts so I can’t really help you there. You may want to take a look at cubictest if you havn’t already, it uses eclipse and selenium. http://boss.bekk.no/cubictest/index.html

    Good Luck
    JodyT

  26. JodyT
    March 27th, 2010 at 20:13 | #26

    @Lena

    Hey Lena.. Wazzup

    It looks like the server is running fine, you need to open another cmd line interface to run your scripts with phpunit.

    Sorry I took so long to reply… been real busy.

    P.S The cakes look great. http://www.lenasdesignercakes.com

    JodyT

  27. Janu
    May 27th, 2010 at 03:47 | #27

    phpdeveloper :
    I’m exporting the test case code from selenium ide as php format

    @JodyT
    Hi Jody is there any way to generate test report using selenium with php. i am new for this selenium and php…. using ur info i install that i worked in cmd fine. but i want to know is there any way to generate test report..

  28. Rehan Ali
    June 26th, 2010 at 01:19 | #28

    @JodyT
    First of all I want to say thank you for all of your value able information regarding Selenium RC with PHP ok one think i want to ask about Selenium IDE i m facing problem to record the test cases for uploading.downloading files will you plz give me some value able knowledge regarding this issue.Even I manually edit the commands for handle the pop which opens when user going to download any file from any site by using Fire Fox.How handle this issue and how to record this test cases by using selenium IDE or there way how to automate this test cases?
    Thanks
    Rehan Ali

  29. Rehan Ali
    June 28th, 2010 at 04:15 | #29

    Hi jodyT
    I follow all the setps I ma using ubuntu 9.10…Linux
    When I run my test following message is showing
    PHPUnit 3.4.14 by Sebastian Bergmann.

    Cannot open file “./LoginAuthentication.php”.

  30. Rehan Ali
    June 28th, 2010 at 04:53 | #30

    PHP script in the file name LoginAuthentication.php is

    setBrowser(“*chrome”);
    $this->setBrowserUrl(“http://staging.vcred.com/#/authentication/login?json=1″);
    }

    public function testMyTestCase()
    {
    $this->open(“/#/authentication/login?json=1″);
    $this->type(“//input[@id='username' and @name='username' and @value='']“, “rehan23_bsku@hotmail.com”);
    $this->type(“//input[@id='password' and @name='password' and @value='']“, “test”);
    $this->click(“//input[@name='login' and @value='Login']“);
    }
    }
    ?>

  31. richard kim
    July 15th, 2010 at 13:27 | #31

    Hi Jody,

    I have the error below when installing PHPUNIT;

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\alex>cd ..

    C:\Documents and Settings>cd ..

    C:\>cd xam*

    C:\xampp>cd php

    C:\xampp\php>pear channel-discover pear.phpunit.de
    Channel “pear.phpunit.de” is already initialized

    C:\xampp\php>pear channel-discover pear.symfony-project.com
    Channel “pear.symfony-project.com” is already initialized

    C:\xampp\php>pear install phpunit/PHPUnit
    Did not download optional dependencies: pear/Image_GraphViz, pear/Log, symfony/Y
    AML, use –alldeps to download automatically
    phpunit/PHPUnit can optionally use package “pear/Image_GraphViz” (version >= 1.2
    .1)
    phpunit/PHPUnit can optionally use package “pear/Log”
    phpunit/PHPUnit can optionally use package “symfony/YAML” (version >= 1.0.2)
    phpunit/PHPUnit can optionally use PHP extension “xdebug” (version >= 2.0.5)
    downloading PHPUnit-3.4.14.tgz …
    Starting to download PHPUnit-3.4.14.tgz (254,983 bytes)
    ………….done: 94,654 bytes
    ERROR: unable to unpack C:\DOCUME~1\alex\LOCALS~1\Temp\pear\download\PHPUnit-3.4
    .14.tgz

    C:\xampp\php>

    Tried twice; but still the same.

    Any thoughts to clear this error?

    Thanks

  1. No trackbacks yet.