我正在尝试使用Cucumber和chai创建Angular e2e测试。当我使用“ ng e2e”运行测试时,E /启动器遇到错误。
我曾尝试将文件与Internet上的指南/教程进行比较,但我是黄瓜新手,似乎找不到任何与此问题相关的参考。
protractor.conf.js
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
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'),
cucumberOpts: {
require: ['./src/steps/**/*.steps.ts'],
}
};
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.ts
import { browser, by, element } from 'protractor';
export class AppPage {
navigateTo() {
return browser.get(browser.baseUrl) as Promise<any>;
}
getTitleText() {
return element(by.css('app-root h1')).getText() as Promise<string>;
}
}
app.steps.ts
import { Before, Given, Then, When } from 'cucumber';
import { expect } from 'chai';
import { AppPage } from '../app.po';
let page: AppPage;
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('TopicCreationFrontEnd');
});
我期望它能够运行,但这是我得到的终端输出:
[11:07:51] E/launcher - Error: /Users/n0361431/Developments/Workspaces/Angular/topic-creation-front-end/e2e/src/steps/app.steps.ts:1
(function (exports, require, module, __filename, __dirname) { import { Before, Given, Then, When } from 'cucumber';
^
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at supportCodePaths.forEach.codePath (/Users/n0361431/Developments/Workspaces/Angular/topic-creation-front-end/node_modules/cucumber/lib/cli/index.js:142:42)
at Array.forEach (<anonymous>)
at Cli.getSupportCodeLibrary (/Users/n0361431/Developments/Workspaces/Angular/topic-creation-front-end/node_modules/cucumber/lib/cli/index.js:142:22)
at /Users/n0361431/Developments/Workspaces/Angular/topic-creation-front-end/node_modules/cucumber/lib/cli/index.js:169:41
at Generator.next (<anonymous>)
at asyncGeneratorStep (/Users/n0361431/Developments/Workspaces/Angular/topic-creation-front-end/node_modules/cucumber/lib/cli/index.js:44:103)
[11:07:51] E/launcher - Process exited with error code 100
答案 0 :(得分:0)
protractor.config.js中未提供用于TS的编译器 添加以下回调函数以启动。
arr[3][3]