Based on counter automated testing method and the test macro of uiautomator test frameTechnical field
The present invention relates to automatization testing technique field, particularly the system of a kind of counter automated testing method based on uiautomator test frame and application the method thereof.
Background technology
Automatic test has saving manpower, time, hardware resource, increases work efficiency and judge the advantages such as accuracy, and therefore, on the basis of traditional-handwork test, automatic test is just being introduced gradually in the test job of mobile terminal APP.For mobile phone calculator, the automated testing method of current main flow has based on the automatic test under Robotium framework, first application interface is carried out layering by it, carry out encoding and be compiled as can perform script according to the solo method that the various functions of correspondence calls in Robotium, imported in test machine, started automatic test; Then according to the test setting judging point of various functions, call screenshotss function and sectional drawing is carried out to test result; Finally the sectional drawing got and expected results are compared and verify, export test report; But the method to the differentiation of test result by call screenshotss function to result of calculation carry out after sectional drawing the later stage again people be that comparison differentiates, efficiency is low, not easily in a large number, repeatedly carry out the stability testing to ensure software.
Summary of the invention
The present invention, for solving the problem, provides a kind of counter automated testing method based on uiautomator test frame and test macro, automatically can calculate and automatic discrimination result mobile phone calculator.
For achieving the above object, the technical solution used in the present invention is:
Based on a counter automated testing method for uiautomator test frame, it comprises the following steps:
10. obtain the control property at the counter interface corresponding to project to be tested;
Control property described in 20. utilizations orients control element to be tested;
30. under uiautomator test frame, described control element is encapsulated as the component object that can uniquely identify;
Described component object is encoded by 40., and is compiled as can performs script according to project to be tested;
Performed script described in 50. startups carries out automatic test.
Preferably, in described step 10, obtain the control property at the counter interface corresponding to project to be tested, be obtain counter by uiautomatorviewer instrument each interface corresponding to project to be tested on all control properties.
Preferably, described control property is utilized to orient control element to be tested in described step 20, be to be identified control element to be tested by the mode of tag search according to described control property and locate, each control element is provided with corresponding control property and identification label.
Preferably, in described step 30, described control element being encapsulated as the component object that can uniquely identify, is the control title of described control element, control regions, control annotation information and control built-in attribute are carried out being encapsulated as the component object that can uniquely identify.
Preferably, in described step 40, after described component object is encoded, carry out being compiled as can perform script according to the testing procedure of project to be tested and test loop number of times.
Preferably, the project to be tested of described counter comprises one or more following combination: the display test of the mapping test of calculator panel button, data display field, check and remove calculate historical record test, the test of general panels and fundamental operation function, science panel and special calculation function test.
Preferably, carry out in described step 50 in automatic test course, automatically calculate, automatic acquisition result of calculation, automatic decision test result, and carry out automatic cycle testing according to the cycle index preset, finally generate test report.
Preferably, in described step 30, described control element is encapsulated as the component object that can uniquely identify, and the character string directly obtained for identifying this component object, in automatic test course, by the character string of this component object and the character string preset are carried out contrasting the judgement carrying out test result.
In addition, present invention also offers a kind of counter automatization test system based on uiautomator test frame, it comprises:
Control property acquisition module, for obtaining the control property at the counter interface corresponding to project to be tested;
Control element locating module, its utilize described in control property orient control element to be tested;
Component object package module, described control element is encapsulated as the component object that can uniquely identify by it under uiautomator test frame;
Step collector, described component object is encoded by it, and is compiled as can performs script according to project to be tested;
Automatic test module, carries out automatic test for starting described performed script.
Preferably, described control element is encapsulated as the component object that can uniquely identify by described component object package module, and the character string directly obtained for identifying this component object, carry out in automatic test course calling automatic test module, by the character string of this component object and the character string preset are carried out contrasting the judgement carrying out test result.
The invention has the beneficial effects as follows:
(1), automatically can calculate mobile phone calculator, automatic discrimination result, can test be repeated, ensure that test efficiently, is fully carried out, potential leak can be found better;
(2), adopt uiautomator test frame, test specification is wider, more convenient operation:
A, prior art adopt Robotium test frame can only carry out independent test for certain specific apk, and working range has limitation; The present invention adopts uiautomator test frame can carry out automatic test to all operations of whole system, and test specification is wider;
When using Robotium framework to test on simulator or prototype in b, prior art, must make test pack and tested bag into identical signature, this process relates to heavily signature and waits operation; And Robotium calls screenshotss function also needs a precondition: the access limit to SD card will be added in the AndroidManifest.xml of tested application; The present invention adopts uiautomator framework then without the need to the operation of so complicated prerequisite and restriction, more convenient operation;
(3) be, call screenshotss function to carry out sectional drawing to test key point to the judgement of result of calculation in prior art, then by the manpower comparing in later stage to judging; The present invention is by being encapsulated as the component object that can uniquely identify by described control element, and the character string directly obtained for identifying this component object, in automatic test course, by the character string of this component object and the character string preset are carried out contrasting the judgement carrying out test result, without the need to manual intervention, really realize automatic test, and test process does not take additional storage capacity;
(4), the control title of described control element, control regions, control annotation information and control built-in attribute carry out being encapsulated as the component object that can uniquely identify by the present invention, and information of its encapsulation is abundanter, and identity is better.
Accompanying drawing explanation
Accompanying drawing described herein is used to provide a further understanding of the present invention, forms a part of the present invention, and schematic description and description of the present invention, for explaining the present invention, does not form inappropriate limitation of the present invention.In the accompanying drawings:
Fig. 1 is the general flow chart of counter automated testing method of the present invention;
Fig. 2 is the structural representation of counter automatization test system of the present invention.
Embodiment
In order to make technical matters to be solved by this invention, technical scheme and beneficial effect clearly, understand, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
As shown in Figure 1, a kind of counter automated testing method based on uiautomator test frame of the present invention, it comprises the following steps:
10. obtain the control property at the counter interface corresponding to project to be tested;
Control property described in 20. utilizations orients control element to be tested;
30. under uiautomator test frame, described control element is encapsulated as the component object that can uniquely identify;
Described component object is encoded by 40., and is compiled as can performs script according to project to be tested;
Performed script described in 50. startups carries out automatic test.
Obtain the control property at the counter interface corresponding to project to be tested in described step 10, be obtain counter by uiautomatorviewer instrument each interface corresponding to project to be tested on all control properties.
Described control property is utilized to orient control element to be tested in described step 20, be to be identified control element to be tested by the mode of tag search according to described control property and locate, each control element is provided with corresponding control property and identification label.
In described step 30, described control element being encapsulated as the component object (UiObject) that can uniquely identify, is the control title (packagename) of described control element, control regions (bounds), control annotation information (content-desc) and control built-in attribute are carried out being encapsulated as the component object that can uniquely identify; And, by obtaining the character string for identifying this component object, in automatic test course, by the character string of this component object and the character string preset being carried out contrasting the judgement carrying out test result, whether the component object after can directly passing through to judge to have encapsulated exists just easily can realize checking.Such as, the long test by function, do not provide the long method touched the button in the Solo class of Robotium test frame of the prior art, need the coordinate first obtaining button, then length realizes by the transfer mode that coordinate is such, and step is complicated, and workload is large; The Uiautomator test frame that the present invention adopts then provides the method for operating to the nearly all needs of component object after encapsulate, presses function, only need UiObject.longClick () directly to realize as long, efficiently faster.
In described step 40, after described component object is encoded, carry out being compiled as can perform script according to the testing procedure of project to be tested and test loop number of times.
In described step 50, performed script after compiling is imported in test machine, use adbshell instruction or special Test Application just can start this can perform script and carry out automatic test, and carrying out in automatic test course, automatically calculate, automatic acquisition result of calculation, automatic decision test result, and carry out automatic cycle testing according to the cycle index preset, finally generate test report.The present invention can calculate mobile phone calculator and automatic discrimination test result each time automatically, after completing loop test number of times, automatically exports test report, without the need to manual intervention.
Wherein, the project to be tested of described counter comprises one or more following combination: the display test of the mapping test of calculator panel button, data display field, check and remove calculate historical record test, the test of general panels and fundamental operation function, science panel and special calculation function test.
As shown in Figure 2, present invention also offers a kind of counter automatization test system based on uiautomator test frame, it comprises:
Control property acquisition module A, for obtaining the control property at the counter interface corresponding to project to be tested;
Control element locating module B, its utilize described in control property orient control element to be tested;
Component object package module C, described control element is encapsulated as the component object that can uniquely identify by it under uiautomator test frame;
Step collector D, described component object is encoded by it, and is compiled as can performs script according to project to be tested;
Automatic test module E, carries out automatic test for starting described performed script.
In the present embodiment, described control element is encapsulated as the component object that can uniquely identify by described component object package module C, and the character string directly obtained for identifying this component object, carry out in automatic test course calling automatic test module E, by the character string of this component object and the character string preset are carried out contrasting the judgement carrying out test result.
Compared with automated testing method of the prior art, the present invention is simple to operate, after getting control property, just can encapsulate the script edit that unique discernible component object completes all functions test item, eliminate some complex operations required in Robotium test frame; Meanwhile, this method of testing can calculate automatically, automatic acquisition judge result of calculation, artificially contrasts sectional drawing without the need to the later stage, and can repeat, automatically exports test report.Therefore, the present invention can more efficiently, ensure the carrying out of test fully, improve and find the ability of potential leak, strengthen the stability of software, system.
It should be noted that, each embodiment in this instructions all adopts the mode of going forward one by one to describe, and what each embodiment stressed is the difference with other embodiments, between each embodiment identical similar part mutually see.For system class embodiment, due to itself and embodiment of the method basic simlarity, so description is fairly simple, relevant part illustrates see the part of embodiment of the method.And, in this article, term " comprises ", " comprising " or its any other variant are intended to contain comprising of nonexcludability, thus make to comprise the process of a series of key element, method, article or equipment and not only comprise those key elements, but also comprise other key elements clearly do not listed, or also comprise by the intrinsic key element of this process, method, article or equipment.When not more restrictions, the key element limited by statement " comprising ... ", and be not precluded within process, method, article or the equipment comprising described key element and also there is other identical element.In addition, one of ordinary skill in the art will appreciate that all or part of step realizing above-described embodiment can have been come by hardware, the hardware that also can carry out instruction relevant by program completes, described program can be stored in a kind of computer-readable recording medium, the above-mentioned storage medium mentioned can be ROM (read-only memory), disk or CD etc.
Above-mentioned explanation illustrate and describes the preferred embodiments of the present invention, be to be understood that the present invention is not limited to the form disclosed by this paper, should not regard the eliminating to other embodiments as, and can be used for other combinations various, amendment and environment, and can in invention contemplated scope herein, changed by the technology of above-mentioned instruction or association area or knowledge.And the change that those skilled in the art carry out and change do not depart from the spirit and scope of the present invention, then all should in the protection domain of claims of the present invention.