views:

105

answers:

3

I am running a ubuntu server with apache/php/mysql. I want to use selenium on one of my php projects. Basically, I want a setup where I can more or less copy paste code from the Firefox Selenium IDE (format set to php) into my php project, like this:

<?php

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*chrome");
    $this->setBrowserUrl("http://www.google.com/");
  }

  public function testMyTestCase()
  {
    $this->type("q", "stack overflow");
    $this->click("link=2");
    $this->waitForPageToLoad("30000");
    $this->click("btnG");
    $this->waitForPageToLoad("30000");
    $this->type("q", "stack overflow php");
    $this->click("btnG");
    $this->waitForPageToLoad("30000");
  }
}
?>

I have tried to figure out how to do this in PHP using Selenium RC, but the documentation is confusing and outdated.

I would be very grateful for instructions for beginners on how to get started with PHP and Selenium RC.

Thank you very much.

EDIT:

Thanks for the feedback. I have got Selenium up and running on Ubuntu/firefox and it is obvious that this is not what I am looking for. The fact that it runs a java server and is dependent on a full blown browser makes it anything than lightweight.

If anyone knows a similar solution where you can just load a php library to interact with dom/html, please tell me.

+1  A: 

I haven't done much with Selenium, but my understanding is that if you only have Selenium IDE, there is no way to do more than run it in your browser - the different language outputs are essentially irrelevant.

If you want to incorporate Selenium into your program, in any language, you need Selenium RC.

Colin Fine
Yeah, Selenium RC is needed and it's a bit of a PITA to set it up. Otherwise, you could invoke the test from the commandline using PHP but you'll need to use tests in Selenese script.
bobdiaes
A: 

You could use SauceLabs onDemand for Selenium testing using PHP. And you won't have to setup Selenium RC yourself. They have a 30-day free trial if you want to check it out.

http://saucelabs.com/ondemand

bobdiaes
A: 

Starting up Selenium RC is quite straight forward (if you already have a desktop environment), make sure you have JRE installed and run the command

java -jar selenium-server.jar

Selenium RC will listen at localhost(port 4444), and you can connect it using the PHP client (Pear), for example.

By the way, the Testing_Selenium(Pear) client is outdated, e.g. does not support HTTP POST, you might be interested in patching it (http://github.com/tszming/Testing_Selenium--Patch-)

tszming