【发布时间】:2021-05-29 13:37:02
【问题描述】:
我有两个角度应用程序
-
用于登录
-
业务逻辑
我尝试使用量角器开始对这些应用程序进行自动化测试。但是在登录后(第一个应用程序)从第二个应用程序获取元素详细信息时面临问题。
文件是
specs: [
'login.js',// 1st application
'navigatetoRegisterReport.js',// page loaded by menu navigation from 1st application
'requestCreation.js',// 2nd application page loaded by `browser.get(2nd app Url)`
'navigateToDcOtherInvoice.js'// navigation to another screen in my 2nd application
],
我已经通过以下方式完成了登录逻辑,并且运行良好
async first() {
await browser.driver.get(browser.baseUrl).then(async () => {
await browser.wait(ExpectedConditions.elementToBeClickable(element(by.linkText("Other User"))), 30000);
await element(by.linkText("Other User")).click().then(() => {
browser.wait(ExpectedConditions.elementToBeClickable(element(by.css('#username'))), 30000);
element(by.css('#username')).sendKeys('XXXXX').then(() => {
browser.wait(ExpectedConditions.elementToBeClickable(element(by.id("password-field"))), 30000);
element(by.id("password-field")).sendKeys('XXXXX').then(() => {
browser.wait(ExpectedConditions.elementToBeClickable(element(by.id('login-submit'))), 30000);
element(by.id('login-submit')).click().then(async () => {
const dashboardImage = await element(by.css("app-dashboard .dashboard-image"));
browser.wait(ExpectedConditions.elementToBeClickable(dashboardImage), 30000);
dashboardImage.isDisplayed().then((value) => {
if (value == true) {
console.log('dashborad image is displayed')
} else {
console.log('dashborad image is not identified')
}
}).catch(error => console.error('caught error while login', error));;
}).catch(error => console.error('caught error 7', error));;
}).catch(error => console.error('caught error on password', error));;
}).catch(error => console.error('caught error on user name', error));;
}).catch(error => console.error('caught error tab click', error));;
}).catch(error => console.error('caught error on load', error));
}
但是在从第二个应用程序获取元素值时,我遇到了错误
async requestCreation(date: string, report: string) {
await browser.get('https://2ndapplication/xxx/xxxx').then(async () => {
var selectDate = element(by.xpath("//input[@id='icon-right']"));
var reportType = element(by.xpath("//input[@placeholder='Report Type']"));
browser.wait(ExpectedConditions.elementToBeClickable(selectDate), 30000);
selectDate.clear();
selectDate.sendKeys(date)
browser.wait(ExpectedConditions.elementToBeClickable(reportType), 30000);
reportType.click();
reportType.clear();
reportType.sendKeys(report)
}).catch(error => console.error('caught error on requestCreation', error));
}
错误:
ScriptTimeoutError: script timeout
(Session info: chrome=88.0.4324.190)
(Driver info: chromedriver=88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784}),platform=Windows NT 10.0.18363 x86_64)
at Object.checkLegacyResponse (E:\updatedCode\backup\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (E:\updatedCode\backup\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (E:\updatedCode\backup\node_modules\selenium-webdriver\lib\http.js:441:30)
at process._tickCallback (internal/process/next_tick.js:68:7)
From: Task: Protractor.waitForAngular() **- Locator: By(xpath, //input[@id='icon-right'])
我可以在浏览器中看到该元素并且它是可见的。但是量角器抛出错误,因为它不存在。我知道如果我为 WaitForAngularDisabled(false) 提供 false 就会解决。但是这两个应用程序都仅由 Angular 实现。所以我不想通过禁用角度来失去任何量角器功能。那么如何通过量角器测试两个角度应用呢?
版本:
- 保护器:7.0.0
- 角度:7.3.9
【问题讨论】:
-
你为什么要用这么多的链接把你的代码弄得这么乱!!!!你不能直接使用等待而不是链接。有了这样的承诺链,代码真的是一个令人头疼的维护问题
-
@PDHide 感谢您的回复。实际上它适用于我的第一个应用程序,问题是我的第二个应用程序抛出无法找到元素错误。
-
它肯定会起作用,但问题是当某些东西中断并且您必须调试时,更改链接并使其等待
-
并非所有角度应用程序都可以使用默认的 waitForAngularEnabled(true) 量角器进行测试。在这里查看如何检查您的应用程序是否可以运行stackoverflow.com/a/66111219/9150146 让我知道您的每个页面上的 getAllAngularTestabilities 返回什么
标签: angular automation jasmine protractor