pjb*_*pjb 8 javascript angularjs protractor
我有一个自举的Angular(1.2.6)应用程序.这意味着它没有明确的ng-app.因此,我遇到了使Protractor框架测试工作的各种问题(使用SauceLabs和grunt-protractor-runner).
错误因我尝试的内容而异,但一般情况下:
Error: Angular could not be found on the page http://xxx:9000/ :
angular never provided resumeBootstrap
Run Code Online (Sandbox Code Playgroud)
要么...
Error: Error while waiting for Protractor to sync with the page: {}
Run Code Online (Sandbox Code Playgroud)
我找到了一些我尝试过的解决方案.包括在这个丰富的线程中找到的那些,以及这里.但是,我没有做任何事情.
我试图angular.resumeBootstrap在bootstrapping中使用(注意我尝试了多种变体无效,包括尝试以编程方式在文档主体上设置ng-app):
angular.element( document ).ready( function() {
window.name = 'NG_DEFER_BOOTSTRAP!'
angular.bootstrap( document, [ 'app' ] );
setTimeout( angular.resumeBootstrap, 0 );
});
Run Code Online (Sandbox Code Playgroud)
正如其他人发现的那样,这个错误很奇怪:
UnknownError: unknown error: [ng:btstrpd] App Already Bootstrapped with this Element
'<body ng-app="" ng-controller="ApplicationController" class=" ng-scope pace-done">'
Run Code Online (Sandbox Code Playgroud)
奇怪/令人讨厌的是,至少在Sauce Labs会议上看来,这个测试似乎正在运行......它只是奇怪地认为它已被引导两次.
我一直在使用的各种组合也试过waitForAngular,wait和其他测试本身.这是我尝试过的一种变体:
it( 'should load the home page', function() {
ptor = protractor.getInstance();
ptor.waitForAngular();
ptor.driver.get( 'http://xxx:9000/' );
ptor.driver.wait( function() {
return ptor.getCurrentUrl().then( function() {
return ptor.isElementPresent( by.id( 'signIn' ) ).then( function() {
console.log('we are here!');
return true;
});
});
})
.then( function() {
expect( ptor.isElementPresent( by.id( 'signIn' ) ) ).toBe( true );
});
});
Run Code Online (Sandbox Code Playgroud)
这会导致如下错误:
1) e2e: home should load the home page
Message: timeout: timed out after 20000 msec waiting for spec to complete
Stacktrace: undefined
Run Code Online (Sandbox Code Playgroud)
我也试过在配置文件中增加各种超时无济于事.
任何帮助将非常感激!
小智 3
您应该将测试分为两个“it”步骤。像这样:
it( 'should load angular', function() {
ptor = protractor.getInstance();
ptor.waitForAngular();
})
it( 'should load the home page', function() {
ptor.driver.get( 'http://xxx:9000/' );
ptor.driver.wait( function() {
return ptor.getCurrentUrl().then( function() {
return ptor.isElementPresent( by.id( 'signIn' ) ).then( function() {
console.log('we are here!');
return true;
});
});
})
.then( function() {
expect( ptor.isElementPresent( by.id( 'signIn' ) ) ).toBe( true );
});
});
Run Code Online (Sandbox Code Playgroud)
量角器的问题是每个命令都无需等待上一步完成即可运行。所以,ptor.waitForAngular()和ptor.driver.get( 'http://xxx:9000/' )几乎同时运行。如果将它们分成两个步骤,量角器会在第一个“it”步骤完成后继续移动。