我正在尝试按照 Protractors official site 上的 Protractor 教程进行操作但我什至无法完成第 0 步。
我在 6.0.0 版中使用 Protractor 和 webdriver-manager。我的 SO 是 Linux (Ubuntu 18.06),我的 Chrome 是最新的 (73.0.3683.86)。
安装 Protractor 后,我不得不降级默认安装的 chromedriver,因为它希望我拥有 Chrome 74。我通过执行 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)
最佳答案
更新此答案
Protractor version 6.0使用 selenium version 4这是第一个放弃对控制流支持的 selenium 版本。控制流允许 Protractor 执行如下代码
browser.get('http://google.com');
expect(browser.getTitle()).toEqual('Super Calculator');
以同步方式。
为了以用户友好的方式处理 webdriverJS 的 promise 的异步性质,控制流一直被使用到现在。一旦es8 async/await promise 处理风格得到支持,但决定弃用控制流并建议用户在未来利用 async/await。
原始答案
6.0 是 latest version Protractor,我相信它是在 3 天前(大约 22/March/19)发布的,它放弃了对以前默认启用的控制流的支持。显然,教程文档尚未更新以反射(reflect)这一点,我相信这就是您看到此问题的原因。
以后您将需要使用 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
中,这可能允许您继续编写演示。
关于javascript - Protractor "Error while waiting for Protractor to sync with the page"浏览 Angular 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55359412/