我是一个自动化的角度js网站,其中有一个登录功能。所有我想点击登录链接,并输入用户名和密码。但不知何故,我的脚本执行得比页面加载快得多。请建议我如何处理这个问题:我的登录页面对象是:
'use strict'
// Normal Login
require('../page-objects/loginPage.js');
var customerPortalHome = function () {
this.clickSignIn = function () {
browser.sleep(5000);
element(by.linkText('Sign In')).click();
browser.waitForAngular();
browser.sleep(2000);
return require('./loginPage.js');
}
}
module.exports = new customerPortalHome();我的测试规范是;
var co = require('co');
var UI = require('./ui.js');
var ui = new UI();
var CustomerPage = require('../page-objects/customerPortalHome.js')
describe(" Smoke Test Login to the application", function () {
it("test", co.wrap(function* () {
var EC = protractor.ExpectedConditions;
browser.get(ui.createStartLink());
expect(browser.getTitle()).toContain("Portal");
// Verify if user is able to Login into the application
var loginPage = CustomerPage.clickSignIn();
loginPage.switchToFrame('account-sdk');
var reportPage = loginPage.clickLogin('$$$$$@gmail.com', '$$$$$');
expect(browser.getCurrentUrl()).toContain('reports');
reportPage.clickSignOut();
expect(browser.getCurrentUrl()).toContain("?signout");
browser.sleep(800);
}));
}); 每当我执行测试时,浏览器都会打开一秒钟,然后关闭。
我的Onprepare方法看起来像这样:
beforeLaunch: function () {
return new Promise(function (resolve) {
reporter.beforeLaunch(resolve);
});
},
onPrepare: function () {
browser.manage().timeouts().implicitlyWait(5000);
afterEach(co.wrap(function* () {
var remote = require('protractor/node_modules/selenium-webdriver/remote');
browser.driver.setFileDetector(new remote.FileDetector());
}));发布于 2017-06-23 18:18:28
使用浏览器休眠从来都不是一个好主意,最好的做法是等待一个元素,然后使用then函数来完成此操作。
element(by.xpath("xpath")).click().then(function(){
var list = element(by.id('id'));
var until = protractor.ExpectedConditions;
browser.wait(until.presenceOf(list), 80000, 'Message: took too long');
});发布于 2017-06-26 11:02:54
browser.wait(protractor.ExpectedConditions.visibilityOf($$('.desk-sidebar > li').get(num-1)), 60000);通常,我使用这个等待。
发布于 2017-06-26 15:44:36
您是否在使用ignoreSynchronisation时没有将false放在页面对象帮助器中的某个位置?
要小心,当有很多重定向时,登录有时会破坏waitForAngular。当记录日志时,我最终使用了一个脏睡眠来等待页面加载(没有找到其他解决方案,ignoreSync、EC更改url和等待元素都不是有效的解决方案)。
你也应该分享你得到的错误。
https://stackoverflow.com/questions/44718713
复制相似问题