E2E测试失败

时间:2016-11-18 14:53:29

标签: angular typescript protractor angular-cli

我正在尝试在Angular 2中设置一个示例应用程序,现在我正在尝试测试e2e测试部分。我对Angular 2使用的Jasmine框架或Protractor库知之甚少。

所以我不确定为什么我在运行ng e2e时遇到此错误(我正在使用Angular CLI)

我得到的错误:

[09:41:10] I/direct - Using ChromeDriver directly...
[09:41:10] I/launcher - Running 1 instances of WebDriver
[09:41:12] E/launcher - Error: TSError: ? Unable to compile TypeScript
e2e\app.e2e-spec.ts (16,4): Cannot find name 'browser'. (2304)
e2e\app.e2e-spec.ts (17,19): Cannot find name 'element'. (2304)
e2e\app.e2e-spec.ts (17,27): Cannot find name 'by'. (2304)
e2e\app.e2e-spec.ts (18,5): Supplied parameters do not match any signature of ca
ll target. (2346)

我的测试用例(app.e2e-spec.ts)

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

describe('web App', function() {
  let page: WebPage;

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

  it('should display message saying app works', () => {
    page.navigateTo();
    expect(page.getParagraphText()).toEqual('Hello World');
  });

  it('Has a greeting', function () {
    browser.get('/index.html');
    var greeting = element(by.id('h2Id'));
    expect().getText(greeting).toEqual('Hello, World!');
  });


});

Protrator.config.js

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js

/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  useAllAngular2AppRoots: true,
  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e'
    });
  },
  onPrepare: function() {
    jasmine.getEnv().addReporter(new SpecReporter());
  }
};

1 个答案:

答案 0 :(得分:0)

app.e2e-spec.ts:

expect()。getText(greeting).toEqual('Hello,World!');

=>  expect(greeting.getText()).toEqual('Hello, World!');