mirror of https://github.com/vitalif/phantomjs
Unit tests: reduce the flakiness of loading progress tests.
For whatever reason, swapping the order with the render() tests solve the intermittent random failures. Also, split the tests between loading start and finish checks (to better recognize which one is failing, if there is a failure), also make the tests more asynchoronous. https://github.com/ariya/phantomjs/issues/110911.9
parent
192a1e15f9
commit
d181c00378
|
@ -1905,6 +1905,69 @@ describe('WebPage navigation events', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("WebPage loading/loadingProgress properties", function() {
|
||||||
|
var p = require("webpage").create();
|
||||||
|
|
||||||
|
it("should not be loading when page has just been created", function() {
|
||||||
|
expect(p.loading).toBeFalsy();
|
||||||
|
expect(p.loadingProgress).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be loading when 'page.open' is invoked", function() {
|
||||||
|
var s = require("webserver").create();
|
||||||
|
|
||||||
|
s.listen(12345, function(request, response) {
|
||||||
|
setTimeout(function() {
|
||||||
|
response.statusCode = 200;
|
||||||
|
response.write('<html><body>Loaded!</body></html>');
|
||||||
|
response.close();
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
runs(function() {
|
||||||
|
p.open("http://localhost:12345");
|
||||||
|
expect(p.loading).toBeTruthy();
|
||||||
|
expect(p.loadingProgress).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
waits(500);
|
||||||
|
|
||||||
|
runs(function() {
|
||||||
|
s.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be completed when page is fully loaded", function() {
|
||||||
|
var s = require("webserver").create();
|
||||||
|
|
||||||
|
s.listen(12345, function(request, response) {
|
||||||
|
setTimeout(function() {
|
||||||
|
response.statusCode = 200;
|
||||||
|
response.write('<html><body>Loaded!</body></html>');
|
||||||
|
response.close();
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
|
||||||
|
var loaded = false;
|
||||||
|
|
||||||
|
runs(function() {
|
||||||
|
p.open("http://localhost:12345", function () {
|
||||||
|
loaded = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
waitsFor(function () {
|
||||||
|
return loaded;
|
||||||
|
}, 'Can not test loading progress' , 3000);
|
||||||
|
|
||||||
|
runs(function() {
|
||||||
|
expect(p.loading).toBeFalsy();
|
||||||
|
expect(p.loadingProgress).toEqual(100);
|
||||||
|
s.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("WebPage render image", function(){
|
describe("WebPage render image", function(){
|
||||||
var TEST_FILE_DIR = "webpage-spec-renders/";
|
var TEST_FILE_DIR = "webpage-spec-renders/";
|
||||||
|
|
||||||
|
@ -2008,37 +2071,3 @@ describe("WebPage render image", function(){
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("WebPage loading/loadingProgress properties", function() {
|
|
||||||
var p = require("webpage").create();
|
|
||||||
|
|
||||||
it("should not be loading when page has just been created", function() {
|
|
||||||
expect(p.loading).toBeFalsy();
|
|
||||||
expect(p.loadingProgress).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should be loading when 'page.open' is invoked", function() {
|
|
||||||
var s = require("webserver").create();
|
|
||||||
|
|
||||||
s.listen(12345, function(request, response) {
|
|
||||||
setTimeout(function() {
|
|
||||||
response.statusCode = 200;
|
|
||||||
response.write('<html><body>Loaded!</body></html>');
|
|
||||||
response.close();
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
|
|
||||||
p.onLoadFinished = function(status) {
|
|
||||||
expect(p.loading).toBeFalsy();
|
|
||||||
expect(p.loadingProgress).toEqual(0);
|
|
||||||
};
|
|
||||||
p.open("http://localhost:12345");
|
|
||||||
expect(p.loading).toBeTruthy();
|
|
||||||
expect(p.loadingProgress).toBeGreaterThan(0);
|
|
||||||
|
|
||||||
waits(500);
|
|
||||||
|
|
||||||
runs(function() {
|
|
||||||
s.close();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue