問題描述
我有一些使用量角器為 angular.js 應用程序編寫的測試.我正在使用 Page Objects
設計模式,并且我有一些方法可以通過單擊鏈接和按鈕導航到其他頁面.不久之后,我正在調用 browser.waitForAngular()
.
I have some tests written using protractor for angular.js app. I am using Page Objects
design pattern and there i have some methods that navigate to other pages by clicking on links and buttons. and soon after that i am calling browser.waitForAngular()
.
頁面對象
module.exports = function () {
this.companyNameLink = element(by.id('viewCompany'));
this.newMeetingButton = element(by.id('newMeetingButton'));
this.createNewGeneralMeeting = function () {
this.newMeetingButton.click();
browser.waitForAngular();
};
this.goToCompanyPage = function () {
this.companyNameLink.click();
browser.waitForAngular();
};
};
在一些規范文件中,我像這樣使用這個頁面對象..
And in some spec file i use this page object like this..
var DashboardPage = require('../dashboardPageObject.js');
dashboardPage = new DashboardPage();
...
dashboardPage.goToCompanyPage();
但問題是有時我得到 angular could not be found on the window
錯誤并且我的測試失敗.大多數時候測試運行.這個問題是隨機的.我的問題是我應該從頁面對象方法中刪除 browser.waitForAngular()
并在我像這樣調用方法后調用它...
But the problem is sometimes i get the angular could not be found on the window
error and my tests fail. Most of the time the tests run. This issue is random. My question is that should i remove the browser.waitForAngular()
from the page object method and call it after i make the method call like this...
修改后的頁面對象
...
this.goToCompanyPage = function () {
this.companyNameLink.click();
};
...
規格文件
dashboardPage.goToCompanyPage();
browser.waitForAngular();
調用 browser.waitForAngular()
是否會導致問題?我應該在哪里調用 waitForAngular
有沒有關于如何使用它的最佳實踐?
Is calling browser.waitForAngular()
causing the issue? Where should i call waitForAngular
is there any best practice on how to use this?
推薦答案
來自protractor的文檔:
From protractor's documentation:
指示 webdriver 等到 Angular 完成渲染并且沒有未完成的 $http 或 $timeout 調用后再繼續.請注意,量角器會在每個 WebDriver 操作之前自動應用此命令.
Instruct webdriver to wait until Angular has finished rendering and has no outstanding $http or $timeout calls before continuing. Note that Protractor automatically applies this command before every WebDriver action.
你根本不應該調用這個,我想不出一個你應該調用的有效案例.
You shouldn't be calling this at all and I cannot think of a valid case where you should.
這篇關于量角器 - 在哪里使用 browser.waitForAngular()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!