Angular 量角器无需等待网页更改
使用带量角器的角5 在等待浏览器url更改以查看用户是否登录然后登录到内部仪表板页面时遇到问题 规格:Angular 量角器无需等待网页更改,angular,selenium,protractor,Angular,Selenium,Protractor,使用带量角器的角5 在等待浏览器url更改以查看用户是否登录然后登录到内部仪表板页面时遇到问题 规格: fdescribe('Suite 1', function() { it('should login and land on the dashboard page', function() { // Arrange browser.ignoreSynchronization = true; const baseUrl = 'confidentialUrl';
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');
});
执行“Gradurator conf.js”时出现的错误:
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');
});
失败:等待条件必须是类似承诺的对象、函数或
条件对象
需要一个对象作为第一个参数,该参数是条件对象或类似承诺的对象。例如,您可以从量角器
// 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');
});
我们通过使用解决了这类问题
我编辑了您的代码,因此在您的情况下:
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);
});
你能在问题中编辑我上面的代码,然后我试试吗。上面的例子有点混乱。谢谢你的更新。我运行了测试,并得到了这个错误:失败:等待超时后5004msCan你尝试添加更多的秒?是的,我添加了10秒,并得到了相同的错误。我注意到url没有改变,例如从/login到/dashboard页面。它似乎会暂停浏览器,而不是等待浏览器更改。您确定您的应用程序在登录到页面
机密URL/仪表板
后正在重定向吗?因为您关闭了同步,您需要解决自己的问题。