Fnordian Knot
Fnordian Knot

Reputation: 45

Selenium RC and PHP for beginners

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.

Upvotes: 3

Views: 4266

Answers (7)

Mat Weir
Mat Weir

Reputation: 1

I use phpQuery for this kind of thing, it's a jQuery port.

Upvotes: 0

tomzi
tomzi

Reputation: 1235

I started last week doing test with Selenium IDE and now i'm going to Selenium RC. Actually you need the selenium-server-standalone and you need to install phpunit with pear. Check on Google there are good tutorials.

When phpunit is ready, you need to install a plugin to Selenium IDE which his named Selenium IDE PHP Formaters and then you can go on Selenium IDE->file->export file in php (phpunit).

When it's okay you can launch your test from your cmd consol by doing :

phpunit c:\path\to\myfile.php

and it'll tell you if the test is ok or not.

Upvotes: 0

markdrake
markdrake

Reputation: 624

Selenium RC Server is deprecated and out of date. The selenium webdriver is the one that you need but as you mention it requires to have a server listening and could be resources consuming. At Nearsoft, we created a library to interact with the web server via the JSON Wire protocol but we aimed to make it as similar as possible with the examples from selenium website so any example in Java would have a very similar syntax in PHP. Here's the link, hope it helps: https://github.com/Nearsoft/PHP-SeleniumClient

If you like it, share it, get involved, fork it or do as you please :)

Regards, Mark.

Upvotes: 0

j walker ib
j walker ib

Reputation: 127

Try simpletest webtester:

Its a very simple library which fits your requirements of "similar solution where you can just load a php library to interact with dom/html"

Upvotes: 0

tszming
tszming

Reputation: 2084

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-)

Upvotes: 3

bobdiaes
bobdiaes

Reputation: 1110

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

Upvotes: 0

Colin Fine
Colin Fine

Reputation: 3364

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.

Upvotes: 1

Related Questions