【问题标题】:cucumber stepdefinition file is not recognized by the protractor cucumber config file量角器黄瓜配置文件无法识别黄瓜 stepdefinition 文件
【发布时间】:2019-09-05 06:19:44
【问题描述】:

无法执行步骤定义文件中的步骤

我尝试了谷歌提供的解决方案,但没有一个能回答我的问题。

我的配置文件

  //seleniumAddress: 'http://localhost:4444/wd/hub',
  directConnect: true,
  //specs: ['/Users/bharaniravisankar/Desktop/PRO/SPECS/TEST.JS'],
  framework: 'custom',
  // path relative to the current config file
  frameworkPath: require.resolve('protractor-cucumber-framework'),
  capabilities: {
    'browserName': 'chrome'
  },
  specs: [
    '/Users/bharaniravisankar/Desktop/PRO/Feature/test.feature'
  ],

  cucumberOpts: {
    require: '/Users/bharaniravisankar/Desktop/PRO/Feature/Step Definition/login.js',
    //tags: false,
    //format: 'pretty',
    profile: false,
    'no-source': true
  }

};

我的控制台日志

? Given User navigate to Home Page
       Undefined. Implement with the following snippet:

         Given('User navigate to Home Page', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   ? When User enter email and other details
       Undefined. Implement with the following snippet:

         When('User enter email and other details', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   ? And click on Submit button
       Undefined. Implement with the following snippet:

         When('click on Submit button', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   ? Then Login is created sucessfully
       Undefined. Implement with the following snippet:

         Then('Login is created sucessfully', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   ✔ After # CONG.js/node_modules/protractor-cucumber-framework/lib/resultsCapturer.js:26

1 scenario (1 undefined)
4 steps (4 undefined)

步骤定义文件

var { Given, When, Then } = require("cucumber");

module.exports = function () {

    this.Given(/^User navigate to Home Page$/, async function () {
     // this.When('User enter email and other details', function () {

        //launch AWS portal
        browser.get('https://portal.aws.amazon.com/billing/signup#/start');

        //Maximize the browser window
        browser.driver.manage().window().maximize();

        //Check the title of the Webpage
       expect(await browser.getTitle()).toEqual('AWS Console - Signup');


      });

      this.When(/^User enter email and other details$/, function () {
      //  this.When('User enter email and other details', function () {

        element(by.model('credentials.email')).sendKeys('bharaniravi36@gmail.com')
        element(by.model('credentials.password')).sendKeys('Feb%1992');
        element(by.model('credentials.rePassword')).sendKeys('Feb%1992');
        element(by.model('credentials.fullName')).sendKeys('bharaniravi85');

      });



      //this.When('click on Submit button', function () {

        this.When(/^click on Submit button$/, function () {

        element(by.xpath("(//input[@class='a-button-input'])[1]")).click();
      });

      this.Then(/^Login is created sucessfully$/, function () {

        expect(browser.getTitle()).toEqual('AWS Console - Signup');
        element(by.id('company')).sendKeys('POLI');

        //click on country drop down
        element(by.model("address.countryCode")).click();
        element(by.xpath("//option[@label='American Samoa']")).click();
              // add sleep to give a time for te options to reveal
              browser.sleep(3000)
      });
  };

在我的研究中,我没有错过我的设置中的任何内容,并且所有内容都在我的系统中设置并下载了所需的依赖项。

【问题讨论】:

  • 你知道你用的黄瓜是什么版本的吗?

标签: protractor cucumber cucumberjs


【解决方案1】:

首先尝试在功能文件夹之外创建步骤定义文件夹以保持功能和步骤定义的分离,并且文件夹名称应该没有空格,例如“stepdefinition”。

其次,确保所有功能步骤都应在步骤定义文件中实现,并且每个步骤的文本应与功能中提到的相同。

尝试使用它,如果它适合你,请告诉我。

【讨论】:

  • 仍然面临同样的问题
  • 更新了步骤定义文件..你可以刷新它并检查问题描述
  • this.Given(/^User navigate to Home Page$/, async function () - 确保从步骤中删除字符并以这种方式编写 this.Given(User navigate to Home Page , async function() 再试试
  • 如果我使用这样的语句给定(用户导航到主页,异步函数()。它抛出错误代码为 12:55:36] I/launcher - 运行 1 个 WebDriver 实例[12:55:36] I/direct - 直接使用 ChromeDriver... [12:55:40] E/launcher - 错误:/Users/bharaniravisankar/Desktop/PRO/stepdefinition/login.js:5 this.Given(用户导航到主页,函数 () { ^^^^ SyntaxError: missing ) 在参数列表之后
  • 我已经尝试了整段代码,它正在我的最后工作,可能存在某种配置问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-01
  • 1970-01-01
  • 2016-06-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多