量角器 - 在哪里使用 browser.waitForAngular()
Protractor - Where to use browser.waitForAngular()
我有一些使用量角器为 angular.js 应用程序编写的测试。我正在使用 Page Objects
设计模式,我有一些方法可以通过单击链接和按钮导航到其他页面。不久之后我打电话给 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();
};
};
并且在一些规范文件中我使用这个页面对象是这样的..
var DashboardPage = require('../dashboardPageObject.js');
dashboardPage = new DashboardPage();
...
dashboardPage.goToCompanyPage();
但问题是有时我会收到 angular could not be found on the window
错误并且我的测试失败。大多数时候测试 运行。这个问题是随机的。我的问题是我应该从页面对象方法中删除 browser.waitForAngular()
并在我像这样调用方法后调用它...
修改页面对象
...
this.goToCompanyPage = function () {
this.companyNameLink.click();
};
...
规格文件
dashboardPage.goToCompanyPage();
browser.waitForAngular();
调用 browser.waitForAngular()
是否导致问题?我应该在哪里打电话 waitForAngular
有没有关于如何使用它的最佳实践?
来自量角器的 documentation:
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.
你根本不应该调用它,我想不出你应该调用的有效案例。
而不是使用 waitForAngular
,您应该处理由 click
编写的承诺 return。
因此,首先,您的页面对象方法应该return那些承诺:
this.goToCompanyPage = function () {
return this.companyNameLink.click();
};
那么,你实际使用这个方法可以是这样的:
dashboardPage.goToCompanyPage().then(function() {
// this will be executed when the click is done.
// No need for any waitForAngular.
});
有关更多示例,请参阅我的 state/page-object version Angular PhoneCat Protractor 测试套件。
我在通过 browser.Url 导航到特定页面之前使用 browser.WaitForAngular()
否则,我在测试清理中断言的浏览器日志中出现错误。
我有一些使用量角器为 angular.js 应用程序编写的测试。我正在使用 Page Objects
设计模式,我有一些方法可以通过单击链接和按钮导航到其他页面。不久之后我打电话给 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();
};
};
并且在一些规范文件中我使用这个页面对象是这样的..
var DashboardPage = require('../dashboardPageObject.js');
dashboardPage = new DashboardPage();
...
dashboardPage.goToCompanyPage();
但问题是有时我会收到 angular could not be found on the window
错误并且我的测试失败。大多数时候测试 运行。这个问题是随机的。我的问题是我应该从页面对象方法中删除 browser.waitForAngular()
并在我像这样调用方法后调用它...
修改页面对象
...
this.goToCompanyPage = function () {
this.companyNameLink.click();
};
...
规格文件
dashboardPage.goToCompanyPage();
browser.waitForAngular();
调用 browser.waitForAngular()
是否导致问题?我应该在哪里打电话 waitForAngular
有没有关于如何使用它的最佳实践?
来自量角器的 documentation:
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.
你根本不应该调用它,我想不出你应该调用的有效案例。
而不是使用 waitForAngular
,您应该处理由 click
编写的承诺 return。
因此,首先,您的页面对象方法应该return那些承诺:
this.goToCompanyPage = function () {
return this.companyNameLink.click();
};
那么,你实际使用这个方法可以是这样的:
dashboardPage.goToCompanyPage().then(function() {
// this will be executed when the click is done.
// No need for any waitForAngular.
});
有关更多示例,请参阅我的 state/page-object version Angular PhoneCat Protractor 测试套件。
我在通过 browser.Url 导航到特定页面之前使用 browser.WaitForAngular() 否则,我在测试清理中断言的浏览器日志中出现错误。