剧作家-黄瓜- Javascript:如何通过NPX命令运行特性



你好:我想通过npx命令运行Cucumber的功能,但是我不能。

这是我使用的命令:npx playwright tests:chrome --grep @POC 这里是剧作家配置文件:
const config = { 
timeout: 3000,
actionTimeout: 1500,
//workers: 2, //for parallel testing
retries: 2,
testDir: 'features/**/*.feature', 
use: {
headless: false, //true
viewport: { width: 1920, height: 1080 }, //1280x720
launchOptions: {
slowMo: 1000,
},
video:"off",
screenshot: 'only-on-failure',
},
projects: [
{
name: 'Chromium',
use: { browserName: 'chromium'},
},
{
name: 'Firefox',
use: { browserName: 'firefox'},
},
{
name: 'Webkit',
use: { browserName: 'webkit'},
},
],
};
module.exports = config;

这是我的package.json文件:

{
"name": "automation-testing",
"version": "1.0.0",
"description": "Testing Automation Framework with Playwright and CucumberJs.",
"main": "config.js",
"scripts": {
"tests:chrome": "playwright test --config=playwright.config.js --project=Chromium",
"tests:firefox": "playwright test --config=playwright.config.js --project=Firefox",
"tests:webkit": "playwright test --config=playwright.config.js --project=Webkit",
"tests:cucumber": "./node_modules/.bin/cucumber-js --require cucumber.js --require step-definitions/**/*.js --require features/**/*.js -f json:cucumber_report.json",
"report": "node reporter.js"
},
"author": "NN",
"license": "ISC",
"homepage": "https://bitbucket.org/maritzmotivation/rpp-automation-testing#readme",
"dependencies": {
"@cucumber/cucumber": "^8.8.0",
"@playwright/test": "^1.27.1",
"chai": "^4.3.7",
"cucumber-html-reporter": "^5.5.0",
"playwright": "^1.27.1",
"prettier": "^2.8.0"
},
"devDependencies": {
"playwright-expect": "^0.1.2"
}
}

当我运行完整的黄瓜它的工作(npm run tests:cucumber -- --tags "@MyTag"),但当我试图运行这个与npx (npx playwright tests:chrome --grep @MyTag)它显示错误:

error: unknown command 'tests:chrome'
有谁能帮我一下吗?

我还没有看到通过剧作家测试运行器运行黄瓜剧作家测试的可能性我只能建议使用配置文件与您想要传递给测试并在测试初始化期间读取的数据(您可能可以使用cmd参数以某种方式传递文件名和位置)

像testconfig.json

{
"browser": "chrome",
...
}

然后在BeforeAll步骤中,您可以读取文件并使用所需的参数启动所需的浏览器

BeforeAll(async () => {
const config = <read the config file here>
console.log("Launching browser...");
if (config.browser == "chrome") {
browser = await chromium.launch({
headless: config.headless,
});
}
...
...
});

参见如何向World传递参数文档

OR using cucumber profiles profile文档

我在package.json

中定义了以下脚本(众多脚本中的一个)
"debug-pw": "npx cucumber-js -p test_runner --tags @debug"

,那么你将能够编写调试功能

$env:PWDEBUG=1
npm run debug-pw

最新更新