我创建了一个angular2项目,没有使用angular cli。但是,当我在运行delegator.conf.js时使用delegator时,它抛出了一个错误,从“delegator”导入了意外的标记(browser,element,by)。
我正在使用测试用例的类型脚本。
以下是app.po.ts的代码

import { browser, element, by, protractor } from 'protractor';
export class MainPage {
   navigateTo() {
    return browser.get('/');
  }

  getTitle() {
    return browser.getTitle();
  }

  getDasboardTitle() {
    return element(by.css('.al-title')).getText();
  }
}

下面是app.ts的代码
import { MainPage } from './app.po';
describe('demo-project App', function() {
  let page: MainPage ;

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

  it('Application should have a title', () => {
    page.navigateTo();
    expect(page.getTitle()).toEqual('Operator - Flight Operation Management');
  });

   it('Dasbord should have a heading', function() {
    expect(page.getTitle()).toEqual('DASHBOARD');
  });
});

下面是运行量角器时的错误
[11:45:08] E/launcher - Error: c:\Angular2\ui\src\protractor\app.ts:1 (function (exports, require, module, __filename, __dirname) { import { OperatorMainPage } from './app.po';
                                                              ^^^^^^ SyntaxError: Unexpected token import
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at C:\Node\npm\node_modules\protractor\node_modules\jasmine\lib\jasmine.js:71:5
    at Array.forEach (native) [11:45:08] E/launcher - Process exited with error code 100

最佳答案

您正在导入MainPage,但正在调用OperatorMainPageOperatorMainPage类型不存在。

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

describe('demo-project App', function() {
  let page: MainPage;

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

  it('Application should have a title', () => {
    page.navigateTo();
    expect(page.getTitle()).toEqual('Operator - Flight Operation Management');
  });

   it('Dashbaord should have a heading', function() {
    expect(page.getTitle()).toEqual('DASHBOARD');
  });
});

07-24 21:15