将参数从npx命令传递到playright.config.js文件。

huangapple go评论86阅读模式
英文:

how to pass parameter from npx command to playright.config.js file

问题

我有这个在playwright.config.js文件中的axios报告
reporter: [['junit', { outputFile: 'results.xml' }],['./aio-reporter.js']],

现在我想在从命令行运行测试时向报告传递参数
例如:
reporter: [['junit', { outputFile: 'results.xml' }],['./aio-reporter.js'], let testcycle],

npx playwright test --testcycle=TC-TY-2

英文:

i have this axios report in playwright.config.js file
reporter: [['junit', { outputFile: 'results.xml' }],['./aio-reporter.js']],

now I want to pass a parameter to the report when I'm running the test from the command line
ex:
reporter: [['junit', { outputFile: 'results.xml' }],['./aio-reporter.js'], let testcycle],

npx playwright test --testcycle=TC-TY-2

答案1

得分: 1

你可以选择一个简单的实现方式,即在这种情况下使用环境变量来传递该值。你可以这样运行命令:

TESTCYCLE="TC-TY-2" npx playwright test

然后在代码中可以通过process.env.TESTCYCLE引用该值。

英文:

One option that is simple to implement would be to just use an environment variable in this case to pass in that value. You could run the command like so:

TESTCYCLE=“TC-TY-2” npx playwright test

And then you can reference that value in the code as process.env.TESTCYCLE

huangapple
  • 本文由 发表于 2023年3月1日 13:58:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600044.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定