我配置了黄瓜+量角器,我首先将stepDefinitions拆分成不同的文件,如下所示:
当我创建新的功能文件并开始运行时,黄瓜/量角器没有识别出我正在添加到其他文件的这些新步骤。所以我决定将所有新步骤移到同一个文件中。
但是当我跑步的时候,虽然写得很好(检查并比较了数千次),但我收到了这个错误:
[launcher] Error: /Users/brunosoko/Documents/Dev/Personal/test2/features/step_definitions/homepage/homepage.js:30
this.When(/^I select an image
or video$/, function (done) {
^
SyntaxError: Invalid regular expression: missing /
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at /Users/brunosoko/Documents/Dev/Personal/test2/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:63:29
at Array.forEach (native)
at Object.wrapper (/Users/brunosoko/Documents/Dev/Personal/olapic-test2/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:62:15)
我正在运行量角器和黄瓜的以下版本:
"devDependencies": {
"chai": "*",
"chai-as-promised": "^5.1.0",
"cucumber": "~0.6.0",
"protractor": "1.4.0",
"protractor-cucumber-junit": "latest",
"protractor-html-screenshot-reporter": "^0.0.21",
"selenium-webdriver": "2.47.0" },
这些是我的stepDefinition:
```
/*Given*/
this.Given(/^I am at the homepage$/, function (done) {
browser.get('').then(function(){
CarouselPage.clickOutSidePopUp();
done();
});
});
this.Given(/^I can see that images and videos are present on the widget$/
, function (done) {
expect(CarouselPage.checkMediaSource()).to.eventually.be.true;
done();
});
this.When(/^I select an image
or video$/, function (done) {
CarouselPage.getMedia(1).click();
done();
});
/*Then*/
this.Then(/^I see that Carousel Widget is correctly displayed$/, function(done){
expect(CarouselPage.carouselContainer.isPresent()).to.eventually.be.true;
done();
});
this.Then(/^I see the viewer modal
$/, function(done){
expect(ViewerModal.viewerContainer.isPresent()).to.eventually.be.true;
done();
});
this.Then(/^I see the Gallery widget
$/, function(done){
expect(CarouselPage.carouselContainer.isPresent()).to.eventually.be.true;
done();
}); ```
那么,我做错了什么?我需要清除一些缓存吗?这是我正在使用的版本的错误吗?
谢谢!
注:的 同样引起我注意的是,如果我甚至评论整个步骤,我会在控制台上看到这个
./node_modules/protractor/bin/protractor conf.js
util.puts: Use console.log instead
Starting selenium standalone server...
util.puts: Use console.log instead
Selenium standalone server started at http://192.168.0.101:58696/wd/hub
[launcher] Error: /Users/brunosoko/Documents/Dev/Personal/test2/features/step_definitions/homepage/stepsDefinitions.js:24
//this.When(/^I select an image
or video$/, function (done) {
^^^^^^
SyntaxError: Unexpected identifier
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at /Users/brunosoko/Documents/Dev/Personal/test2/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:63:29
at Array.forEach (native)
at Object.wrapper (/Users/brunosoko/Documents/Dev/Personal/test2/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:62:15)
编辑2:
这是我的conf.js
文件,以防你在这里看到我做错了什么
exports.config = {
specs: [
'features/*.feature'
],
baseUrl: "http://www.page.com",
multiCapabilities: [
{
'browserName': 'chrome'
}
],
framework: 'cucumber',
//seleniumAddress: 'http://localhost:4444/wd/hub',
cucumberOpts: {
require: 'features/step_definitions/**/*.js',
format: 'pretty'
},
resultJsonOutputFile: 'report.json',
onPrepare: function () {
browser.driver.manage().window().maximize();
browser.ignoreSynchronization = true;
browser.manage().timeouts().implicitlyWait(20000);
browser.getCapabilities().then(function (cap) {
browserName = cap.caps_.browserName;
});
}
};