为什么量角器黄瓜无法在量角器黄瓜框架中找到带有最新版本的黄瓜的步骤文件

时间:2020-08-01 09:36:21

标签: protractor cucumber cucumberjs

我正在使用量角器黄瓜框架,因为从很长时间以来,我一直观察到黄瓜无法在项目中找到规格文件。我使用的是黄瓜最新版本6.0.3,无法找到规格文件,但我使用黄瓜1.3.3运行的代码相同。有人可以告诉我此版本有什么区别吗?我需要为6.0.3更新什么吗

黄瓜依赖性-1.3.3

"cucumber": {
      "version": "1.3.3",
      "resolved": "https://registry.npmjs.org/cucumber/-/cucumber-1.3.3.tgz",
      "integrity": "sha1-Za+2Xy+T9y2teN8qterPFGCf7C8=",
      "requires": {
        "camel-case": "^3.0.0",
        "cli-table": "^0.3.1",
        "co": "^4.6.0",
        "colors": "^1.1.2",
        "commander": "^2.9.0",
        "duration": "^0.2.0",
        "figures": "1.7.0",
        "gherkin": "^4.1.0",
        "glob": "^7.0.0",
        "is-generator": "^1.0.2",
        "lodash": "^4.0.0",
        "stack-chain": "^1.3.5",
        "stacktrace-js": "^1.3.0"
      }

黄瓜依赖性6.0.3最新


"cucumber": {
      "version": "6.0.3",
      "resolved": "https://registry.npmjs.org/cucumber/-/cucumber-6.0.3.tgz",
      "integrity": "sha512-FSx7xdAQfFjcxp/iRBAuCFSXp2iJP1tF2Q5k/a67YgHiYbnwsD9F+UNv9ZG90LFHNsNQhb+67AmVxHkp4JRDpg==",
      "dev": true,
      "requires": {
        "assertion-error-formatter": "^3.0.0",
        "bluebird": "^3.4.1",
        "cli-table3": "^0.5.1",
        "colors": "^1.1.2",
        "commander": "^3.0.1",
        "cucumber-expressions": "^8.0.1",
        "cucumber-tag-expressions": "^2.0.2",
        "duration": "^0.2.1",
        "escape-string-regexp": "^2.0.0",
        "figures": "^3.0.0",
        "gherkin": "5.0.0",
        "glob": "^7.1.3",
        "indent-string": "^4.0.0",
        "is-generator": "^1.0.2",
        "is-stream": "^2.0.0",
        "knuth-shuffle-seeded": "^1.0.6",
        "lodash": "^4.17.14",
        "mz": "^2.4.0",
        "progress": "^2.0.0",
        "resolve": "^1.3.3",
        "serialize-error": "^4.1.0",
        "stack-chain": "^2.0.0",
        "stacktrace-js": "^2.0.0",
        "string-argv": "^0.3.0",
        "title-case": "^2.1.1",
        "util-arity": "^1.0.2",
        "verror": "^1.9.0"
      }

StepDef

module.exports=function(){
    this.Given(/^Open the browser and Load the URL$/,async function(){
        await firstBrowser.get(properties.get("url1"));
        browser.logger.info("Title of the window is :"+await browser.getTitle());
        //screenshots.takesScreenshot("filename");
    });
    
    this.When(/^User entered the text in the search box$/,async function(){
        firstBrowser.sleep(3000);
        await page1.email().sendKeys(testData.Login.CM[0].Username);
        browser.sleep(3000);
        await page1.password().sendKeys(testData.Login.CM[0].Password);
    });
}

配置文件

exports.config = {

//seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
directConnect:true,

framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
    'browserName': 'chrome'
},
ignoreUncaughtExceptions:true,
// Spec patterns are relative to this directory.
specs: [
    'H:\\workspace\\Protractor_Cucumber\\src\\FeatureFiles\\Test.feature'
],

cucumberOpts: {
    require: 'H:\\workspace\\Protractor_Cucumber\\src\\StepDefFiles\\*.js',
    tags: false,
    profile: false,
    'no-source': true
},
 onPrepare: function () {
     browser.waitForAngularEnabled(false);
const {Given, Then, When, Before} = require('cucumber');

  }
};

我在测试脚本中没有使用任何黄瓜钩子。 是什么让他们的工作与众不同,对此可以有所帮助吗?

1 个答案:

答案 0 :(得分:0)

一个原因是Then/When/Given 6.x中的cucumber使用情况发生了变化,您可以更改几步功能来验证这一点。

对于1.x步进功能文件来说

module.exports = function () {

  this.Then(/^Then the response status is (.*)$/, function (status) {
    assert.equal(this.responseStatus, status)
  });
  this.When(//, ...)
}

对于6.x步进功能文件来说,

const { Then, When } = require('cucumber');

Then(/^the response status is (.*)$/, function (status) {
  assert.equal(this.responseStatus, status)
});

When(//,...)

另一个可能的原因是需要升级protractor-cucumber-framework兼容的cucumber@6.x版本