Monday, February 01, 2010

Selenium - wait_for_condition - timeout

$sel->wait_for_condition($script, $timeout)  is not working correctly if the timeout is more than 180 seconds (180000 milliseconds). The timeout is not passed to the LWP::UserAgent object. By default the user agent times out for 180 seconds. If you are waiting for any time consuming AJAX operations, user agent times out at 180 seconds even if you pass higher timeout value (say 300000 milliseconds = 300 seconds) to the wait_for_condition selenium API.
I was getting the following error:

Error requesting http://localhost:4444/selenium-server/driver/:
500 read timeout

 
I and my colleague Mahesh checked the Selenium perl library code. It is not passing the timeout to the user agent, which is the issue. Normally people does not wait more than 3 minutes (180 seconds), so this issue might not have come to visibility. Anyhow, I have made a temporary fix locally only for the WaitForCondition command and it is working for higher timeout values.

Code changes in Selenium.pm are
   $command = uri_escape($command);
    my $fullurl = "http://$self->{host}:$self->{port}/selenium-server/driver/";
    my $content = "cmd=$command";
    my $tmp_timeout = 180;
    if ($command eq 'waitForCondition') {
        $tmp_timeout = $args[1]/1000;
    }
and
 my $ua = LWP::UserAgent->new;
 my $header = HTTP::Headers->new( Content_Type => 'application/x-www-form-urlencoded; charset=utf-8' );
 if ($command eq 'waitForCondition') {
        $ua->timeout($tmp_timeout);
 }
I am not sure about other commands that require this fix, this fix just handle the timeout issue in $sel->wait_for_condition() API.