how to set cucumber environment variables(如何设置黄瓜环境变量)
问题描述
我有以下 package.json:
I am having the following package.json:
{
"name": "newcucumber",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/cucumber-js",
"firefox": "./node_modules/.bin/cucumber-js -- --profile.desktop.env.browser ff"
},
"author": "",
"license": "ISC",
"dependencies": {
"chromedriver": "^2.24.1",
"cucumber": "^1.3.0",
"firefox-profile": "^0.4.2",
"geckodriver": "^1.1.2",
"phantomjs-prebuilt": "^2.1.12",
"selenium-webdriver": "^3.0.0-beta-2"
}
}
我使用以下方式运行程序:
I run the program using:
npm test
我想为 cucumber 设置一个环境变量,这样我就可以从命令行运行:npm test firefox
或 npm test phantomjs
.
I would like to set an environment variable for cucumber, such that I could run from the command line: npm test firefox
or npm test phantomjs
.
如上所示,它也可以作为 package.json 'scripts' 的一部分,但我不确定我是否做得对.调用 npm run-script firefox
It could also be as a part of package.json 'scripts' as seen above, but I am not sure if I did it right. Invoking npm run-script firefox
如何实现它,以便在 js 代码(如 world.js 或 browser.js)中获取 env 变量?
How does one implement it, such that in the js code, like world.js or browser.js I grab the env variable?
推荐答案
再一次,我得到了我最开始想使用的答案:
Once more, now I have got the answer I wanted to use in the first place:
这就是 package.json 的一部分(注意!!!引号的语法)的样子:
This is how part of package.json (MIND!!! the syntax of quotation marks) looks like:
"scripts": {
"test": "cucumber-js",
"firefox": "cucumber-js --world-parameters '{"browser":"firefox"}'",
"chrome": "cucumber-js --world-parameters '{"browser":"chrome"}'",
"safari": "cucumber-js --world-parameters '{"browser":"safari"}'",
"phantomjs": "cucumber-js --world-parameters '{"browser":"phantomjs"}'"
}
JSON 对象被传递给 World.在您的 World.js 中,代码如下所示:
The JSON object is passed to World. In your World.js the code looks like this:
module.exports = function() {
this.World = function(input) {
console.log(input.browser); // Do whatever you want with the JSON (input) object
};
};
这篇关于如何设置黄瓜环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何设置黄瓜环境变量


- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01