Brian
Brian

Reputation: 2221

Selenium RC WaitForPageToLoad Hangs

I am trying to get Selenium RC up and running for doing some automated testing on my website. I am finding that I constantly want to verify that I haven't broken any features, and manual testing is starting to become tiresome.

However, I can't seem to get Selenium RC to work with WaitForPageToLoad.

I tried copying the basic example that they give in the selenium documentation, but the test always gets stuck at: $this->waitForPageToLoad("30000"); I can see that it gets that far in the window that it brings up and that the page appears to have loaded correctly (we are at a google search result page). But the test fails with a timeout.

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

/**
 * Description of Test
 *
 * @author brian
 */
class Test extends PHPUnit_Extensions_SeleniumTestCase {

    function setUp() {
        $this->setBrowser("*safari");
        $this->setBrowserUrl("http://www.google.com/");
    }

    function testMyTestCase() {
        $this->open("/");
    $this->type("q", "selenium rc");
    $this->click("btnG");
    $this->waitForPageToLoad("30000");
    $this->assertTrue($this->isTextPresent("Results * for selenium rc"));
    }
}

What is even more interesting is that if I refresh the page when it is waiting, everything continues on as expected. So it would appear as though the waitForPageToLoad isn't realizing that the page has already loaded.

Upvotes: 1

Views: 3089

Answers (4)

Mezz
Mezz

Reputation: 130

An alernative to "WaitForPageToLoad()" Is to wait for an element to be present.


    $SECONDS = 360;

for ($second = 0; ; $second++) {
    if ($second >= $SECONDS) $this->fail("TIMEOUT");
    try {
        if ($this->isElementPresent("edit-submit")) break;
    } catch (Exception $e) {}

    sleep(1);
}

This code will loop for 360 seconds, checking if the value (edit-submit) is present each second. ("sleep(1)"). It essentially will achieve the same result as WaitForPageToLoad, but you can specify an absolute target.

Upvotes: 0

Karthi
Karthi

Reputation: 479

I have observed same problem many times. Hence I did not use this command when user is not navigating away from current page. It hangs at times and using IsElementPresent in while loop and exit after it return true.

Upvotes: 0

Jonathan
Jonathan

Reputation: 2213

There is also another possible cause of this situation that I ran into just now. According to the documentation, if you call ANY SELENIUM COMMANDS in between loading a page and calling waitForPageToLoad, then it is possible that waitForPageToLoad will hang. (If I understand it correctly, it is technically a race condition between the test script and selenium server, so it happens sometimes, not necessarily all the time).

In most cases, the page load is caused by a click event. When you have a test script like:

$this->click("/some/path");
//  <<- NO SELENIUM COMMANDS HERE
$this->waitForPageToLoad("30000");

Make extra sure that no selenium commands ever accidentally get inserted into the marked area.

While this is not technically the same problem that the OP posted about, it has the same error message, and I couldn't find this information without digging around quite a bit. Hopefully this is easier to find for other people in the future.

Upvotes: 1

Ross Patterson
Ross Patterson

Reputation: 9570

The example in the Selenium RC documentation is obsolete. Google changed the way their home page worked quite a while ago, and it is no longer a simple HTML page. Pressing the search button is now an AJAX-type operation that sends the search request and gets back a JSON response that is processed by the JavaScript code in the page. So the page never is re-loaded, and WaitForPageToLoad() eventually times out.

Upvotes: 5

Related Questions