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

问题描述 投票:0回答:1

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

我正在尝试在Visual Studio Code上使用Cucumber.js,Appium服务器/客户端,节点和Javascript。

有点背景。我是Java语言的新手,但对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';
});

我还没有添加任何代码,但是当我运行此Run->无需调试运行时,我期望发生的至少是什么-因为没有代码。

但是我遇到了错误(如下所述)

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

谢谢!

javascript node.js cucumber appium cucumberjs
1个回答
1
投票

您应该让黄瓜赛跑者知道步骤定义文件的位置。您可以使用nightwatchjs here找到一个实施良好的Cucumberjs项目。这可能有太多细节,但可以帮助您理解。

© www.soinside.com 2019 - 2024. All rights reserved.