[英]Protractor no waiting for web page to change
将Angular 5与量角器配合使用。
在等待浏览器URL更改以查看用户是否登录然后登陆内部仪表板页面时遇到麻烦。
规格:
fdescribe('Suite 1', function() {
it('should login and land on the dashboard page', function() {
// Arrange
browser.ignoreSynchronization = true;
const baseUrl = 'confidentialUrl';
const email = 'email';
const password = 'password';
// Act
browser.get(baseUrl);
element(by.id('username')).sendKeys(email);
element(by.id('password')).sendKeys(password);
element(by.css('.submit-btn')).click();
// Assert
browser.wait(5000);
const currentUrl = browser.getCurrentUrl();
expect(currentUrl).toEqual('confidentialUrl/dashboard');
});
执行“量角器conf.js”时出现错误:
失败:等待条件必须是类似promise的对象,函数或Condition对象
browser.wait
需要一个对象作为第一个参数,它是条件对象或类似Promise的对象。 例如,您可以从protractor
创建预期条件
// Expected condition object
const EC = protractor.ExpectedConditions;
// wait 5 seconds for expected condition
// in this case it will wait for url contains a given value
browser.wait(EC.urlContains('foo'), 5000).then(() => {
// then you can assert here
const currentUrl = browser.getCurrentUrl();
return expect(currentUrl).toEqual('confidentialUrl/dashboard');
});
我们通过使用ExpectedConditions解决了此类问题。
我编辑了您的代码,因此在您的情况下:
fdescribe('Suite 1', function() {
it('should login and land on the dashboard page', function() {
// Arrange
browser.ignoreSynchronization = true;
const baseUrl = 'confidentialUrl';
const email = 'email';
const password = 'password';
// Act
browser.get(baseUrl);
element(by.id('username')).sendKeys(email);
element(by.id('password')).sendKeys(password);
element(by.css('.submit-btn')).click();
// Assert
const EC = protractor.ExpectedConditions;
browser.wait(EC.urlContains('confidentialUrl/dashboard'), 5000).then(() => {
const currentUrl = browser.getCurrentUrl();
return expect(currentUrl).toEqual('confidentialUrl/dashboard');
})
});
或者您可以:
fdescribe('Suite 1', function() {
it('should login and land on the dashboard page', function() {
// Arrange
browser.ignoreSynchronization = true;
const baseUrl = 'confidentialUrl';
const email = 'email';
const password = 'password';
// Act
browser.get(baseUrl);
element(by.id('username')).sendKeys(email);
element(by.id('password')).sendKeys(password);
element(by.css('.submit-btn')).click();
// Assert
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return expect(url).toEqual('confidentialUrl/dashboard');
});
}, 10000);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.