我正在运行量角器,它成功运行并加载我的角度应用程序。 我编写的第一个测试是获取注册按钮。尽管我可以在视图中看到“注册”按钮,并且可以使用适当的CSS进行定位。
仍然,运行测试后,我得到的只是这个错误。
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)
我尝试将allScriptsTimeout
文件中的protractor.conf.ts
增大,但无济于事。
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('/');
}
在这里我可能做错了什么?
答案 0 :(得分:3)
更新了一些语法,并从页面对象功能中删除了异步/唤醒。
正如我提到的,您的失败很可能是由于异步问题引起的。您可以尝试更改代码以禁用conf中的promise_manager并使用async / await语法,看看是否有帮助?
我先前在subject of the async/await & the promise manager上的答案
与浏览器交互的每个动作都需要先等待,并且每个包含等待的功能都需要标记为 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');
});