【问题标题】:Using Angular 7.x with Protractor 6 (beta)将 Angular 7.x 与 Protractor 6(测试版)一起使用
【发布时间】: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


    【解决方案1】:

    Protractor 6.0.0-beta 不适用于 angular-cli

    感谢您站在最前沿(并试用我的版本)!希望它主要在这个问题之外起作用。不幸的是,angular-cli 和 Protractor 的新版本(6.0.0-beta)不能一起工作。一旦 Protractor 正式发布并且 angular-cli 使用它,这个故事将会改善。

    目前推荐的路径是,如果您想使用 6 beta,将其(您的测试)与 angular-cli 项目分开。

    page.getTitleText()未被等待时

    page.getTitleText() 的错误可能与最终解决承诺有关,浏览器会话被 Protractor 关闭(这可能不是最好的错误消息)。另外你只需要做一个expect(await page.getTitleText()).toEqual('Welcome to ng72!');,你需要在expect前面加上一个await

    【讨论】:

    • 感谢您的反馈!尝试单独使用量角器。我遇到的一个问题是测试用例的顺序。默认情况下,测试现在以随机顺序执行:bash Randomized with seed 78491 Started Jasmine started 我很难覆盖它:json jasmineNodeOpts: { random: false, ... } 我看到一些指针表明基础 Jasmine 配置在 3.3.0 中发生了变化。我错过了什么还是这仍然很出色?
    • 看起来 jasmine.getEnv().randomizeTests(false); 可以解决问题。
    • 嗯...看起来这应该默认发生。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多