views:

297

answers:

2

Hi, I have installed Selenium IDE on Firefox and manage to record and play various web navigation sequences. What I need is to do it all automated through PHP, i.e. run a PHP script which gets the html source of the final page (i.e. at end of navigation sequence). Within Selenium there is an option to export to PHP, so I get something like

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

function testMyTestCase() { $this->open("/"); $this->click("link=24"); $this->waitForPageToLoad("30000"); $this->click("link=Test2"); $this->waitForPageToLoad("30000"); $this->click("//td[4]/a/img"); $this->waitForPageToLoad("30000"); $this->type("username", "user"); $this->type("password", "pass"); $this->click("//input[@name='login']"); $this->waitForPageToLoad("30000"); } }

Although I can use this in my PHP code, it doesnt seem to do anything (since its just a class definition I guess). How do I get that last source page? Note that I do not want my PHP code to do the navigation on screen, instead I would then like to process that final source code further within PHP.

Thanks for any clues

A: 

The Export to PHP Option will export your test in a form that will (with a little extra work) run using the Selenium RC PHP driver. It does not export the page you're looking at.

Out of the box Selenium IDE will not allow you to take the final source of your page and do anything with it. If I had to accomplish something like this I'd

  1. Reconsider my approach

  2. If I decided I wanted to do this with Selenium IDE, I'd look into using the user-extension.js mechanism to write a new Selenium action that would use Javascript to fetch the source of a page, and then POST it to a URL of my choosing

  3. Make the URL above the PHP page that does the rest of the processing.

This is kind of hacky, would require some research into user-extension.js (not for everyone), and is extra custom work that's bound to be fragile. (See option #1)

Alan Storm
Would you be able to elaborate on option #1 a little bit? Doesnt need to be through selenium. After I naviagate through a site (mainly .aspx) I get to the page I want and can "view source" through the browswer. This is what I would like to get to "automatically", e.g. through PHP code.
Rob
A: 

A couple of things that make this easier.

1)When it comes time to doing it via php it needs to connect to a server.

2)So go and download the server (selenium-rc). Run it via: java -jar selenium-server.jar Check the parameters via java -jar selenium-server.jar -? (I think!). The important one at this point will be the log file location.

3)Server will start on localhost and port 4444 (the defaults the code generated above expects).

4)Try to connect with that php code above. Check your selenium-server log. It should have details of the attempted connection.

Koobz
More info here: http://www.phpunit.de/manual/3.1/en/selenium.html. I'm not sure if it's possible to dynamically dump the html (I'm guessing you want to see what the markup looks like after javascript modifications?). Really, I'm mostly working with assert* and screenshots to get an idea of how the tests are going.
Koobz
Thanks. Have installed selenium server and managed to start it in cmd window. Bit confused by "try to connect with that php code above", i.e. how do I submit it?
Rob
use phpunit. If you've installed it with pear on a unix system, you should have the phpunit command in your path.Navigate to your test directory and type:phpunit TestName.php
Koobz
Using Vista and running php by uploading scripts to my domain host (hence havent event got much control over php.ini).
Rob