编写步骤定义时出现问题 - JavaScript 上的 Cucumber 和 Appium

Problem in writing step definitions - Cucumber & Appium on JavaScript

我正在从事一个更像是概念验证的项目。实际上对我来说是一个 POC,因为我确信它以前已经完成了。

我正在尝试使用 Cucumber.js、Appium 服务器/客户端、Node 和 Javascript 编写 Visual Studio 代码。

一些背景知识。我是 Javascript 的新手,但对 BDD / Cucumber 和 Appium 自动化测试并不完全陌生。

我刚开始这个项目就遇到了障碍,我不明白哪里出了问题,也不知道从哪里开始。搜索互联网并没有让我找到任何地方 - 可能没有在正确的地方使用正确的关键字搜索。

让我解释一下。我在 Visual Studio 代码中的工作区内创建了功能文件,如下

 Feature: Change Font Size

  Scenario: Set Font Size to Default
    Given that I am on Font Size option
    When I click the default option
    Then The font size should be set to default

  Scenario: Set Font Size to Small
    Given that I am on Font Size option
    When I click the small option
    Then The font size should be set to small

我已经使用以下命令生成了胶水代码

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Projects\VisualStudioCode\CucumberAppium> node_modules/.bin/cucumber-js

一切都很好,因为这会生成我添加到我的 js 文件中的粘合代码/步骤定义。我的 js 文件如下所示。这是在 运行 执行 cucumber-js 命令(如上所述)

后按原样提取的
const {Given,When,Then} = require('cucumber');

Given('that I am on Font Size option', function () {
    // Write code here that turns the phrase above into concrete actions
    return 'pending';
});

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

Then('The font size should be set to default', function () {
    // Write code here that turns the phrase above into concrete actions
    return 'pending';
});

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

Then('The font size should be set to small', function () {
    // Write code here that turns the phrase above into concrete actions
    return 'pending';
});

我还没有添加任何代码,但是当我 运行 这个 运行->运行 没有调试 然后非常至少我期望发生的是什么——因为没有代码。

但是我收到一个错误(如下所述)

C:\Program Files (x86)\nodejs\node.exe features\steps.js\
internal/validators.js:118
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received undefined
    at validateString (internal/validators.js:118:11)
    at Object.relative (path.js:437:5)
    at getDefinitionLineAndUri (c:\Projects\VisualStudioCode\CucumberAppium\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:184:27)
    at buildStepDefinitionConfig (c:\Projects\VisualStudioCode\CucumberAppium\node_modules\cucumber\lib\support_code_library_builder\build_helpers.js:124:7)
    at SupportCodeLibraryBuilder.defineStep (c:\Projects\VisualStudioCode\CucumberAppium\node_modules\cucumber\lib\support_code_library_builder\index.js:51:79)
    at Object.<anonymous> (c:\Projects\VisualStudioCode\CucumberAppium\features\steps.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_INVALID_ARG_TYPE',
  [Symbol(originalCallSite)]: [
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {}
  ],
  [Symbol(mutatedCallSite)]: [
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {}
  ]
}

我知道我可能忽略了一些事情。

如果有人能指出正确的方向,我将不胜感激。

My package.json is as follows
{
  "name": "cucumberappium",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "cucumber": "^6.0.5",
    "selenium-webdriver": "^4.0.0-alpha.7"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

谢谢!

您应该让 Cucumber Runner 知道步骤定义文件的位置。您可以使用 nightwatchjs here 找到一个实现良好的 cucumberjs 项目。这可能有太多细节,但它可以帮助您理解。