我们的登录屏幕是非角度的,登录后将其重定向到角度应用程序。我们正在conf.js中使用以下脚本登录。一切正常,没有任何问题。所有突然的相同脚本开始失败。
onPrepare: async function() {
browser.ignoreSynchronization = true
await browser.waitForAngularEnabled(false);
await browser.get('http://abc.dev.xyz.com');
await element(By.id('userName')).sendKeys('abcd');
await element(By.className('btn btn-primary')).click();
await element(By.id('password')).sendKeys('xyz@123');
await element(By.className('btn btn-primary')).click();
await browser.waitForAngularEnabled(true);
browser.manage().window().maximize();
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'target/screenshots',
preserveDirectory: false,
takeScreenShotsOnlyForFailedSpecs: true,
docTitle: 'UI Automation Test Report'
}).getJasmine2Reporter());
}
在运行时,只需打开浏览器并启动URL。之后立即关闭浏览器。以前,它用于等待登录页面加载并继续。现在,它根本没有等到页面加载。因此无法找到用户名字段。我不想在这里使用硬编码的等待。知道为什么它开始失败了吗?我尝试过更新webdiver-manager。什么都没用
答案 0 :(得分:0)
这是因为在DOM中加载username
元素会花费一些时间。调用以下行await browser.get('http://abc.dev.xyz.com');
首先您需要导入
import { browser, protractor } from 'protractor';
const { ExpectedConditions: until } = protractor
在await browser.get('http://abc.dev.xyz.com');
await browser.wait(until.presenceOf(element(By.id('userName'))), 60000, 'Taking more time');
60000->特定组件加载所需的最长时间(设置时间限制)。
最终解决方案
import { browser, protractor } from 'protractor';
const { ExpectedConditions: until } = protractor
onPrepare: async function() {
browser.ignoreSynchronization = true
await browser.waitForAngularEnabled(false);
await browser.get('http://abc.dev.xyz.com');
await browser.wait(until.presenceOf(element(By.id('userName'))), 60000, 'Taking more time');
await element(By.id('userName')).sendKeys('abcd');
await element(By.className('btn btn-primary')).click();
await element(By.id('password')).sendKeys('xyz@123');
await element(By.className('btn btn-primary')).click();
await browser.waitForAngularEnabled(true);
browser.manage().window().maximize();
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'target/screenshots',
preserveDirectory: false,
takeScreenShotsOnlyForFailedSpecs: true,
docTitle: 'UI Automation Test Report'
}).getJasmine2Reporter());
}