zoukankan      html  css  js  c++  java
  • 关于jmeter+ant+jenkins性能自动化将测试结果文件jtl转换成html文件遇到的问题。

    1、ant自身缺陷,返回结果中有特殊字符,乱码字符,无法识别,jtl文件转换时报错。

    2、jtl文件过大转换成html文件时出现内存溢出。

    针对以上情况:可考虑使用BeenShell Sampler:对返回结果的乱码、特殊字符进行处理,返回结果内容过大,通过代码进行截取,但是会对性能测试结果又小许影响。

    引入的外部java文件代码如下:

    import java.net.URI;
    import org.apache.http.HttpHost;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.config.RequestConfig;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClientBuilder;
    import org.apache.http.util.EntityUtils;

    public class GetRequest {
    public static String doGet(String url, String keyValueParam,String proxy,String port){
    // 构建htpp客户端对象
    CloseableHttpClient client = HttpClientBuilder.create().build();
    HttpGet get = new HttpGet();
    RequestConfig requestConfig = RequestConfig.custom()
    .setSocketTimeout(20000)
    .setConnectTimeout(20000)
    .setConnectionRequestTimeout(20000)
    .build();
    if(!proxy.equals("")){
    requestConfig = RequestConfig.custom()
    .setSocketTimeout(20000)
    .setConnectTimeout(20000)
    .setConnectionRequestTimeout(20000).setProxy(new HttpHost(proxy, Integer.valueOf(port)))
    .build();
    }

    get.setConfig(requestConfig);
    // 将url和键值对参数拼接成新的url地址
    get.setURI(URI.create(url + keyValueParam));
    HttpResponse response;
    String strResponse ="No HttpResponse";
    try {
    response = client.execute(get);
    // 获取返回主体
    strResponse = EntityUtils.toString(response.getEntity());
    } catch (Exception e) {
    // TODO Auto-generated catch block
    //e.printStackTrace();
    strResponse ="Send Request,But HttpResponse is error";
    }finally {

    try {
    client.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    //e.printStackTrace();
    }

    }


    return strResponse;
    }

    public static String doGet(String url, String keyValueParam, String header,String proxy,String port){
    // 构建htpp客户端对象
    CloseableHttpClient client = HttpClientBuilder.create().build();

    HttpGet get = new HttpGet();
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20000).setConnectTimeout(20000)
    .setConnectionRequestTimeout(20000).build();
    if (!proxy.equals("")) {
    requestConfig = RequestConfig.custom().setSocketTimeout(20000).setConnectTimeout(20000)
    .setConnectionRequestTimeout(20000).setProxy(new HttpHost(proxy, Integer.valueOf(port))).build();
    }
    get.setConfig(requestConfig);
    // 将url和键值对参数拼接成新的url地址
    get.setURI(URI.create(url + keyValueParam));
    get.addHeader("Cookie", header);

    HttpResponse response;
    String strResponse="No HttpResponse";
    try {
    response = client.execute(get);
    strResponse = EntityUtils.toString(response.getEntity());
    } catch (Exception e) {
    // TODO Auto-generated catch block
    //e.printStackTrace();
    strResponse="Send Request,But HttpResponse is error";
    }finally {

    try {
    client.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    //e.printStackTrace();
    }

    }
    // 获取返回主体

    return strResponse;
    }
    }

    BeenShell  Sampler的代码如下:

    source("D:/Jmeter/运营平台核心性能场景/java/GetRequest.java");
    String actualResponse = GetRequest.doGet("${Agreement}://${Host}:${Port}","${qualityCertificationUrl}","${Cookie}","${ProxyHost}","${ProxyPort}");
    String sonStr= "<h3>初级认证2.0</h3>";
    String response="";
    //判断是否包含期望的字符串
    if(actualResponse.indexOf(sonStr)!=-1){
    response = "<h3>初级认证2.0</h3>";
    }else{
    response = actualResponse;
    }
    //为jmeter响应结果赋值
    ResponseMessage=response;

  • 相关阅读:
    「NOIP2011」聪明的质监员
    「CF5E」Bindian Signalizing
    「NOIP2017」列队
    「NOIP2016」愤怒的小鸟
    「牛客CSP-S2019赛前集训营2」服务器需求
    「牛客CSP-S2019赛前集训营1」仓鼠的石子游戏
    「SCOI2010」幸运数字
    函数求值一<找规律>
    梯形
    F(k)<(维护+枚举)(找规律+递推+枚举)>
  • 原文地址:https://www.cnblogs.com/zw520ly/p/8337623.html
Copyright © 2011-2022 走看看