Selenium RC is ignoring my timeout
I have a simple Selenium test that runs against a remote Selenium Server instance.
I'm trying to test for page performance, and some pages can exceed the max execution time, and I'm trying to catch that.
No matter what I put in setTimeout(), it always waits for the full page to load or the server times out.
public static $browsers = array(
array(
'name' => 'Firefox on Ub开发者_如何学运维untu',
'browser' => '*firefox',
'host' => 'dev-ubuntudesktop',
'port' => 4444,
'timeout' => '1000',
),
)
public function testSlowPage() {
$this->setTimeout(1000);
$this->open('myslowaddress');
$this->assertTextNotPresent('Internal Server Error');
}
Even though I'm not using openAndWait
, the above example doesn't reach the assert line until after the page is loaded or the web server terminates the request.
What I'd really like is a test that confirms "Page loads in under 1 second", without waiting 30 seconds (or whatever the PHP timeout happens to be set to).
Open method implicitly invokes wait, whether you want it to or not. This wait defaults to 30sec. And setTimeOut is used when your page does not load with in 30 sec. Hence if your page does not load in 30 second then you could use setTimeOut else you tests would fail, so it would be -
selenium.Open(appURL); selenium.setTimeOt(timeOut);
Now coming to your test objective. You could do assertion to check how long page takes to load, I have checked with 1 sec here -
(It's in java but you should be able to find PHP equivalent)
int testStartTime = Calendar.getInstance().get(13);
selenium.open(appURL);
int testEndTime = Calendar.getInstance().get(13);
Assert.assertTrue((testEndTime-testStartTime)>1, "Fail");
Notice that I have not used setTimeOut method here, hence if page does not load with in 30sec then test would fail any way and you would know that page does not load with in 30 sec. In this situation if you yet want to check page load time then can use exception handling along with time calculation to find page load time.
精彩评论