量角器、AngularJS、解析器——量角器不等待 Angular 解析 [英] Protractor, AngularJS, Parse -- Protractor does not wait for Angular to resolve
问题描述
我是 Protractor 和 AngularJS 的新手.我在后端使用 Parse.尝试做一个非常简单的测试:
I am new to Protractor and AngularJS. I'm using Parse on the back end. Trying to do a very simple test:
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
}); ...
测试失败.该元素在 template.html 中:
The test fails. The element is in template.html:
...
<body>
<button id="test321">stuff</button>
...
它是由angular-route加载的.此路由也从后端加载数据:
It is loaded by angular-route. This route also loads data from back end:
...
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
}...
问题是由上面的data:"行引起的.如果我去掉那条线,或者让它返回静态结果,它就可以正常工作.此外,如果我移动这个元素 index.html 它也可以工作.
The problem is caused by the "data:" line above. If I take that line out, or have it return static result it works fine. Also if I move this element index.html it works as well.
这似乎是一个时间问题.然而,根据文档量角器(或特别是 isElementPresent)在定位元素之前等待所有分辨率.
This seems like a timing issue. However according to the documentation protractor (or specifically isElementPresent) waits for all resolutions before locating elements.
我被踩到了.非常感谢您的帮助.
I'm stomped. Many thanks for any help.
更新:根据 this 这已在 Protractor 1.2 中解决,但我在 1.4.很奇怪.
Update: According to this this was solved in Protractor 1.2, but I'm on 1.4. Very strange.
推荐答案
由于这是一个时间问题,解决方法可以是在断言元素存在之前等待元素存在:
Since it's a timing issue, a workaround can be to wait for the element to be present before you assert that it's present:
describe('Test', function () {
beforeEach(function () {
browser.get('index.html#/example')
});
it('should have a button', function () {
browser.wait(function() {
return $('#test321').isPresent(); // keeps waiting until this statement resolves to true
}, timeToWaitInMilliseconds, 'message to log to console if element is not present after that time');
expect($('#test321').isPresent()).toBe(true);
}); ...
这篇关于量角器、AngularJS、解析器——量角器不等待 Angular 解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!