Use Selenium code to download Web page
I have installed Selenium IDE on Firefox and manage to record开发者_StackOverflow 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 doesn't seem to do anything (since it's 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.
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
Reconsider my approach
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
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)
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.
精彩评论