我最近一直在进行一些量角器测试,有时我的一些测试会随机失败,并出现以下错误:
DEBUG - WebDriver session successfully started with capabilities { caps_:
{ platform: 'LINUX',
acceptSslCerts: true,
javascriptEnabled: true,
browserName: 'chrome',
chrome: { userDataDir: '/tmp/.com.google.Chrome.czw4dR' },
rotatable: false,
locationContextEnabled: true,
mobileEmulationEnabled: false,
'webdriver.remote.sessionid': '3afc09d9-d06d-4c99-a788-d1118093c08d',
version: '40.0.2214.111',
takesHeapSnapshot: true,
cssSelectorsEnabled: true,
databaseEnabled: false,
handlesAlerts: true,
browserConnectionEnabled: false,
nativeEvents: true,
webStorageEnabled: true,
applicationCacheEnabled: false,
takesScreenshot: true } }
Started
token: a62e88d34991f4eef0894102e004e92032857700
.F...........................
Failures:
1) login form filled should fail on wrong credentials
Message:
Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md
$http
查看量角器文档时,通常会在有待处理的请求或我正在使用 $timeout 进行某些操作时发生此错误。我尝试为我的测试设置更长的超时时间(分钟),但没有帮助。我最近的想法是报告哪些请求正在等待,所以我做了以下 Jasmine Reporter:
var AngulaRequestsReporter = function(dir){
dir = (dir || '/tmp/protractors/');
this.requests = function(testDescription) {
var fname = testDescription.replace(/\s/g, '_') + '.pending_requests';
mkdirp(dir);
browser.executeScript(function(){
try{
var $http = angular.injector(["ng"]).get("$http");
return $http.pendingRequests;
}catch(e){
return [];
}
}).then(function(pendingRequests){
var stream = fs.createWriteStream(path.join(dir, fname));
stream.write(util.inspect(pendingRequests, {showHidden: false, depth: null}));
stream.end();
});
};
return this;
};
// takes screenshot on each failed spec (including timeout)
AngulaRequestsReporter.prototype = {
specDone: function(result) {
if (result.status !== 'passed') {
this.requests(result.description );
}
}
};
然而结果总是一个空的[]
。你们之前有没有遇到过这个问题,如果有,你们是怎么解决的?另外,我能做些什么来改善这位记者吗?