我正在使用Node 6.4.1和esversion6。
我正在尝试从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');
});
});
答案 0 :(得分:1)
我承认我对webstorm不熟悉,但我认为没有理由为什么您需要在规范文件中导入这些文件。量角器应在自动启动时设置这些变量。我可能错过了一些东西,但是您可以尝试删除它们,然后查看您的项目是否在运行。
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";