量角器无法找到元素和脚本超时 [英] Protractor unable to find elements and script timeout
问题描述
我正在运行量角器,它成功运行并加载我的角度应用程序. 我编写的第一个测试是获取注册按钮.尽管我可以在视图中看到注册"按钮,并且可以使用适当的CSS对其进行定位.
I'm running protractor, it runs successfully and load my angular app. The very first test I wrote is to get the sign-up button. Although I can see the sign-up button in my view and I'm targeting it with proper CSS.
仍然,运行测试后,我得到的只是这个错误.
Still, all I get is this error after running the test.
App
✗ should get the text of sign up button
- Failed: script timeout: result was not received in 11 seconds
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.45.615355 (d5698f682d8b2742017df6c81e0bd8e6a3063189),platform=Mac OS X 10.14.2 x86_64)
我试图增加protractor.conf.ts
文件中的allScriptsTimeout
,但无济于事.
I've tried to increase the allScriptsTimeout
in the protractor.conf.ts
file but to no avail.
app.e2e-spec.ts 文件
it('should get the text of sign up button', () => {
page.navigateTo();
expect<any>(page.getButtonText()).toEqual('Sign up');
});
app.po.ts
getButtonText() {
return element(by.css('a[data-e2e="nav-signup"]')).getText();
}
navigateTo() {
return browser.get('/');
}
在这里我可能做错了什么?
What might I be doing wrong here?
推荐答案
更新了一些语法,并从页面对象功能中删除了异步/唤醒.
Updated some syntax and removed async/awaits from page object function.
正如我提到的,您的失败很可能是由于异步问题引起的.您可以尝试更改代码以禁用conf中的promise_manager并使用async/await语法,看看是否对您有帮助?
As I mentioned your failure is likely due to an async issue. Can you try changing your code to disable the promise_manager in the conf and use the async/await syntax and see if that helps you?
与浏览器交互的每个动作都需要先等待,并且每个包含等待的功能都需要标记为 async
Every action that interacts with the browser will need an await before it and every function that contains an await will need to be labeled async
Conf.js
exports.config = {
framework: 'jasmine',
specs: ['./app.js'],
// specs: ['./app.js','./app.1.js'],
seleniumAddress: 'http://localhost:4444/wd/hub',
SELENIUM_PROMISE_MANAGER: false
}
页面对象
getButtonText() {
return element(by.css('a[data-e2e="nav-signup"]')).getText();
}
navigateTo() {
return browser.get('/');
}
规范文件
it('should get the text of sign up button', async () => {
await page.navigateTo();
expect(await page.getButtonText()).toEqual('Sign up');
});
这篇关于量角器无法找到元素和脚本超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!