我需要先在非角度页面上登录并采取一些操作(https://www.qa.dealertrack.com/default1.aspx) 然后切换到角度页面并完成测试。 在CONF我在我最近的测试中,在非角度页面上使用量角器
global.driver = browser.driver;
我的页面对象的样子:
var LogInPage = function() {
this.loginUrl = 'https://www.qa.dealertrack.com/default1.aspx';
this.id = browser.driver.findElement(by.name('username'));
this.password = browser.driver.findElement(by.name('password'));
this.loginButton = browser.driver.findElement(by.name('login'));
this.logIn = function(id, password) {
// maximize window
driver.manage().window().maximize();
// log in
driver.get('https://www.qa.dealertrack.com/default1.aspx');
this.id.sendKeys(id);
this.password.sendKeys(password);
this.loginButton.click();
}
};
我的测试看起来像:
describe('Sample Test - Log In', function() {
var loginPage = require('../pages/LogInPage.js');
/**
* Disable waiting for AngularJS for none Angular page
*/
beforeEach(function() {
isAngularSite(false);
});
it('logging in', function() {
loginPage.logIn('xxx', 'xxx');
})
})
然而,即使让到现场之前,量角器抛出错误NoSuchElementError :无此元素:无法找到元素:{'method':'name','selector':'username'}
但是当我评论了所有的元素变量和相关线路,只剩
driver.get(this/loginUrl);
它的工作。为什么browser.driver.get会工作,但browser.driver.findElement
不?
这是我在Stackoverflow上的第一个问题。谢谢大家!
检查: https://github.com/angular/protractor/issues/51 如果您在使用非角度应用程序时使用量角器: browser.ignoreSynchronization = true; – Nick