a preface
In the performance test framework development, you need to process the completed test report of the scene, summarize the performance metrics data that you are following in the report, and then write the report and send the relevant person a message. So, one of the steps is how to capture the data from the test report (e.g.,TPS, Response time, number of concurrent users, etc.).
Two problem analysis
when LR generates a test report, it saves the report data to the table of contents, which has a summary of similar metrics, as shown in. However, this idea will disappoint you if you want to get the data for each metric by parsing the HTML! Because analysis of the HTML source discovery, the indicator data is not actually in the page, but in the definition of the page frameset. In layman's words, a page is nested in another page, and the actual data is obtained by accessing the inline page. Familiar with selenium classmate, must know this kind of situation, after all want to locate the element, the first thing to do is switch_to_frame . Not much here, follow-up will be a series of selenium related articles.
three solution ideas
after the analysis of HTML source code, you can find that each indicator data corresponds to an HTML file stored in the report directory , as long as the use of python html The parsing technique gets, and then modifies the data slightly, adding a number of HTML-formatted strings in the form of a label , and finally writing to the. html file.
four Python HTML Parsing technology summary
Python is very good at parsing html , many methods, summed up the following several:
1. lxml.html
2. BeautifulSoup
3. Sgmlparser
4. Htmlparaer
5. requests-html
6. Regular Expressions
in this implementation, the use ofBeautifulSoup, a model forfromHTMLorXMLfiles that extract data from thePythonLibrary,APIclear and concise. Among them,LRthe table styles in the report and the code to get the tabular data are as follows:
Style table for LR reports
Some of the code is as follows:
Five implementation effect
Finally, we analyze the results of the scene execution and extract TPS, Response time, number of concurrent users and other metrics data, and the style for generating summary reports is as follows:
Other resources:
Python Introductory course:http://i.youku.com/weiworld521
Python implementation parse LR analyse result and generate summary performance metrics Data Report