Open joemcmahon opened 3 years ago
Here's a demo.
# ------------------------------------------------------------
# A Selenium Perl client script to demonstrate its start-up
# hanging.
# ------------------------------------------------------------
use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;
my $selenium_dir = 'D:/Meir/Dropbox/Data_base/Scripts/Selenium';
my $firefox_profile_dir = 'D:/Meir/Dropbox/Data_base/Scripts/Selenium';
my $selenium_jar_file = 'selenium-server-standalone-2.28.0.jar';
my $sel;
my $selenium_call_string =
"start cmd /k java -jar $selenium_dir/$selenium_jar_file ".
"-firefoxProfileTemplate \"$firefox_profile_dir\"";
system ($selenium_call_string) == 0 or die "system call failed: $?\n";
print "Just fired up the Selenium server\n";
$sel = Test::WWW::Selenium->new(
host => "localhost",
port => 4444,
browser => "*firefox",
browser_url => "http://www.tase.co.il/"
);
#eval {
# local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
# alarm 15;
# alarm 0;
#};
#if ($@) {
# die unless $@ eq "alarm\n"; # propagate unexpected errors
#}
#sleep 10;
print "... and now its client\n";
my $url = "http://www.tase.co.il/Eng/general/company/Pages/companyHistoryData.aspx?companyID=000629&subDataType=0&shareID=00629014";
$sel->open_ok($url);
$sel->click_ok("id=history1");
$sel->click_ok("xpath=(//input[\@value='Display Data'])[2]");
$sel->wait_for_page_to_load_ok("60000");
$sel->click_ok("css=td.GreenTextBtn");
$sel->click_ok("link=TSV");
$sel->wait_for_pop_up_ok("_blank", "60000");
END
{
$sel->shut_down_selenium_server();
}
I have an application which is invoked by a scheduler, i.e., unattended. Attached is a demo version of it, which very reliably reproduces the problem, under the right conditions, detailed below.
It uses:
After a long time (a day or two) of no use, but definitely, with 100% repeatability, after a boot up, it ALWAYS hangs and times out with a 500 status code.
I traced the point at which it is hung to the very first HTTP request to the Selenium server with the cmd = 'getNewBrowserSession', line 117, of the 'do_command sub. It results from the call to the 'new' method of 'WWW::Selenium' package, via the methods-chain 'start' -> 'get_string' -> 'do_command'. When in the hanging conditions I listed above (i.e., after boot-up, or after long inactivity), the HTTP request remains un-answered. It then times out after the 3 minutes of LWP's User_Agent + the extra wait you added in the 'ua' sub.
Also with 100% repeatability, once I abort both the Selenium server and the Perl client and restart the application, it NEVER hangs(!)
What seems as a work-around the problem is to place a 2 seconds 'sleep' between the system() call that fires up the Selenium server and the "$sel = Test::WWW::Selenium->new()" call.
My guess (educated I hope...) is that the
system ($selenium_call_string)
returns a bit too soon, before it is really ready to accept commands. That's why It hangs after a boot up. It works the second time around probably because Selenium is still memory resident. And again, it hangs after a long time of Selenium inactivity because it was purged from memory.Can you verify that?