无法传递 Jenkins 参数以运行量角器脚本 [英] Trouble passing Jenkins parameters to run Protractor scripts

查看:72
本文介绍了无法传递 Jenkins 参数以运行量角器脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用 2 个配置文件来使用 Jenkins 运行我的量角器脚本.

I am currently using 2 config files to run my Protractor scripts using Jenkins.

devConfig.ts and prodConfig.ts

这些具有开发凭据和 URL 以及生产凭据和 URL.

These have the dev creds and URL and the prod creds and URL.

我有两个运行不同命令的 Jenkins 作业

I have two Jenkins jobs that run different commands

npm run tsc && protractor tmp/devConfig.js --suite devRegression
npm run tsc && protractor tmp/devConfig.js --suite prodRegression

不是有两个配置文件,如何合二为一?通过传递 URL、Creds、Suite 和浏览器的参数?

Instead of having two config files, how is it possible to do in one? By passing params for URL, Creds, Suite and Browser?

我能够在 Jenkins 上进行设置:

I was able to setup on Jenkins:

这导致

但我无法将它们传递回量角器脚本.有没有一种直接的方法来构造这些参数并将它们传递给量角器?

But I am not able to pass them back to the protractor scripts. Is there a straightforward way to construct these parameters and pass them on to protractor?

推荐答案

对于量角器方面,请查看此页面

For protractor side check out this page

根据其内容,在您的 conf.js 中包含此内容:

Per its content, having this in your conf.js:

module.exports = {
  params: {
    login: {
      email: 'default',
      password: 'default'
    }
  },
    //  * other config options *
}

您可以在 CMD 中向其传递任何参数,如下所示:

you can pass any parameter to it in CMD as follows:

protractor --baseUrl='http://some.server.com' conf.js --parameters.login.email=example@gmail.com 
--parameters.login.password=foobar

所以你最终在你的规格中拥有这个:

so you end up having this in your specs:

describe('describe some test', function() {
  it('describe some step', function() {
    browser.get(browser.baseUrl);
    $('.email').sendKeys(browser.params.login.email);
    $('.password').sendKeys(browser.params.login.password);
  });
});

对于Jenkins,只需按如下方式构建命令:

For Jenkins just construct the command as follows:

protractor --baseUrl=${url} conf.js --parameters.login.email=${email}
--parameters.login.password=${password}

如果您只想传递一个参数,另一种方法是在您的 config.js 中有对象,并映射所有相关参数,如下所示:

Another way if you want to just pass one parameter is have object in your config.js with mapping of all related params like this:

let param_mapping = {
    prod: {
        url: "https://prod.app.com",
        email: "prod@gmail.com",
        password: "Test1234"
    },
    dev: {
        url: "https://dev.app.com",
        email: "dev@gmail.com",
        password: "Test1234"
    },
    stage: {
        url: "https://stage.app.com",
        email: "stage@gmail.com",
        password: "Test1234"
    }
};

let parameters = param_mapping[process.ENV.CUSTOM_ENV];

exports.config = {
    baseUrl: parameters.url,
    params: parameters,
    // ...
};

然后使用环境变量启动您的进程:

and then start your process with an environment variable:

CUSTOM_ENV=dev protractor protractor.conf.js

请注意,我现在还没有测试这个特定的代码,但我不久前确实测试了逻辑,所以这可以成为你的方法

Please note, I haven't tested this particular code now, but I did test the logic a little while ago, so this can be your approach

这篇关于无法传递 Jenkins 参数以运行量角器脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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