获得意外标记{在import语句,同时从WebStorm运行量角器测试(Getting Unexpe

2019-10-29 15:21发布

我使用的节点6.4.1和esversion 6。

我试图从运行WebStorm量角器测试,但在运行时我收到以下错误。 浏览器是越来越调用成功,但随后停止。

Error:
    [20:15:29] I/launcher - Running 1 instances of WebDriver
    [20:15:29] I/hosted - Using the selenium server at           http://localhost:4444/wd/hub
    [20:15:33] E/launcher - Error: D:\Protractor-Final\e2e-tests\spec.js:3
    import {WebDriver as browser}  from "selenium-webdriver";
       ^

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)
[20:15:33] E/launcher - Process exited with error code 100

Process finished with exit code 4

Conf.js文件

"use strict";
exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js'],
  capabilities: {
  browserName: 'chrome'
  }
};

spec.js

"use strict";

import {WebDriver as browser}  from "selenium-webdriver";
import {By as by} from "selenium-webdriver";
import {beforeEach, describe, it} from "selenium-webdriver/testing";
import {element} from "protractor";


describe('Protractor Demo App', function() {
let firstNumber = element(by.model('first'));
let secondNumber = element(by.model('second'));
let goButton = element(by.id('gobutton'));
let latestResult = element(by.binding('latest'));

beforeEach(function() {
browser.get('http://juliemr.github.io/protractor-demo/');
});

it('should have a title', function() {
  expect(browser.getTitle()).toEqual('Super Calculator');
});

it('should add one and two', function() {
  firstNumber.sendKeys(1);
  secondNumber.sendKeys(2);

  goButton.click();

  expect(latestResult.getText()).toEqual('3');
 });

 it('should add four and six', function() {
  firstNumber.sendKeys(4);
  secondNumber.sendKeys(6);

  goButton.click();
  expect(latestResult.getText()).toEqual('10');
  });

 it('should read the value from an input', function() {
   firstNumber.sendKeys(1);
   expect(firstNumber.getAttribute('value')).toEqual('1');
  });
});

Answer 1:

我承认我不熟悉webstorm,但我看不出有什么理由你需要在你的spec文件的进口。 量角器应该设置这些变量时,它将自动启动。 这是可能的,我错过了一些东西,但你可以尝试删除它们,看,如果你的项目,然后运行。

import {WebDriver as browser}  from "selenium-webdriver";
import {By as by} from "selenium-webdriver";
import {beforeEach, describe, it} from "selenium-webdriver/testing";
import {element} from "protractor";


文章来源: Getting Unexpected token { at the import statement while running protractor tests from WebStorm