a p
a p

Reputation: 1271

SyntaxError: Unexpected token { - Error while running protractor cucumber test

I am just trying to start with Protractor- Cucumber test setup and following is my basic setup that I did following some tutorials online. Thanks to the Samaritan who shared that.

The problem is that when I try to run it, I get the error - unexpected token for the imports. I have no clue as why its giving that. Any help is much appreciated.

Following are the versions of node etc I am using -

C:\Users\A>npm --version
6.4.1

C:\Users\A>node --version
v10.15.1

C:\Users\A>protractor --version
Version 5.4.2

Following is my feature file -

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

Following is my steps definition file -

import { AppPage } from '../pages/app.po';
import { Before, Given, When, Then } from 'cucumber';
import { expect } from 'chai';

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('Welcome to angular-cli-cucumber-demo!');
});

Following is my page objects file -

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

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

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

I am getting below error when I try running tests using command ng e2e -

DevTools listening on ws://127.0.0.1:56273/devtools/browser/7653bd59-c490-4ac0-a00e-0d3132dc5b11
[0417/123615.432:ERROR:broker_win.cc(137)] Error sending sync broker message: Error (0x5) while retrieving error. (0xE8)
[0417/123615.433:ERROR:command_buffer_proxy_impl.cc(92)] ContextResult::kFatalFailure: AllocateAndMapSharedMemory failed
[12:36:17] E/launcher - Error: C:\Users\A527629\Documents\workspace-vs-code\poc-serenity\e2e\src\steps\app.steps.ts:1
(function (exports, require, module, __filename, __dirname) { import { AppPage } from '../pages/app.po';
                                                                     ^

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 (C:\Users\A527629\Documents\workspace-vs-code\poc-serenity\node_modules\cucumber\lib\cli\index.js:142:42)
    at Array.forEach (<anonymous>)
    at Cli.getSupportCodeLibrary (C:\Users\A527629\Documents\workspace-vs-code\poc-serenity\node_modules\cucumber\lib\cli\index.js:142:22)
    at C:\Users\A527629\Documents\workspace-vs-code\poc-serenity\node_modules\cucumber\lib\cli\index.js:169:41
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\A527629\Documents\workspace-vs-code\poc-serenity\node_modules\cucumber\lib\cli\index.js:44:103)
[12:36:17] E/launcher - Process exited with error code 100
An unexpected error occurred: undefined

Upvotes: 1

Views: 2147

Answers (2)

Alexander
Alexander

Reputation: 160

Add following section to your protractor.conf.js

onPrepare() {
  require('ts-node').register({
    project: require('path').join(__dirname, './tsconfig.json')
  });
}

Upvotes: 1

DublinDev
DublinDev

Reputation: 2348

Try removing

steps definition

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

and page objects

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

These imports should be completed by protractor automatically when it initializes.

Upvotes: 0

Related Questions