【问题标题】:Adding 'Notes' dynamically through taurus command line arguments通过 taurus 命令行参数动态添加“注释”
【发布时间】:2019-02-26 04:27:47
【问题描述】:

我正在使用带有 blazemeter 报告模块的 blazemeter/taurus:1.13.2 Docker 映像来执行测试。

taurus 命令行有没有一种方法可以为 BlazeMeter 上的“Notes”字段传递一个值?我已经成功传递了其他值,例如:

-o modules.blazemeter.report-name="${report_name}"

我希望在“Notes”中传递类似的东西。我试过了:

-o modules.blazemeter.notes="${notes}"

但没有运气。

这是我运行完整命令行的脚本:

#!/bin/bash
api_token=$1
timestamp=`date +%s`
report_name="`hostname`_`git log --format='%h' -n 1`_taurus-jmeter_${timestamp}"
notes="testing use of notes through taurus command line args"
artifacts_dir="artifacts/${timestamp}"
docker run -t --rm -v `pwd`:/bzt-configs -v `pwd`/artifacts:/tmp/artifacts blazemeter/taurus:1.13.2 taurus.yml -o settings.artifacts-dir="${artifacts_dir}" -o modules.blazemeter.report-name="${report_name}" -o modules.blazemeter.notes="${notes}" -o modules.blazemeter.token="${api_token}"

【问题讨论】:

    标签: blazemeter taurus


    【解决方案1】:

    使用 JMeter,您可以使用此代码,您可以将其放入 JSR223 Samplersetup Thread Group 或者,您可以使用Shell Exec

    Java 代码: URL url = 新 URL("https://a.blazemeter.com:443/api/v4/masters/" + masterId); HttpURLConnection 连接 = 空; 尝试 { conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoInput(true); conn.setDoOutput(true);

                /* We use the API Key and API Secret as Basic Authentication */
                String usernameColonPassword = "" + X_GlobalVariables.BZM_API_KEY + ":" + X_GlobalVariables.BZM_API_SECRET + "";
                String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(usernameColonPassword.getBytes());
    
                // Include the HTTP Basic Authentication payload
                conn.addRequestProperty("Authorization", basicAuthPayload);
    
                //Create JSONObject here
                JSONObject jsonParam = new JSONObject();
                jsonParam.put("note", "Service Version: " + serviceVersion + "\nGateway Version: " + gatewayVersion + "");
                try (OutputStreamWriter out = new  OutputStreamWriter(conn.getOutputStream())) {
                    out.write(jsonParam.toString());
                }
    
                /* Check here for a OK (200) response */
                if (conn.getResponseCode() != 200) {
                     throw new RuntimeException("Failed : HTTP error code : "
                         + conn.getResponseCode());
                }
    
                /* Release the connection */
            } finally {
                if (conn != null) {
                    conn.disconnect();
                }
            }
    

    来源:

    【讨论】:

    • 谢谢。我无法编辑您的帖子以修复代码块的开始位置,因为更改只有 1 个换行符。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 1970-01-01
    • 2015-04-26
    • 2010-11-07
    相关资源
    最近更新 更多