我是Protractor和AngularJS的新手.我在后端使用Parse.试着做一个非常简单的测试:
describe('Test', function () {
beforeEach(function () {
browser.get('index.html#/example')
});
it('should have a button', function () {
expect(element(by.css('#test321')).isElementPresent()).toBe(true); //fails
}); ...
Run Code Online (Sandbox Code Playgroud)
测试失败.该元素位于template.html中:
...
<body>
<button id="test321">stuff</button>
...
Run Code Online (Sandbox Code Playgroud)
它由角度路径加载.此路由还从后端加载数据:
...
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/example', {
templateUrl: 'template.html',
controller: 'templateCtrl',
resolve: {
data: 'dataService' //Data is loaded from Parse. This line causes the problem
}...
Run Code Online (Sandbox Code Playgroud)
问题是由上面的"data:"行引起的.如果我拿出那条线,或者让它返回静态结果,它可以正常工作.此外,如果我移动此元素index.html也可以.
这似乎是一个时间问题.但是根据文档量角器(或特别是isElementPresent)在定位元素之前等待所有分辨率.
我被踩了.非常感谢任何帮助.
更新:据此,这在Protractor 1.2中得到了解决,但我在1.4.很奇怪.