angular - 将一个角度应用程序导航到另一个角度应用程序时量角器超时错误
问题描述
我有两个角度应用程序
登录
对于业务逻辑
我尝试使用量角器开始对这些应用程序进行自动化测试。但面临登录后从第二个应用程序(第一个应用程序)获取元素详细信息的问题。
这些文件是
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)
. 但是这两个应用程序都仅由 Angular 实现。所以我不想通过禁用角度来失去任何量角器功能。那么如何通过量角器测试两个角度应用呢?
版本:
- 保护者:7.0.0
- 角度:7.3.9
解决方案
正如我在评论中提到的,您的问题是因为您的 Angular 应用程序不断地在后台轮询某些东西,即使在视觉上它可能看起来页面已经准备好。你可以在量角器页面和这里阅读更多关于它的信息。不幸的是,我只做测试自动化,从未尝试在应用程序端解决问题。但是,无论如何,我总是倾向于禁用量角器的等待角度,所以它从来没有真正困扰过我
我知道您已经在另一篇文章中看到了我的答案,我只是想在这里背诵一些以供大家参考
- 确定您的页面是否为 Angular:在浏览器中和“控制台”选项卡运行命令中打开开发控制台
getAllAngularTestabilities()
如果输出是getAllAngularTestabilities is not defined
,那么您的页面不是有角度的,请转到步骤 #3 以禁用内置等待
- 如果您的页面是有角度的,那么庆祝还为时过早,因为 Protractor 可能仍然无法在本地工作。在控制台中运行这些命令以检查它是否存在
getAllAngularTestabilities()[0]._ngZone.hasPendingMacrotasks
getAllAngularTestabilities()[0]._ngZone.hasPendingMicrotasks
如果其中任何一个返回true
(如果有待处理的微任务或宏任务),则转到最后一步。如果都是false
,恭喜,您可以使用内置量角器的等待角。但是,如果您不喜欢它,我不喜欢它,请阅读最后一步以了解如何禁用它
- 运行上述命令。但!它返回一个promise,需要处理,最好使用
await
关键字
await browser.waitForAngularEnabled(false)
完整答案在这里
推荐阅读
- c# - 实体框架对使用复合主键的表形成虚拟集合
- database - 自动将日志从 keycloak 数据库传输到 syslog
- javascript - 同一部手机多次访问后,HTML 视频无法在手机上播放
- java - 您的 SQL 语法有错误,但查询在 MySQL 工作台中运行
- python - 如何在 Linux 中使用 Python 运行 C# 代码
- c# - 如何更改内存提供程序中的配置?
- android - 无法阻止 Android 房间数据库中的触发器递归
- c++ - glad.c 找不到glad/glad.h,但是main.cpp 可以
- asp.net - 从 Razor revisa_login.cshml 访问 Session 对象
- itext - 在 iText 7 java 中,如何在已将链接文本添加到文档后更新链接文本