[英]Access option values webdriver.io
Right now with my ui tests using WebdriverIO, I have this in my configuration file: 现在,使用WebdriverIO进行ui测试时,我在配置文件中包含以下内容:
var baseUrl = 'http://localhost:3000';
global.testParameters = {
baseUrl: baseUrl
};
This gives me access to my base url in the tests however it has to be fixed in the configuration file and I can't use the --baseUrl option when running wdio command. 这使我可以访问测试中的基本URL,但是必须在配置文件中对其进行修复,并且在运行wdio命令时无法使用--baseUrl选项。 The reason for this is because from everything I have read, I don't see a way to have access to command line option values in my tests.
这样做的原因是,从我阅读的所有内容中,我看不到在测试中可以访问命令行选项值的方法。
Is there a way to access the value of the command line options (specifically --baseUrl) in my actual test files? 有没有办法在我的实际测试文件中访问命令行选项的值(特别是--baseUrl)?
You can use the yargs library. 您可以使用yargs库。 Do
npm install yargs
and in your config file add: 执行
npm install yargs
并在配置文件中添加:
var argv = require('yargs').argv;
var baseUrl = argv.baseUrl;
You can then pass in the baseUrl with --baseUrl <your URL>
然后,您可以使用
--baseUrl <your URL>
传递--baseUrl <your URL>
You can also make use of the WebdriverIO spec ( wdio.conf.js ) for configuration and create a separate conf.js file for each baseUrl you'd like to run your tests against 您还可以利用WebdriverIO规范( wdio.conf.js )进行配置,并为要对其运行测试的每个baseUrl创建一个单独的conf.js文件。
You can pass your base location through command line using -baseUrl=
like below 您可以使用
-baseUrl=
通过命令行传递基本位置,如下所示
wdio --baseUrl=http://[device IP]
You can pass any argument you need using the same way and can access it in wdio.config.js ' onprepare
' event like below 您可以使用相同的方法传递所需的任何参数,并可以在
onprepare
'事件中访问它,如下所示
wdio --type=XXX
Then in wdio config 然后在wdio config中
onPrepare: function(config, capabilities) {
if (process.argv !== undefined && process.argv.length) {
process.argv.forEach(arg => {
if (arg.indexOf('--type=') !== -1) {
process.env.type = arg.replace('--type=', '');
}
});
}
},
before: function(capabilities, specs) {
global.type = process.env.type;
}
Now your type is available through-out your workspace as a global variable. 现在,您的类型可以作为全局变量在整个工作空间中使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.