如何参数化量角器配置文件的 baseUrl 属性 [英] How do I parameterize the baseUrl property of the protractor config file

查看:47
本文介绍了如何参数化量角器配置文件的 baseUrl 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在配置文件中使用不同的 baseUrl 在不同的上下文中运行我的量角器测试.我不想为每种情况使用单独的配置文件,因为这样更难以维护.相反,我想将基本 url 作为命令行参数传入.这是我迄今为止尝试过的:

I need to run my protractor tests in different contexts with different baseUrls in the config files. I don't want to use separate config files for each situation since that is more difficult to maintain. Rather, I want to pass the base url in as a command line parameter. Here is what I have tried so far:

量角器.conf.js:

The protractor.conf.js:

exports.config = {
  onPrepare : {
    ...
    exports.config.baseUrl = browser.params.baseUrl;
    ...
  }
}

并调用量角器:

protractor protractor.conf.js --params.baseUrl 'http://some.server.com'

这不起作用,因为在调用 onPrepare 之前似乎已经配置了 browser 实例.

This does not work since it seems like the browser instance is already configured before onPrepare is called.

同样,我也试过这个:

exports.config = {
  baseUrl : browser.params.baseUrl
}

但这也不起作用,因为在生成配置时浏览器实例似乎不可用.

But this doesn't work either since it seems like the browser instance is not available when the config is being generated.

看起来我可以使用标准节点 process.argv 来访问所有命令行参数,但这似乎违背了量角器的精神.

It looks like I can use standard node process.argv to access all command line arguments, but that seems to be going against the spirit of protractor.

对我来说,做我需要做的事情的最佳方式是什么?

What is the best way for me to do what I need to do?

推荐答案

看起来这已经是可能的,但是这方面的文档参差不齐.看代码,但是,量角器确实支持看似未记录的命令行参数的数量.

Seems like this is already possible, but the documentation is spotty in this area. Looking at the code, however, protractor does support a number of seemingly undocumented command line arguments.

所以,运行这样的东西会起作用:

So, running something like this will work:

protractor --baseUrl='http://some.server.com' my.conf.js

这篇关于如何参数化量角器配置文件的 baseUrl 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆