Selenium RC and PHP
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.
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.
I’m exporting the test case code from selenium ide as php format
Hi phpdeveloper, sounds like you don’t have the RC server running, did you follow step 7?
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
Thanx for your reply Jody T…
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.
Hey I got the solution.
It was due to export file generated code.
Thanx for your valuable reply..
Again thanx frnds….
I don’t know that worked for some time and now again it has started showing same error….
Hey..
( distraught
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,
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
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.
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.
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.
@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.
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????????
it works great!!! Thanks Jody…
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.
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
first execute
>pear upgrade-all
then
>pear install phpunit/PHPUnit
>phpunit yourphpfilenamewithoutextention
how we can run selenium php scrip on Eclipse?
I have worked with phpunit by using cmd prompt
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.
Can you please elaborate the pre requisites, steps & procedure in instaling and using SeleniumRC with PHP.
FYI.. I updated the how to just a bit as there is a little change in the phpunit installation.
JodyT
@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
@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
@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..
@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
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”.
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']“);
}
}
?>
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