我似乎无法让 Protractor 意识到 Angular 已加载并正在运行.当它打开 Chrome 时,我的应用程序在浏览器中完全加载,所以我知道 Angular 已正确加载并运行.
I can't seem to get Protractor to realize that Angular is loaded and running. When it opens Chrome my app loads fully in the browser, so I know that Angular is loaded and running correctly.
配置文件:
exports.config = {
seleniumServerJar: 'C:/Dev/PrismWeb/selenium/selenium-server-standalone-2.35.0.jar',
seleniumPort: null,
chromeDriver: 'C:/Dev/PrismWeb/selenium/chromedriver.exe',
seleniumArgs: [],
seleniumAddress: null,
allScriptsTimeout: 110000,
specs: ['c:/dev/prismweb/test/e2e/*.js'],
capabilities: {'browserName': 'chrome'},
baseUrl: 'http://localhost:8080',
rootElement: 'html',
jasmineNodeOpts: {
onComplete: null,
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 30000
}
};
我只有一个尝试运行的测试,但它失败了,因为 Protractor 找不到 Angular.
I've only got one test that I am trying to run and it fails because Protractor can't find Angular.
测试:
describe('homepage loads: ', function(){
var ptor;
ptor = protractor.getInstance();
beforeEach(function(){
ptor.get('/');
});
it('should load the prism homepage: ', function(){
var usernameField = ptor.findElement(protractor.By.id("username"));
//expect(usernameField).toBeDefined();
});
});
这是我得到的错误:
UnknownError:javascript 错误:未定义角度(会话信息:铬=30.0.1599.69)(驱动程序信息:chromedriver=2.2,platform=Windows NT 6.1 SP1 x86_64) (警告:服务器没有提供任何堆栈跟踪信息)命令持续时间或超时:19 毫秒构建信息:版本:'2.35.0',修订:'c916b9d',时间:'2013-08-12 15:42:01' 系统信息:os.name:'Windows7',os.arch:'amd64',os.version:'6.1',java.version:'1.7.0_21'会话 ID:1ef7dcd7c5fc9c4e9e1dede050002adf 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 功能 [{platform=XP,acceptSslCerts=true, javascriptEnabled=true, browserName=chrome,铬={chromedriverVersion=2.2},可旋转=假,locationContextEnabled=true,版本=30.0.1599.69,cssSelectorsEnabled=true,databaseEnabled=true,handlesAlerts=true,browserConnectionEnabled=false,webStorageEnabled=true,nativeEvents=true, applicationCacheEnabled=false,takeScreenshot=true}]
UnknownError: javascript error: angular is not defined (Session info: chrome=30.0.1599.69) (Driver info: chromedriver=2.2,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 19 milliseconds Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01' System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_21' Session ID: 1ef7dcd7c5fc9c4e9e1dede050002adf Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={chromedriverVersion=2.2}, rotatable=false, locationContextEnabled=true, version=30.0.1599.69, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
我尝试将 ng-app 属性移动到 body 标记(并相应地更改配置),但我得到了同样的错误.我们在 html 标签上也有一个 ng-controller 属性,我尝试将它移到正文中,并在 html 标签上单独保留 ng-app 属性,但结果是一样的.有人知道为什么会失败吗?
I've tried moving the ng-app attribute to the body tag (and changing the config accordingly) but I got the same error. We also have an ng-controller attribute on the html tag, and I tried moving that to the body and leaving the ng-app attribute alone on the html tag, but the result was the same. Does anybody have any insight as to why this fails?
只是一些可能会有所帮助的注释.我已经更新了上面的测试以包括手动引导工作.Angular 的脚本标签和所有模块都位于页面底部,就在结束 BODY 标签之前.HTML 标记仍然具有 ng-app="myApp" 属性和 ng-controller="baseController" 属性.如果我尝试在测试中手动引导应用程序,我会得到以下信息:
Just a couple of notes that might help. I've updated the test above to include the manual bootstrapping efforts. The script tags for Angular and all of the modules are located at the bottom of the page, right before the closing BODY tag. The HTML tag still has the ng-app="myApp" attribute plus the ng-controller="baseController" attribute. If I try to bootstrap the app manually in the test, I get the following:
ReferenceError: angular is not defined
让我担心的另一件事是,我们使用的其中一个模块绝对需要$"来映射到 jQuery,所以我们像这样映射它:
One other thing that worries me is that one of the modules we use absolutely needs "$" to be mapped to jQuery, so we map it like this:
<script type="text/javascript">
var $jq=jQuery.noConflict();
var $=jQuery.noConflict();
</script>
ng-app 包含在哪里:
Where the ng-app is included:
<!DOCTYPE html>
<html ng-app="prismApp" ng-controller="baseController">
<head>
我不太确定在 a, it()
中执行 beforeEach()
但是除此之外,你试过等一会儿吗?显然,我的意思是 ptor.waitForAngular()
或 ptor.wait()
?
I'm not too sure about doing a beforeEach()
within a, it()
but that aside, have you tried waiting a while?
Obviously by this i mean either a ptor.waitForAngular()
or a ptor.wait()
?
在你的 ptor.get()
之后尝试 ptor.sleep(10000)
只是为了看看它是否是一个计时的东西.
Try a ptor.sleep(10000)
after your ptor.get()
just to see if it is a timing thing.
也看看 protractor api以及 wait()
的工作原理:
also take a look at the protractor api and how wait()
works:
ptor.wait(function () {
// Return a condition. Code will continue to run once it is true
}, 10000); // Only do this for 10 seconds
尝试 ptor.driver.get('my-page');
而不是 ptor.get('my-page');
Protractor 现在将 browser
公开为全局,因此您可以只使用 browser.get('index.html#/foo')
或 browser.等待()
等
Protractor now exposes browser
as a global so you can just use browser.get('index.html#/foo')
or browser.wait()
etc.
这篇关于量角器找不到 Angular的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!