Our use of a real web browsers makes it really easy to do website load testing and monitoring. By default a page is considered to have timed out if the page “onload event” can’t fire within 30 seconds. However, sometimes the page appears to be fully loaded to a typical user and shouldn’t be counted as a timeout error in your tests.
We call these errors “soft timeouts”, and they require a little bit of code to ignore them:
var selenium = browserMob.openBrowser(); selenium.setTimeout(2500); function ignoreIfSafeTimeout(e, step, minObjects, acceptableThreshold) { if (e.message.indexOf("Timed out after ") == -1) { throw e; // this isn't a timeout, so throw it } var objects = step.getObjects(); var objectCount = objects.size(); if (objectCount < minObjects) { throw "Expected at least " + minObjects + " objects but only saw " + objectCount; } var errors = 0; for (var i = 0; i < objectCount; i++) { var object = objects.get(i); var code = object.getStatusCode(); if (code < 200 || code >= 400) { errors++; } } var errorRatio = errors / objectCount; if (errorRatio > acceptableThreshold) { throw "Expected no more than " + acceptableThreshold + " error ratio but saw " + errorRatio; } } browserMob.beginTransaction(); var step1 = browserMob.beginStep("Home Page"); try { selenium.open("http://marketwatch.com"); } catch (e) { ignoreIfSafeTimeout(e, step1, 130, 0.1); } browserMob.endStep(); browserMob.endTransaction();




Recent Comments