我如何在现有项目angular 7中集成e2e测试

时间:2018-11-15 16:55:07

标签: angular jasmine protractor e2e-testing angular7

我的e2e文件夹已被删除,现在我正尝试从新项目中添加新文件夹,但是我遇到了一些问题:

ng e2e 有效并且出现导航,但是默认测试无效:

当我执行 ng e2e 时:

    PS D:\Front> ng e2e
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

Date: 2018-11-15T16:18:54.401Z
Hash: 9b50fbb72fe71f9a2063
Time: 33191ms

i 「wdm」: Compiled successfully.
    DevTools listening on ws://127.0.0.1:55832/devtools/browser/fe26995e-5889-4bf4-adda-fb4ce77610fb
    Jasmine started

      workspace-project App
        × should display welcome message
          - Failed: No element found using locator: By(css selector, app-root h1)
              at elementArrayFinder.getWebElements.then (D:\Front\node_modules\protractor\built\element.js:814:27)
              at ManagedPromise.invokeCallback_ (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1376:14)
              at TaskQueue.execute_ (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
              at TaskQueue.executeNext_ (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
              at asyncRun (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2927:27)
              at D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
              at <anonymous>
              at process._tickCallback (internal/process/next_tick.js:188:7)Error
              at ElementArrayFinder.applyAction_ (D:\Front\node_modules\protractor\built\element.js:459:27)
              at ElementArrayFinder.(anonymous function).args [as getText] (D:\Front\node_modules\protractor\built\element.js:91:29)
              at ElementFinder.(anonymous function).args [as getText] (D:\Front\node_modules\protractor\built\element.js:831:22)
              at AppPage.getParagraphText (D:\Front\e2e\src\app.po.ts:9:47)
              at UserContext.<anonymous> (D:\Front\e2e\src\app.e2e-spec.ts:12:17)
              at new ManagedPromise (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1077:7)
              at ControlFlow.promise (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2505:12)
              at TaskQueue.execute_ (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
          From: Task: Run it("should display welcome message") in control flow
              at ControlFlow.emit (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\events.js:62:21)
              at ControlFlow.shutdown_ (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2674:10)
              at shutdownTask_.MicroTask (D:\Front\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2599:53)
          From asynchronous test:
          Error
              at Suite.<anonymous> (D:\Front\e2e\src\app.e2e-spec.ts:10:3)
              at Object.<anonymous> (D:\Front\e2e\src\app.e2e-spec.ts:3:1)
              at Module._compile (module.js:635:30)
              at Module.m._compile (D:\Front\node_modules\ts-node\src\index.ts:439:23)
              at Module._extensions..js (module.js:646:10)
              at Object.require.extensions.(anonymous function) [as .ts] (D:\Front\node_modules\ts-node\src\index.ts:442:12)

    **************************************************
    *                    Failures                    *
    **************************************************

    1) workspace-project App should display welcome message
      - Failed: No element found using locator: By(css selector, app-root h1)

    Executed 1 of 1 spec (1 FAILED) in 6 secs.
    [16:19:07] I/launcher - 0 instance(s) of WebDriver still running
    [16:19:24] I/launcher - chrome #01 failed 1 test(s)
    [16:19:24] I/launcher - overall: 1 failed spec(s)
    [16:19:24] E/launcher - Process exited with error code 1
    An unexpected error occurred: undefined

并且在我的 app.po.ts 中,他不知道量角器的导入方式:

import { browser, by, element } from 'protractor';

export class AppPage {
    navigateTo() {
        return browser.get('/');
    } 

    getParagraphText() {
        return element(by.css('app-root h1')).getText();
    }
}

这是我的 app.e2e-spec.ts (他不知道描述每个人,并且期望):

import { AppPage } from './app.po';

describe('workspace-project App', () => {
  let page: AppPage;

  beforeEach(() => {
    page = new AppPage();
  });

  it('should display welcome message', () => {
    page.navigateTo();
    expect(page.getParagraphText()).toEqual('Welcome to MyProject!');
  });
});

之后,我在全局量角器中停滞,并执行了 webdriver-manager更新 webdriver-manager start ,第一个告诉我:

PS D:\Front> webdriver-manager update
[16:39:31] I/update - chromedriver: file exists C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\chromedriver_2.43.zip
[16:39:31] I/update - chromedriver: unzipping chromedriver_2.43.zip
[16:39:31] I/update - chromedriver: chromedriver_2.43.exe up to date
[16:39:31] I/update - selenium standalone: file exists C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\selenium-server-standalone-3.141.59.jar
[16:39:31] I/update - selenium standalone: selenium-server-standalone-3.141.59.jar up to date
[16:39:32] I/update - geckodriver: file exists C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\geckodriver-v0.23.0.zip
[16:39:32] I/update - geckodriver: unzipping geckodriver-v0.23.0.zip
[16:39:32] I/update - geckodriver: geckodriver-v0.23.0.exe up to date

webdriver-manager start 给我:

PS D:\Front> webdriver-manager start
[16:41:03] I/start - java -Dwebdriver.chrome.driver=C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\chromedriver_2.43.exe -Dwebdriver.gecko.driver=C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\geckodriver-v0.23.0.exe -jar C:\Users\user\AppData\Roaming\npm\node_modules\protractor\node_modules\webdriver-manager\selenium\selenium-server-standalone-3.141.59.jar -port 4444
[16:41:03] I/start - seleniumProcess.pid: 18444
'java' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
[16:41:03] I/start - Selenium Standalone has exited with code 1

有关我的项目版本的更多信息:

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.0.3
Node: 8.9.1
OS: win32 x64
Angular: 7.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.3
@angular-devkit/build-angular     0.10.3
@angular-devkit/build-optimizer   0.10.3
@angular-devkit/build-webpack     0.10.3
@angular-devkit/core              7.0.3
@angular-devkit/schematics        7.0.3
@angular/cli                      7.0.3
@ngtools/webpack                  7.0.3
@schematics/angular               7.0.3
@schematics/update                0.10.3
rxjs                              6.3.3
typescript                        3.1.4
webpack                           4.19.1

这是我的 package.json

{
  "name": "artemis",
  "version": "0.0.1",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --watch",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "rebuild-sass": "npm rebuild node-sass",
    "postinstall": "rimraf node_modules/**/web.config"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "7.0.1",
    "@angular/common": "7.0.1",
    "@angular/compiler": "7.0.1",
    "@angular/core": "7.0.1",
    "@angular/forms": "7.0.1",
    "@angular/http": "7.0.1",
    "@angular/platform-browser": "7.0.1",
    "@angular/platform-browser-dynamic": "7.0.1",
    "@angular/router": "7.0.1",
    "@ngx-translate/core": "^11.0.0",
    "@progress/kendo-angular-dateinputs": "^3.5.1",
    "@progress/kendo-angular-intl": "^1.6.0",
    "@progress/kendo-angular-l10n": "^1.3.0",
    "core-js": "^2.4.1",
    "jquery": "^3.3.1",
    "ngx-progressbar": "^2.1.1",
    "ngx-spinner": "^6.1.2",
    "ngx-toastr": "^9.1.1",
    "node-sass": "^4.9.4",
    "rimraf": "^2.6.2",
    "rxjs-compat": "^6.3.3",
    "selenium-webdriver": "^4.0.0-alpha.1",
    "slick-carousel": "^1.8.1",
    "systemjs": "^2.0.2",
    "zone.js": "^0.8.26",
    "protractor": "^5.4.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.10.0",
    "@angular/cli": "^7.0.3",
    "@angular/compiler-cli": "^7.0.1",
    "@angular/language-service": "^7.0.1",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^10.12.1",
    "ajv": "^6.0.0",
    "codelyzer": "^4.0.1",
    "del": "^3.0.0",
    "jasmine": "^3.0.0",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "2.0.4",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^1.4.0",
    "karma-typescript": "^3.0.13",
    "karma-webpack": "3.0.5",
    "protractor": "^5.4.1",
    "ts-node": "~7.0.1",
    "tslint": "~5.11.0",
    "typescript": "^3.1.4"
  }
}

如果有人需要更多信息,请告诉我。

很多东西!

0 个答案:

没有答案