Disclosure of Invention
The invention aims to provide a test report generation method, a test report generation device and a storage medium based on HTML5, which can solve the problem that in the prior art, a test report output in an xml format only has character information and cannot output modification actions such as a chart and the like.
The purpose of the invention is realized by the following technical scheme:
in a first aspect, the present invention provides a test report generation method based on HTML5, including the following steps:
step 1, a test data parser receives test data of a test framework, and the test data is processed into a dictionary type data structure body which can be read and operated by a test report generator;
and 2, filling the data in the data structure into a preset HTML5 template to generate a HTML test report of a single HTML5 static file.
Furthermore, the data in the data structure is filled into the preset HTML5 template, and the render output is realized by calling the render _ template method of jinja 2.
Further, the process of calling render _ template method of jinja2 to realize rendering output includes:
acquiring template text content;
replacing data in the data structure body analyzed by the test data analyzer to a position corresponding to the template;
generating complete text content;
saved as an HTML5 file.
Further, the test report generation method based on the HTML5 further comprises the steps of generating an HTML5 template:
reporting the key information by using the element layout of HTML, then performing style description on the reporting key information by using CSS, and finally realizing interactive logic by using js.
Further, the report key information includes report summary information and detailed case test data.
Further, the report summary information includes, but is not limited to, a name of a use case, a total number of use cases, a number of pass cases, a number of fail cases, a number of skip cases, a start time, a test time, and a percentage pie chart of a result of a use case.
Further, the detailed use case test data includes, but is not limited to, use case ID, test type, test method, use case description, run time, test result, and view log.
In a second aspect, the present invention provides a test report generating apparatus based on HTML5, including a storage module, a test data parser, and a test report generator, wherein:
the storage module is used for storing an HTML5 template;
the test data parser is used for receiving the test data of the test framework and then processing the test data into a dictionary type data structure body which can be read and operated by the test report generator;
and the test report generator is used for filling the data in the analyzed data structure into a preset HTML5 template to generate a test report of a single HTML5 static file with a suffix of HTML.
In a third aspect, the present invention provides a storage medium having a computer program stored therein, wherein the computer program is operable to execute the test report generation method based on HTML 5.
According to the test report generation method, device and storage medium based on the HTML5, readability and data structure of the output report can be both considered, attractiveness is achieved, the display effect of the template can be defined by modifying the style and format of the template, and the structure of the test data is not affected.
Detailed Description
The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
The embodiments of the present disclosure are described below with specific examples, and other advantages and effects of the present disclosure will be readily apparent to those skilled in the art from the disclosure in the specification. It is to be understood that the described embodiments are merely illustrative of some, and not restrictive, of the embodiments of the disclosure. The disclosure may be embodied or carried out in various other specific embodiments, and various modifications and changes may be made in the details within the description without departing from the spirit of the disclosure. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.
The invention discloses a test report generation method based on HTML5, which comprises the following steps:
step 1, a test data parser receives test data of a test framework, and then the test data is processed into a data structure body which can be read and operated by a test report generator, and the structure body is realized by using dictionary types.
The dictionary type is a built-in data type in the Python language. The dictionary in Python is composed of key (key) value (value) pairs, wherein keys and values are separated by colons, different groups of key value pairs are divided by commas, the whole dictionary is wrapped by { }, and the dictionary is unordered, and we can obtain the value of value by key. For example, a dictionary with values of dit 1 { 'apple' 8, 'banana' 3, 'peach' 5 }.
Test frameworks such as Python unitest and Python test, etc., the test data of which is the data of the Python object.
And 2, filling the data in the data structure into a preset HTML5 template to generate a HTML test report of a single HTML5 static file.
Filling data in the data structure into an HTML5 template, and mainly calling a render _ template method of jinja2 to realize rendering output, wherein the process comprises the following steps:
acquiring template text content;
replacing data in the data structure body analyzed by the test data analyzer to a position corresponding to the template;
generating complete text content;
saved as an HTML5 file.
Jinja2 is a python-based template engine. The generated test report can be directly opened and viewed by using a browser or put on a web server for external presentation. render _ template is one of the template rendering functions within the flash itself.
Further, the test report generation method based on the HTML5 of the present invention further includes the step of generating an HTML5 template:
reporting the key information by using the element layout of HTML, then performing style description on the reporting key information by using CSS, and finally realizing interactive logic by using js. Interaction logic such as pie chart drawing and viewing, log viewing interactions, and the like.
The report key information comprises report summary information and detailed case test data. The report summary information includes, but is not limited to, a case name, a total number of cases, a number of passed cases, a number of failed cases, a number of skipped cases, a start time, a test time, and a percentage pie chart of case results. The detailed case test data includes, but is not limited to, case ID, test type, test method, case description, run time, test result, and view log.
The invention discloses a test report generating device based on HTML5, which comprises a storage module, a test data parser and a test report generator, wherein:
and the storage module is used for storing the HTML5 template.
The HTML5 template is preset in a storage module. Fig. 3 is an example of an HTML5 template, which should not be construed as limiting the HTML5 template, and the HTML5 template may be in other forms, which are specifically set according to the user's needs.
And the test data parser is used for receiving the test data of the test framework and then processing the test data into a data structure body which can be read and operated by the test report generator.
And the test report generator is used for filling the data in the analyzed data structure into a preset HTML5 template to generate a test report of a single HTML5 static file with a suffix of HTML.
A storage medium having a computer program stored therein, the computer program being executable to perform the method of:
step 1, a test data parser receives test data of a test framework, and the test data is processed into a dictionary type data structure body which can be read and operated by a test report generator;
and 2, filling the data in the data structure into a preset HTML5 template to generate a HTML test report of a single HTML5 static file.
Further, in a preferred embodiment of the present application, the data in the data structure is filled into a preset HTML5 template, and a render _ template method of jinja2 is called to implement rendering output.
Further, in a preferred embodiment of the present application, the process of calling render _ template method of jinja2 to implement rendering output includes:
acquiring template text content;
replacing data in the data structure body analyzed by the test data analyzer to a position corresponding to the template;
generating complete text content;
saved as an HTML5 file.
Preferably, the test report generation method based on HTML5 of the present invention further includes the step of generating an HTML5 template: reporting the key information by using the element layout of HTML, then performing style description on the reporting key information by using CSS, and finally realizing interactive logic by using js.
In the present invention, unless otherwise expressly stated or limited, the terms "mounted," "connected," "secured," and the like are to be construed broadly and can, for example, be fixedly connected, detachably connected, or integrally formed; may be mechanically coupled, may be electrically coupled or may be in communication with each other; they may be directly connected or indirectly connected through intervening media, or they may be connected internally or in any other suitable relationship, unless expressly stated otherwise. The specific meanings of the above terms in the present invention can be understood by those skilled in the art according to specific situations.
The above description is for the purpose of illustrating embodiments of the invention and is not intended to limit the invention, and it will be apparent to those skilled in the art that any modification, equivalent replacement, or improvement made without departing from the spirit and principle of the invention shall fall within the protection scope of the invention.