无法添加新的Given/When/Then,出现错误`SyntaxError:无效的正则表达式:缺少/` [英] Cannot add new Given/When/Then, getting error `SyntaxError: Invalid regular expression: missing /`

查看:164
本文介绍了无法添加新的Given/When/Then,出现错误`SyntaxError:无效的正则表达式:缺少/`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置了黄瓜+量角器,首先我将stepDefinitions分割成这样的不同文件:

I had configured cucumber + protractor, and I firstly was splitting stepDefinitions into different files like this:

当我创建新功能文件并开始运行时,黄瓜/量角器无法识别我要添加到其他文件中的这些新步骤.因此,我决定将所有新步骤都移到同一文件中.

When I created new features files, and started running, cucumber/protractor did not recognized these new steps I was adding to the other files. So I decided to move all the new steps into the same file.

但是当我跑步时,尽管它们写得很好(经过数千次检查和比较),但我还是收到此错误:

But when I run, although they are well written (checked and compared thousands of times) I getting this error:

    [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)

我有以下版本的量角器和黄瓜版本:

I've the following versions running of protractor and cucumber:

  "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:

These are my 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();
    }); ```

那么,我在做什么错?我需要清除一些缓存吗?这与我使用的版本有关吗?

So, what am I doing wrong? Do I need to clear some cache? is this a bug with the versions I am using?

谢谢!

注意: 还引起我注意的是,即使我注释了整个步骤,也可以在控制台上看到

NOTE: What also called my attention is that if I even comment the whole step, I see this on the console

./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)

这是我的conf.js文件,以防万一您在这里也发现我做错了事情

EDIT 2: Here's my conf.js file, in case you see I'm doing wrong something here as well

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之后的第一个字符是

That first character after image is a unicode line separator. Delete that and node will be able to parse the regular expression.

这篇关于无法添加新的Given/When/Then,出现错误`SyntaxError:无效的正则表达式:缺少/`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆