【发布时间】:2025-12-09 09:55:01
【问题描述】:
我正在尝试使用量角器示例制作非常简单的黄瓜,但在功能文件中出现错误,这是我的代码
protractor.conf.js 文件
var prefix = 'src/test/javascript/'.replace(/[^/]+/g,'..');
exports.config = {
seleniumServerJar: prefix + 'node_modules/protractor/selenium/selenium-server-standalone-2.52.0.jar',
chromeDriver: prefix + 'node_modules/protractor/selenium/chromedriver',
allScriptsTimeout: 20000,
frameworkPath: require.resolve('protractor-cucumber-framework'),
directConnect: true,
baseUrl: 'http://localhost:8099/',
cucumberOpts: {
require: 'step_definitions/stepDefinitions.js',
format: 'summary'
},
specs: [
'features/*.feature'
]
};
功能文件
Feature: Running Protractor and Cucumber
Scenario: Protractor and Cucumber Test
Given I go to home page
stepDefinition js文件
module.exports = function() {
this.Given(/^I go to home page$/, function(site, callback) {
browser.get(site)
.then(callback);
});
}
但是当我用 $ gulp protractor 运行时,我得到以下错误
[16:01:21] Using gulpfile ~/git/adap_gateway/gulpfile.js
[16:01:21] Starting 'protractor'...
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
[launcher] Error: /home/ali/git/adap_gateway/src/test/javascript/features
/attack.feature:1
(function (exports, require, module, __filename, __dirname) { Feature:
Running Protractor and Cucumber
^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /home/ali/git/adap_gateway/node_modules/jasmine/lib/jasmine.js:71:5
[launcher] Process exited with error code 100
[16:01:21] gulp-notify: [JHipster Gulp Build] Error: protractor exited
with code 100
[16:01:22] Finished 'protractor' after 936 ms
[16:01:22] E2E Tests failed
谁能帮我解决这个错误?
【问题讨论】:
-
此错误可能是由于您使用的是旧版本的节点和新版本的量角器。如果您使用的是最新的 protractor 5.1 版本,您的节点版本应至少为 v 6.9.x
-
节点版本为v6.10.2,量角器版本为5.1.1
-
您是否已经解决了这个问题,因为您还有一个关于 generating a report 的问题,假设您已经成功了,还是那些不相关?
标签: selenium protractor cucumber cucumberjs