Cannot add new Given/When/Then, getting error `SyntaxError: Invalid regular expression: missing /`

Cannot add new Given/When/Then, getting error `SyntaxError: Invalid regular expression: missing /`

我配置了 Cucumber + 量角器,我首先将 stepDefinitions 拆分成不同的文件,如下所示:

当我创建新功能文件并启动 运行ning 时,cucumber/protractor 无法识别我添加到其他文件的这些新步骤。所以我决定将所有新步骤移动到同一个文件中。

但是当我运行时,虽然它们写得很好(检查并比较了数千次)我得到这个错误:

    [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"   },

这些是我的步骤定义:

```
    /*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;
        });

    }
};

image 之后的第一个字符是 unicode line separator。删除它,节点将能够解析正则表达式。