Javascript 如何报告量角器超时的角度未决请求?
我最近一直在做一些量角器测试,有时我的一些测试会随机失败,出现以下错误:Javascript 如何报告量角器超时的角度未决请求?,javascript,angularjs,protractor,e2e-testing,Javascript,Angularjs,Protractor,E2e Testing,我最近一直在做一些量角器测试,有时我的一些测试会随机失败,出现以下错误: DEBUG - WebDriver session successfully started with capabilities { caps_: { platform: 'LINUX', acceptSslCerts: true, javascriptEnabled: true, browserName: 'chrome', chrome: { userDataDir: '
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 );
}
}
};
但是,结果总是空的
[]
。你们以前有过这个问题吗?如果有,你们是如何解决的?还有,我能做些什么来改进这个记者吗?看看另一个答案的想法1和2:不是1,前一段时间检查过,2很难调试,因为测试只在远程jenkins服务器上失败,不能在本地复制。这就是为什么我想用这个jasmine reporter来检查未决的请求我也有同样的问题。你是如何解决这个问题的?从来没有,我猜我的Django dev服务器在太多并发查询上死锁了,这是导致死锁的原因,但是我不确定。我将测试环境更改为使用gunicorn/nginx,这解决了我的问题