Disclosure of Invention
The invention aims to provide a mobile terminal automatic test method and system based on natural language recognition, which are used for solving the problems.
In order to achieve the above purpose, the present invention adopts the following technical scheme:
the mobile terminal automatic test method based on natural language identification is realized based on an automatic test platform and comprises the following steps:
s1, configuring application information to be tested through an automatic test platform;
S2, compiling test cases according to natural language and grammar rules, and defining element information in a UI interface of the application to be tested;
S3, analyzing the test case, splitting the test case into a plurality of operations, and then respectively converting natural language in each operation into machine language to generate a case operation queue;
S4, judging the grammar of the machine language of each operation in the use case operation queue, if the grammar is correct, entering a step S5, otherwise, stopping the operation;
S5, starting system barrier-free service, opening the application to be tested, executing each operation in the use case operation queue, checking whether the operation executed currently is successful, and when all the operations are successfully executed or serious errors occur in the executed operations, completing the test and generating a test report.
Preferably, the test case adopts a plain text format file, and each row in the plain text format file represents one operation.
Preferably, the automated test platform is provided with a case interceptor group, the case interceptor group comprises a plurality of interceptors, the interceptors are composed of interception rules, and the interception rules correspond to grammar rules when writing test cases.
Preferably, step S3 is embodied as
S31, starting text analysis, and analyzing the test case into a plurality of operations;
S32, analyzing UI element information corresponding to each operation and variable value information corresponding to the elements;
s33, starting a use case interceptor group, traversing all interceptors in the interceptor group by each operation in the test use case, searching interceptors corresponding to own conditions, and converting natural language in the operation into machine language through the searched interceptors;
s34, judging whether operation which does not execute analysis exists, if so, returning to the step S32 to continue analysis until all operations are executed, generating a use case operation queue, and issuing to judge grammar and execute operation.
Preferably, step S5 is specifically:
S51, opening a system barrier-free service and opening the application to be tested;
S52, respectively taking out each operation from the use case operation queue, executing the current operation, searching the interface element of the current UI, judging that the interface element is the target element required by the current operation if the interface element is matched with the target element attribute of the operation, and changing the operation state into an operation error if the matched interface element is not searched;
s53, executing element operation through the matched interface element of the barrier-free service, and generating a test report after the test is finished when all the operations are successfully executed or the executed operation errors are serious errors;
and S54, the test data of the test report are displayed through a test result page for a tester to analyze, and the analysis result is fed back to an application development end to be tested.
The mobile terminal automatic test system based on natural language identification comprises a case module, an execution set module, a device module, a natural language analysis module, a semantic module, a variable module, a setting module and a test report module, wherein the case module is used for compiling test cases through natural language and grammar rules, the execution set module is used for integrating a plurality of test cases into one execution set, the device module is used for acquiring device information and realizing single test of the plurality of test cases, the natural language analysis module is used for analyzing the test cases into machine language of machine identification, the semantic module is used for defining element information of a UI interface, the variable module is used for defining variable value information, the setting module is used for setting application information to be tested of automatic test, and the test report module is used for generating a test report from the execution result of the test cases or the execution set.
Preferably, the system further comprises a search module for searching test cases, execution sets and test reports.
Preferably, the natural language analysis module is internally provided with a case interceptor group, the case interceptor group comprises a plurality of interceptors, the interceptors are composed of interception rules, the interception rules correspond to grammar rules when test cases are written, when the natural language analysis module is used, each operation in the test cases traverses all interceptors in the interceptor group, the interceptors corresponding to the conditions are searched, and the natural language in the operation is converted into machine language through the searched interceptors.
After the technical scheme is adopted, compared with the background technology, the invention has the following beneficial effects:
1. The invention provides a mobile terminal automatic test method and a system based on natural language identification, which can write and use test cases without specific file types by using natural language and using simple and visual word description, are convenient to use, are easy to maintain, and can be rapidly compatible with scenes with frequent UI structure change.
2. The invention provides a mobile terminal automatic test method and a system based on natural language identification, which do not need to be connected with a computer PC terminal, all operations are completed in an automatic test platform application, each device can independently write use cases and operate, wireless is realized, and during operation, a barrier-free service operation UI built in an Android system is directly used, so that the time consumption of operation of processing and conversion of a third-party tool is avoided.
3. The invention provides a mobile terminal automatic test method and a system based on natural language identification, wherein a test report is generated by a test case, the test report can be exported and checked on any equipment, and meanwhile, the mobile terminal automatic test method and the system have error information highlighting prompt, so that the problem can be conveniently analyzed by test staff.
Detailed Description
The present invention will be described in further detail with reference to the following examples in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
Examples
The invention discloses a mobile terminal automatic test method based on natural language identification, which is realized based on an automatic test platform and specifically comprises the following steps of:
S1, configuring application information to be tested through an automatic test platform, wherein the application information to be tested comprises application names to be tested, whether to restart the application to be tested when starting running, whether to open a floating window and the like;
S2, writing a test case through natural language and a certain grammar rule, wherein the test case comprises a case name and a case description, and defining element information in a UI interface of an application to be tested, and the element information comprises description and positioning of UI elements;
The test case can be written directly on the automatic test platform of the embodiment, and can also be written on other platforms (such as a computer (PC) end), and after the writing of the other platforms is completed, the content of the test case needs to be copied into the application of the platform so as to be executed; and writing corresponding test case sentences according to the example sentence specifications by using a case operation writing panel, wherein each row of sentences is one operation.
The test cases are written in plain text format files, and each row in the plain text format files represents one operation.
S3, analyzing the test case, splitting the test case into a plurality of operations, and then respectively converting natural language in each operation into machine language to generate a case operation queue;
Step S3 is specifically as follows
S31, starting text analysis, and analyzing the test case into a plurality of operations;
S32, analyzing UI element information corresponding to each operation and variable value information corresponding to the elements;
S33, starting a case interceptor group, traversing all interceptors in the interceptor group by each operation in the test case, searching interceptors corresponding to own conditions, and converting natural language in operation into machine language through the searched interceptors;
s34, judging whether operation which does not execute analysis exists, if so, returning to the step S32 to continue analysis until all operations are executed, generating a use case operation queue, and issuing to judge grammar and execute operation.
S4, judging grammar of machine language of each operation in the use case operation queue, if the grammar is correct, entering a step S5, otherwise, stopping operation;
s5, starting a system barrier-free service, opening an application to be tested, executing each operation in the use case operation queue, checking whether the operation executed currently is successful, and when all the operations are successfully executed or serious errors occur in the executed operations, completing the test and generating a test report.
The automatic test platform is provided with a case interceptor group, the case interceptor group comprises a plurality of interceptors, each interceptor comprises interception rules, and the interception rules correspond to grammar rules when test cases are written.
The step S5 specifically comprises the following steps:
S51, starting system barrier-free service and opening an application to be tested;
S52, respectively taking out each operation from the use case operation queue, executing the current operation, searching the interface element of the current UI, judging that the interface element is the target element required by the current operation if the interface element is matched with the attribute of the target element of the operation, and changing the operation state into an operation error if the matched interface element is not searched;
s53, executing element operation through the matched interface element of the barrier-free service, and generating a test report after the test is finished when all the operations are successfully executed or the executed operation errors are serious errors;
For example, execute statements: if the return button # exists and then the return button is clicked, # the automatic test platform firstly judges whether a return button element exists in the current UI, the UI element is searched according to Text, description, className, xpath and ResId attributes of the element, if the target element is consistent with the text of a certain element on the current page, the two elements accord with initial conditions, the elements are judged and found out to be the most relevant element through ResId or other attributes, the elements are considered to be the elements needing to be operated in a use case, and when the matched element is not found, the operation state is changed into an execution error; when a matching element is found, clicking on the element is performed by the barrier-free service.
And S54, displaying the test data of the test report through a test result page for a tester to analyze, and feeding back an analysis result to an application development end to be tested. The data provided by the test case result page contains each operation screen shot, running time, equipment information, error information and the like.
The following test cases written in natural language are enumerated:
(1) Cold start
(2) Inputting # mobile phone number in the first input box
(3) Inputting a # password in a second input box
(4) Click immediate login
(5) Wait for 5 seconds
(6) Presence indication of successful login
The following is a detailed explanation based on the test case examples described above:
For example, in the interceptor parsing to example (2) above, the platform first determines that there is an "input#" statement, indicating that it needs to be parsed into InputAction of machines; next, extracting the sentence "in the first input box" before "input #" and identifying the core content "first", indicating that the element object to be operated is the first in the UI layer distribution; finally, the sentence "mobile phone number" after "input #" is extracted, which indicates that the content to be input is three words of "mobile phone number". So far, after the analysis of the line of sentences is finished, the line of sentences is converted into machine language, and the interceptor completes work and waits for subsequent operation. Through the converted machine language, when the system starts to run to the operation, the system firstly searches the first element which is an input box in the current page UI distribution from left to right and from top to bottom, and three words of a mobile phone number are automatically input in the input box after the first element is found, so that the line of operation examples are completed.
For example, upon the interceptor parsing to example (4) above, the interceptor responsible for the click event matches the rule: the statement starts with a "click". (4) The operation satisfies the rule indicating a need to be handled by the click event interceptor. Then, the post-sentence part is "immediate login", which means that the name of the target element requiring the operation is "immediate login". After the analysis of the line of sentences is completed, converting the natural language into a machine language, clicking the event machine language into ClickAction, and storing the machine language into a queue.
For example, when the interceptor parses the operation in the example (5) above, the interceptor is responsible for waiting for the event interceptor matching rule to be a regular expression, satisfying the expression condition, the platform parses the interceptor matching rule to be a waiting operation, sets the waiting time to be 5 seconds, and when executing the statement, the platform does not perform any operation, and executes the next operation after 5 seconds.
The rule syntax includes, but is not limited to (below X is the UI control element name): basic element operation grammar such as 'click X', 'double click X', 'long press X', 'slide X', 'return', and the like; element positioning grammars of 'first', 'last', 'any' and the like; logic judgment grammars such as "x# and then #," # is equal to or greater than #, "# text is equal #", and the like if present; variable assignment grammar such as "user nickname=hello", "variable name=get text X". All the rules grammars currently defined meet the operational requirements required for current automated testing.
The invention also discloses a mobile terminal automatic test system based on natural language identification, which comprises a case module, an execution set module, an equipment module, a natural language analysis module, a semantic module, a variable module, a setting module and a test report module, wherein the case module is used for compiling test cases through natural language and a certain grammar rule and supporting the addition, the modification and the deletion of the test cases. The execution set module is used for integrating the plurality of test cases into one execution set, so that the plurality of test cases can be tested for a single time, and the equipment module is used for acquiring equipment information, wherein the equipment information comprises equipment hardware, configuration, version, resolution and the like. The method realizes single test of a plurality of test cases, the natural language analysis module is used for analyzing the test cases into machine language identified by a machine, and the semantic module is used for defining element information of a UI interface, so that the test cases can be conveniently written. For example, a menu button element may be defined as a "menu", and when an instance is written, a "menu" document may be directly used to operate a corresponding element, and if a button operation needs to be clicked, a "click menu" may be directly written, so that the platform may correspondingly operate the element. The variable module is used for defining variable value information, and can dynamically replace a required variable during operation. For example, the user name and the password required by login can be added into the variable, so that dynamic operation replacement can be realized in the use cases of the user name and the password, the original use cases are not required to be modified, and the test work is convenient. For example, a row of use case sentences is used for inputting # { user name }, the variable names are set as user names in advance through the variable module, and the variable values are set as userName, so that the natural language analysis module can directly obtain the variable values through the variable module, and the replacement of the "# { user name }" variables in the sentences is completed. The setting module is used for setting the application information to be tested of the automatic test, and comprises an application name to be tested, whether to restart the application to be tested when starting running, whether to open a floating window and the like. The test report module is used for generating a test report from the execution result of the test case or the execution set, and comprises a screen shot of each operation, wrong operation information, equipment information, case execution duration information and the like. .
The system also comprises a search module which is used for searching the test cases, the execution sets and the test reports and can search through keywords such as case names, execution set names, semantic names, variable names and the like.
The natural language analysis module is internally provided with a case interceptor group, the case interceptor group comprises a plurality of interceptors, each interceptor is composed of an interceptor rule, the interceptor rule corresponds to a grammar rule when the test case is written, when the natural language analysis module is used, each operation in the test case traverses all interceptors in the interceptor group, the interceptors corresponding to the conditions of the interceptors are searched, and the natural language in the operation is converted into a machine language through the searched interceptors.
The present invention is not limited to the above-mentioned embodiments, and any changes or substitutions that can be easily understood by those skilled in the art within the technical scope of the present invention are intended to be included in the scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.