我正在尝试遵循Protractors official site上的量角器教程,但我什至无法完成步骤0。
我在版本6.0.0中使用量角器和webdriver-manager。我的SO是Linux(Ubuntu 18.06),而我的Chrome是最新的(73.0.3683.86)。
安装量角器后,我不得不降级默认安装的chromedriver,因为它期望我拥有Chrome74。我通过执行webdriver-manager --versions.chrome 73.0.3683.68
降级了它。
在那之后,我一直遵循本教程的步骤0。我有configuration.js文件和test-spec.js文件,如下所示:
configuration.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['test-spec.js']
};
test-spec.js
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
运行protactor protractor configuration.js
时出现以下错误:
[15:15:13] I/hosted - Using the selenium server at http://localhost:4444/wd/hub DEPRECATION: Setting randomizeTests directly is deprecated, please use the random option in `configure` DEPRECATION: Setting specFilter directly on Env is deprecated, please use the specFilter option in `configure` Started F Failures: 1) Protractor Demo App should have a title Message: Expected [object Promise] to equal 'Super Calculator'. Stack: Error: Expected [object Promise] to equal 'Super Calculator'. at at UserContext. (/home/srubio/Escritorio/Protractor/test-spec.js:5:32) at 1 spec, 1 failure Finished in 0.009 seconds /home/srubio/n/lib/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:3190 throw arguments[0]; ^ 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 http://git.io/v4gXM for details" at ProtractorBrowser. (/home/srubio/n/lib/node_modules/protractor/built/browser.js:354:27) at Generator.next () at fulfilled (/home/srubio/n/lib/node_modules/protractor/built/browser.js:4:58) at processTicksAndRejections (internal/process/next_tick.js:81:5)
答案 0 :(得分:5)
更新此答案
Protractor version 6.0使用selenium version 4,这是第一个删除对控制流的支持的硒版本。控制流程使量角器可以执行类似的代码
browser.get('http://google.com');
expect(browser.getTitle()).toEqual('Super Calculator');
以同步方式。
到目前为止,一直使用控制流来以用户友好的方式处理webdriverJS承诺的异步性质。一旦es8 async/await样式的承诺处理得到支持,便决定弃用控制流并建议用户利用异步/等待进行。
6.0是量角器的latest version,我相信它是3天前(大约22 / March / 19)发布的,它放弃了对以前默认启用的控制流的支持。显然,教程文档尚未更新以反映此问题,但是我相信这就是为什么您看到此问题。
展望未来,您将需要使用async/await语法(在我看来,它实际上更具可读性和易用性)
尝试以下代码:
configuration.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['test-spec.js']
};
test-spec.js
describe('Protractor Demo App', function() {
it('should have a title', async function() {
await browser.get('http://juliemr.github.io/protractor-demo/');
expect(await browser.getTitle()).toEqual('Super Calculator');
});
});
更新:
如果您尝试将SELENIUM_PROMISE_MANAGER: true,
添加到configuration.js
中,这可能使您可以在编写演示时继续进行演示。