Report generation using a polymerization comparison chart Jmeter

background

Recently to help the project team to perform other performance tests, the tools are Jmeter. Before recording interfaces and parameters of a person has already done, my main job is to execute the script, writing test reports. Things are not complicated, to do it, it is extremely time-consuming.

First, since there are six groups accounts, respectively six different BU, BU and each in turn needs to perform four kinds of 1,10,20,30 pressure mode. If you use the GUI mode to run, you need to perform 24 times, each time also need to change their own parameters, it is to waste effort.

Second, the polymerization results using the generated Jmeter plug, according to the report results. Before I do my colleagues, because it is the first round of testing, there is no comparison, just wrote a report from the interface, page, error rates three dimensions. And I need to this and the previous results, generate graphs to visually display the results. When it first started, I was on demand, find the corresponding interface and the pages were moved to Excel, use Excel to generate charts. But the mistake is easy, but also easy blind, it is grueling.

solution

1

To solve the first problem, my idea is to find Jmeter test script configuration file, multiple copies, batch into a different configuration, and then use a script to perform multiple bat every time.

First the original test script Jmx file multiple copies, press environment into different folders, and then sort out the number of threads in, as shown below:

 

 

 

 

Because Jmx are actually xml file format, which stores the configuration script, so they use the VS Code to open the folder, batch replace, so soon complete the configuration.

 

 

 

After the write bat script, script execution jmx command line mode, and generate test reports.

Note execute multiple commands in a batch file, if an execution on a desired finish (that is, the order calls) and then proceed to the next, use the call method. As follows:

 

 

call %userprofile%\Desktop\apache-jmeter-3.3\bin\jmeter.bat -n -t 'CP BU.jmx' -l test_report.csv -e -o cp_test_report
call %userprofile%\Desktop\apache-jmeter-3.3\bin\jmeter.bat -n -t 'FA BU.jmx' -l test_report.csv -e -o fa_test_report

% Userprofile% is a system variable, a directory on behalf of a user, the form C: \ Users \ xxx. Such calls can improve reusability, and then use the computer only need to jmeter on the desktop, to run.

-n non-gui run in non-GUI mode

-t test-file script file to be executed

-l logfile records the results file, after the polymerization can be used to generate reports

Saved path -o output html report

 

 So each batch file execution thread for each number, you can automatically generate reports and perform a.

In fact, the path can also generate a report, do parametric configuration, together according to certain rules. But also the multi-threaded bat file and then together, this is much easier. These are places that can be optimized

2

This part of the report will compare some of the trouble. The initial idea is to read data from the old and new macro reports, generate charts and then used to generate libraries comparison chart. With the comparison chart, say they would have a lot less, after all, a picture is worth a thousand words thing.

Before his colleagues actually pasted directly from Jmeter out reports, and script-generated html reports there is not the same place. Moreover, html file not read data, it is difficult to compare the data in excel.

The method most provinces brain naturally I re-run again according to the original way, pasting eleven data out, so the results on the same format, but the reusability too bad, is not considered. After you want to use the simplest method, using a plug-read table from html report opens. Tried circle, Chrome plug-ins or only for pages with http, or is ineffective. Tried under UI Path (RPA tools, recently told some tutorials), extraction is successful, but it seems the number of lines on the page and inconsistent, probably some of the elements have not been identified as a table of elements. In desperation, can only think about the use of the existing report generation similar to previous versions of the report. Have found a jemter command jtl (jmeter test results) is converted to polymerization report, but the script can not be executed, saying it was the lack of plug-ins, but since jmeter upload plugin always fail, there is no way. Herself to try on jemter interface, imported csv file generated before the polymerization report plugin. This time successful, but also a little understanding of the role of these reports. The plug-in is actually a log file will be recalculated organize, demonstrate a few of the most concern.

 

This ensures a consistent data format. The next step is to consider reading the data. My first thought is to use storage Dataframe format pandas in the data.

Write a method that reads:

def read_reports_csv(folder):
    cp_df = pd.read_csv(os.path.join(folder, 'cp.csv'))
    mc_df = pd.read_csv(os.path.join(folder, 'mc.csv'))
    mcp113_df = pd.read_csv(os.path.join(folder, 'mcp113.csv'))
    mcproject_df = pd.read_csv(os.path.join(folder, 'mcproject.csv'))
    pa_df = pd.read_csv(os.path.join(folder, 'pa.csv'))
    fa_df = pd.read_csv(os.path.join(folder, 'fa.csv'))
    return cp_df, mc_df, mcp113_df, mcproject_df, pa_df, fa_df

As to generate charts, I am thinking of pyecharts.

Example graphed as follows:

from pyecharts.charts Import Bar
 from pyecharts Import Options AS the opts 


bar = ( 
Bar ({ " width " : " 800px " , " height " : " 750px " ,}) # initialize the width and height of the chart 
.add_xaxis (list (last_label)) # number of x-axis 
.add_yaxis ( ' the Response time time Average this ' , List (this_average)) # increase the y-axis, this results 
.add_yaxis ( ' the Response time Average Last tIme' , List (last_average)) # increase the y-axis, and the last result 
.set_global_opts ( # Set Global Settings 
    title_opts = opts.TitleOpts (title = ' interfaces average response time comparison chart ' ), # Set title 
    xaxis_opts = opts.AxisOpts (axislabel_opts opts.LabelOpts = (Rotate = 15)), # set x weeks, where the text is inclined, for display longer text 
    legend_opts = opts.LegendOpts (is_show = True, pos_right = 10) # the legend 
) 
)

Generate charts this, search the Internet for a long time, mainly parameters do not understand. Finally, all to find the final answer in the official document. Have to say, or official documents tricky, Baidu in the search out the results can sometimes meet their urgent needs, sometimes it is a patchwork, quality is not high. Or multi-use Google it. But pyechart itself is derived from Baidu library, with an estimated few foreign people, probably not much information.

The next chart is go out into the stuffed data, here is the most problematic place, the following main points:

1. before and after the implementation of the interface is not exactly the same, no way to directly label Label sorting, comparing the data to be aligned.

2. Some parameters interface request is dynamic, no way to write the interface name dead.

Visible, data cleaning head will be heavy, will be generated after the decision chart is correct. My solution idea is to compare the interfaces and pages are parameterized, and then holding the data to be compared, whichever Label field, respectively, in the search for new and old data, the old and the new generated data set to be compared, then the data alignment arrangement, ensure consistent order. Dataframe support operations is already a lot, as far as I know, did not find ready-made solutions, they wrote some small way to achieve these goals. Specific code as follows:

DEF df_contains (DF, partial_labels):
     '' ' 
    This step is to find the data to be compared 
    through the list, the match Dataframe, usually contains the current string, all out 
    ' '' 
    result_df = None
     for label in partial_labels: 
        X = DF [DF [ ' the label ' ] .str.contains (label)]
         IF result_df IS None: 
            result_df = X
         the else :
             IF  Not x.empty: 
                result_df = result_df.append (X, ignore_index = True)
     return result_df.drop_duplicates(subset=['Label', 'Average','Median'], keep='first')
DEF replace_digits_in_df (DF, label):
     '' ' 
    This step is to remove the label number in 
    the script Jmeter recorded in front of each request will add the serial number, affect the sort, it is necessary to remove the uniform 
    course in itself may be provided Jmeter, but I do not know 
    '' ' 
    for Row in df.iterrows (): 
        _ = Row [. 1 ] .label 
        df.loc [Row [0], label] = the re.sub ( ' \ + D ' , ' ' , _)
     return df
DEF draw_api (last_df, this_df, column):
     '' ' 
    last_df: results of the last, pd.Dataframe 
    this_df: The results, pd.Dataframe 
    return: FIG columnar contrast, can be plotted in the notebook may also be derived directly HTML 
    ' ' ' 
    last_temp = replace_digits_in_df (last_df, ' the Label ' ) 
    Last = df_contains (last_temp, api_labels) .sort_values (by = [ ' the Label ' ]) 
    
    this_temp = replace_digits_in_df (this_df, ' the Label ' ) 
    the this = df_contains (this_df, api_labels) .sort_values (by = [ ' the Label ' ]) 
   
    Print (the this.
    Label)
    Print ( ' -------- ' )
     Print (last.Label) 

    # The following is to remove the old and the new intersection data set to be compared, to prevent data misalignment 
    this_del_index = this.append (last, sort = False) .drop_duplicates (Subset = [ ' the Label ' ], Keep = False) .index 
    the this = this.drop (this_del_index) 
    
    last_del_index = last.append (the this, Sort = False) .drop_duplicates (Subset = [ ' the Label ' ], Keep = False) .index 
    Last = last.drop (last_del_index) 
    

    
    this_average = the this [column] 
    this_label = this.Label
    last_average = last[column]
    last_label = last.Label
    

    bar = (
    Bar({"width": "800px", "height": "750px", })
    .add_xaxis(list(last_label))
    .add_yaxis('Response Time Average This Time',list(this_average))
    .add_yaxis('Response Time Average Last TIme',list(last_average))
    .set_global_opts(
        title_optsopts.TitleOpts = (title = ' interfaces average response time comparison chart ' ), 
        xaxis_opts = opts.AxisOpts (axislabel_opts = opts.LabelOpts (Rotate = 15 )), 
        legend_opts = opts.LegendOpts (is_show = True, pos_right = 10 ) 
    ) 
    ) 
    return bar

Of course, these methods are tried many times back and forth, slowly write out the rules. For comparison, two execution, there is no case where data is misaligned. In fact, this is the most time-consuming part.

In addition, jupyter notebook can view real-time charts generated, it is convenient, it is recommended to use. Only need to generate the final chart object, call render_notebook () method can be. FIG comparison finally generated as follows:

 

 

 

Code Address:

https://github.com/MRFF/Learning-Python/blob/master/compare_reports.py

Reference links:

https://pandas.pydata.org/pandas-docs/stable/

https://pyecharts.org/

Guess you like

Origin www.cnblogs.com/yifeixu/p/11742452.html