尝试使用serenity-js时出错:如果没有“ new”,则无法调用类构造函数Cli

时间:2019-04-17 14:47:33

标签: protractor serenity-bdd cucumber-serenity serenity-js

我正在尝试在量角器测试中实施BDD方法。到目前为止,这是一个非常简单的设置。我可以使用``来运行示例测试,但是当我按照here步骤尝试使用serenity-js时,出现以下错误-

DevTools listening on ws://127.0.0.1:56872/devtools/browser/bf7318c0-b0a4-4dea-8
ae4-e197dbda68f7
Class constructor Cli cannot be invoked without 'new'
[20:09:31] I/launcher - 0 instance(s) of WebDriver still running
[20:09:31] I/launcher - chrome #01 failed 1 test(s)
[20:09:31] I/launcher - overall: 1 failed spec(s)
[20:09:31] E/launcher - Process exited with error code 1
An unexpected error occurred: undefined

看着它,我无法弄清楚是什么原因导致此错误,以及我在做什么错了。

以下是我的protractor.js文件-

exports.config = {

  allScriptsTimeout: 11000,
  specs: [
    './src/features/**/*.feature'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200',
  framework: 'custom',
  // frameworkPath: require.resolve('protractor-cucumber-framework'),
  frameworkPath: require.resolve('serenity-js'),
  cucumberOpts: {
    require: ['./src/steps/**/*.steps.ts'],
    // format: 'pretty',               // enable console output
    compiler: 'ts:ts-node/register'   // interpret step definitions as TypeScript
  },
  serenity: {
    dialect: 'cucumber'
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
  }
};

下面是我的目录结构-

enter image description here

以下是我的app.feature文件-

Feature: Go to the home
  Display the title

  Scenario: Home Page
    Given I am on the home page
    When I do nothing
    Then I should see the title

以下是app.po-

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

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

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

以下是app.steps.ts

import { Before, Given, Then, When } from 'cucumber';
import { expect } from 'chai';

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

let page;

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

Given(/^I am on the home page$/, async () => {
  await page.navigateTo();
});

When(/^I do nothing$/, () => {});

Then(/^I should see the title$/, async () => {
  expect(await page.getTitleText()).to.equal('Welcome to poc-serenity!');
});

0 个答案:

没有答案