我是新来量角器和AngularJS。我使用的后端解析。试图做一个非常简单的测试:
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> ...它是由角路线加载。这条路线也是从后端加载数据:
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 }...的问题是由引起数据:上面的行。如果我采取的线路输出,或使其返回静态结果,它工作正常。另外,如果我提出这个元素的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.
这似乎是一个时间问题。不过根据文档量角器(或专门isElement present)定位元素之前等待各项决议。
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.
更新:根据这这是在量角器1.2解决了,但我上1.4。很奇怪的。
Update: According to this this was solved in Protractor 1.2, but I'm on 1.4. Very strange.
推荐答案因为它是一个时机的问题,解决方法可以等待元素是present你断言,这是present前:
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,解析
发布评论