在禁用流控制以测试Angular应用程序时,Protractor会生成错误
我一直在努力解决这个错误,而且我已经没法力了。我目前正在尝试使用量角器和async / await测试Angular应用程序。根据文档,我必须通过在配置文件中添加以下内容来禁用控制流:
SELENIUM_PROMISE_MANAGER: false
但这样做会产生以下错误:
UnhandledPromiseRejectionWarning: Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See for details"
我访问了网址(),但结果并没有太大帮助。
在这一点上,我不确定我是做错了什么,或者它是否是量角器本身的错误。出于这个原因,我也opened an issue on GitHub。
这是我的测试:
import {
browser,
ExpectedConditions,
$
} from 'protractor';
describe('When user click \"Test\" button', async () => {
beforeAll(async () => {
expect(browser.getCurrentUrl()).toContain('myawesomewebsite');
});
it ("should click the button", async () => {
var button = $(".button");
button.click();
});
});
这是我的完整配置:
exports.config = {
capabilities: {
'browserName': 'chrome'
},
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine',
specs: ['test.spec.ts'],
SELENIUM_PROMISE_MANAGER: false,
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
beforeLaunch: function () {
require('ts-node/register')
}
};
回答如下:
在每个量角器api调用之前你错过了await
。
describe('When user click \"Test\" button', async () => {
beforeAll(async () => {
expect(await browser.getCurrentUrl()).toContain('myawesomewebsite');
});
it ("should click the button", async () => {
var button = $(".button");
await button.click();
});
});