1

我正在使用blazemeter/taurus:1.13.2带有 blazemeter 报告模块的 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}"
4

1 回答 1

1

使用 JMeter,您可以使用可以将JSR223 Sampler放入setup Thread Group内的代码 或者您可以使用Shell Exec

Java 代码: URL url = new 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();
            }
        }

资源:

于 2019-02-25T20:27:47.443 回答