【发布时间】:2019-01-09 09:37:49
【问题描述】:
是否有人能够使用Protractor 6 (beta) 执行Angular CLI 7.x E2E 测试?由于https://github.com/angular/protractor/issues/4294 描述的问题,我很期待尝试selenium-webdriver@4.0.0-alpha.1,但它似乎没有那么简单,并且遇到了webdriver-manager 找不到的问题。
Protractor 测试版在此处删减:
https://github.com/angular/protractor/commit/205c4d88ace8851b8fa71a75c5d66249c9a63c3b
更新(正在运行)
我相信我明白了。使其工作的步骤:
在Mac OS X 10.13.6 上使用节点10.15.0 LTS:
$ node -v
v10.15.0
使用 Angular CLI 7.2.1。
$ ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 7.2.1
Node: 10.15.0
OS: darwin x64
Angular: 7.2.0
...
创建一个简单的应用程序:
$ ng new ng72 --routing=true --style=scss
更新package.json:
"jasmine-core": "^3.3.0","protractor": "6.0.0-beta"
更新await/async的测试:
import { AppPage } from './app.po';
describe('workspace-project App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
it('should display welcome message', async() => {
await page.navigateTo();
await expect(await page.getTitleText()).toEqual('Welcome to ng72!');
});
});
然后执行:
$ npm install$ ./node_modules/protractor/bin/webdriver-manager update$ npm rebuild node-sass$ ng e2e --no-webdriver-update
Google (Version 72.0.3626.53) 将启动,测试正在成功执行。
作为旁注。如果你不做await page.getTitleText(),那么测试
以相当模糊的 NoSuchSessionError: invalid session id:
**************************************************
* Failures *
**************************************************
1) workspace-project App should display welcome message
- Expected ElementFinder({ browser_: ProtractorBrowser({ execute: Function, setFileDetector: Function, getExecutor: Function, getSession: Function, getCapabilities: Function, quit: Function, actions: Function, executeScript: Function, executeAsyncScript: Function, wait: Function, sleep: Function, getWindowHandle: Function, getAllWindowHandles: Function, getPageSource: Function, close: Function, getCurrentUrl: Function, getTitle: Function, findElementInternal_: Function, findElementsInternal_: Function, takeScreenshot: Function, manage: Function, switchTo: Function, driver: Driver({ session_: [object Promise], executor_: Executor({ w3c: false, customCommands_: Map( [ 'launchApp', Object({ method: 'POST', path: '/session/:sessionId/chromium/launch_app' }) ], [ 'getNetworkConditions', Object({ method: 'GET', path: '/session/:sessionId/chromium/network_conditions' }) ], [ 'setNetworkConditions', Object({ method: 'POST', path: '/session/:sessionId/chromium/network_conditions' }) ], [ 'sendDevTools ... to equal 'Welcome to ng72!'.
Executed 1 of 1 spec (1 FAILED) in 0.484 sec.
Randomized with seed 13684.
/Users/dev/ng72/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:3190
throw arguments[0];
^
NoSuchSessionError: invalid session id
(Driver info: chromedriver=72.0.3626.7 (efcef9a3ecda02b2132af215116a03852d08b9cb),platform=Mac OS X 10.13.6 x86_64)
【问题讨论】:
标签: angular selenium-webdriver protractor angular-cli