量角器Angular 4 E2E意外令牌导入

时间:2018-08-03 17:34:56

标签: javascript angular typescript jasmine protractor

经过几天和无处不在的线程之后,我似乎无法运行我的e2e测试。似乎是从TS到JS都有编译问题,或者量角器库没有加载。当我运行下面的代码时,我收到以下消息:

  

[13:18:39] E /启动器-错误:   /Users/shawncasey/doctor_web_portal/e2e/e2e.spec.ts:23 import {   E2eTest}来自“ ./e2e.page”; ^^^^^^

     

SyntaxError:意外的令牌导入       在createScript(vm.js:80:10)       在Object.runInThisContext(vm.js:139:10)       在Module._compile(module.js:616:28)       在Object.Module._extensions..js(module.js:663:10)       在Module.load(module.js:565:32)       在tryModuleLoad(module.js:505:12)       在Function.Module._load(module.js:497:3)       在Module.require(module.js:596:17)       在要求时(internal / module.js:11:18)       在/Users/shawncasey/doctor_web_portal/node_modules/protractor/node_modules/jasmine/lib/jasmine.js:93:5       在Array.forEach()       在Jasmine.loadSpecs(/Users/shawncasey/doctor_web_portal/node_modules/protractor/node_modules/jasmine/lib/jasmine.js:92:18)       在Jasmine.execute(/Users/shawncasey/doctor_web_portal/node_modules/protractor/node_modules/jasmine/lib/jasmine.js:197:8)       在/Users/shawncasey/doctor_web_portal/node_modules/protractor/built/frameworks/jasmine.js:132:15       在Function.promise(/Users/shawncasey/doctor_web_portal/node_modules/protractor/node_modules/q/q.js:682:9)       在/Users/shawncasey/doctor_web_portal/node_modules/protractor/built/frameworks/jasmine.js:104:14 [13:18:39] E / launcher-进程退出,错误代码为100

如果我将import {element, by, browser} from 'protractor';更改为const by = require('protractor');,则会收到消息by.css is not a function

这里已经有一篇文章:SyntaxError: Unexpected token import when trying to import protractor in e2e test for angular,但是我不确定要移植我的ts。我以为已经解决了。如果不是,该怎么办?

以下是相关代码: 页面对象:

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

export class E2eTest {

    getUsernameBox() {
        return element(by.id('exampleInputEmail1'));
    }
    getPasswordBox () { 
        return element(by.id('exampleInputPassword1'));
    }
    getLoginButton() {
        return element(by.class('.btn-success'));
    }

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

}

测试套件:

import { E2eTest } from './e2e.page';

describe ('Doc Portal App', () => {
    let page: E2eTest;

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

    it ('Should log in to portal', () => {
        page.getUsernameBox().sendKeys('#####');
        page.getPasswordBox().sendKeys('#####');
        page.getLoginButton().click();
    });
});

运行茉莉花3.1.0,量角器5.4.0,打字稿2.9.2。我的protractor.conf.js看起来不错,但这是我的tsconfig.app.json:

{
  "compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2016",
      "dom"
    ],
    "outDir": "../out-tsc/app",
    "target": "es6",
    "module": "es2016",
    "baseUrl": ""
  },
  "exclude": [ ]
}

预先感谢

0 个答案:

没有答案