Color system and method are distinguished in a kind of automation for ui testing
Technical field
The present invention relates to ui testing field, and more particularly to a kind of automation for ui testing is distinguished
Color system and method.
Background technology
Current Android system version updating is more and more faster, and version function interface also becomes increasingly complex, and has many tiny
The color of control and element cannot distinguish that colour efficiency is low by traditional manually distinguishing, and cannot accurately judge.
In existing Android system automatic test, by screenshot capture, picture color contrast is carried out.By Android system
During operation, the point position of needs carries out screenshot capture, and the contrast of original Target Photo.The method has certain error, and efficiency
It is relatively low.
The content of the invention
It is an object of the invention to provide a kind of automation for ui testing distinguishes color system and method to improve
There is the defect of error and inefficiency in existing picture control methods.
The embodiment of the present invention provides a kind of automation for ui testing and distinguishes that colour system is united, including:
Control color reflective module, for obtaining control color standard value from source code using reflex mechanism;
Numeral distinguishes color module, for contrasting the color value and the control color standard value of operating control.
Preferably, the control color reflective module includes:
Control color attribute adding device, for the control color attribute of control to be measured to be added to the control property of acquisition
In;
Control property reflector element, it is described to be measured to obtain for reflecting the control property using the reflex mechanism
The color attribute value of control;
Attribute lead-out unit, for color attribute value digitlization to be obtained into the control color standard value, and by institute
State control color standard value and be aggregated into derivation after control property recording documents.
Preferably, the control color attribute adding device includes:
Control property obtains subelement, for obtaining the control category by the encapsulation class of Android automated test tool
Property;
Control property imports subelement, for the control color attribute of incoming required acquisition, and imports succession institute
State encapsulation class;
Association subelement, for associating the control color attribute and the encapsulation class.
Preferably, the control property reflector element includes:
Root node locator unit, for positioning the control to be measured using the localization method from the encapsulation Similar integral
Root node;
Reflection subelement, for reflecting the root node using the reflex mechanism, finds the described of the control to be measured
Color attribute value.
Preferably, when the color value of operating control is different with the control color standard value, script is pointed out
Run-time error.
The embodiment of the present invention also provides a kind of automation for ui testing and distinguishes color method, including:
Control color standard value is obtained using reflex mechanism from source code;And
Contrast the color value and the control color standard value of operating control.
Preferably, when script is made using reflex mechanism from source code obtaining the step of control color standard value
Suddenly include:
The control color attribute of control to be measured is added in the control property of acquisition;
Reflect the control property using the reflex mechanism to obtain the color attribute value of the control to be measured;And
Color attribute value digitlization is obtained into the control color standard value, and the control color standard value is converged
Always derive to after control property recording documents.
Preferably, the step control color attribute of control to be measured being added in the control property of acquisition includes:
The control property is obtained by the encapsulation class of Android automated test tool;
The control color attribute obtained required for incoming, and import the succession encapsulation class;And
Associate the control color attribute and the encapsulation class.
Preferably, the control property is reflected using the reflex mechanism to obtain the color attribute of the control to be measured
The step of value includes:
The root node of the control to be measured is positioned using the localization method from the encapsulation Similar integral;And
The root node is reflected using the reflex mechanism, the color attribute value of the control to be measured is found.
Preferably, when the color value of operating control is different with the control color standard value, script is pointed out
Run-time error.
Color system and method are distinguished by the automation provided by the present invention for ui testing, when script is made,
Using JAVA reflex mechanisms, precisely reflected from Code Design program, to obtain script in control color attribute, and
It is digitized;Thus, operationally, compared using digitized control color standard value and operating control information
It is right, you can to find whether the color of operating control is correct.Control color value is obtained by source code reflection, there is no mistake
Difference;By digitizing contrast, can improve to specific efficiency.
Description of the drawings
In order to be illustrated more clearly that the embodiment of the present invention or technical scheme of the prior art, below will be to embodiment or existing
The accompanying drawing to be used needed for having technology description is briefly described, it should be apparent that, drawings in the following description are only this
Some embodiments of invention, for those of ordinary skill in the art, on the premise of not paying creative work, can be with
Other accompanying drawings are obtained according to these accompanying drawings.
Fig. 1 distinguishes the schematic diagram that colour system is united for the automation for ui testing that first embodiment of the invention is provided.
Fig. 2 distinguishes the schematic diagram that colour system is united for the automation for ui testing that second embodiment of the invention is provided.
Fig. 3 distinguishes that the flow process of color method is illustrated for the automation for ui testing that third embodiment of the invention is provided
Figure.
Specific embodiment
In order that the objects, technical solutions and advantages of the present invention become more apparent, it is right below in conjunction with drawings and Examples
The present invention is further elaborated.It should be appreciated that specific embodiment described herein is only to explain the present invention, and
It is not used in the restriction present invention.
Embodiment one
Fig. 1 distinguishes the schematic diagram that colour system is united for the automation for ui testing that first embodiment of the invention is provided.
As shown in figure 1, the automation for ui testing distinguishes that colour system system includes that control color reflective module 10 and numeral distinguish color mould
Block 20.Wherein, the control color reflective module 10 is used to obtain control color standard from source code using reflex mechanism
Value;The digital color distinguishes color module 20 for contrasting the color value and the control color standard value of operating control.Tool
Body ground, make script when using JAVA reflex mechanisms to obtain script in control control color standard value;Operationally
The control color standard value and operating control information are contrasted, if the operating control information and the control face
Colour standard value is different, then point out script run-time error.
JAVA reflex mechanisms are in running status, for any one class, can to know all properties of this class
And method;For any one object, its any one method and attribute can be called;The information of this dynamic access with
And the function of the method for dynamic call object is referred to as the reflex mechanism of java language.
The automation for ui testing provided by the present embodiment distinguishes that colour system is united, and when script is made, utilizes
JAVA reflex mechanisms, are precisely reflected from Code Design program, with the color attribute of the control in script, and carry out numeral
Change, obtain control color standard value;Operationally, entered using digitized control color standard value and operating control information
Row is compared, you can find whether the color of operating control is correct.Control color value is obtained by source code reflection, is not existed
Error;By digitizing contrast, can improve to specific efficiency.
Embodiment two
Fig. 2 distinguishes the schematic diagram that colour system is united for the automation for ui testing that second embodiment of the invention is provided.
As shown in Fig. 2 for ui testing automation distinguish colour system system include for using reflex mechanism from source generation
Code in come obtain control color standard value control color reflective module 10 and for contrast operating control color value and
The numeral of the control color standard value distinguishes color module 20.
Specifically, in the present embodiment, control color reflective module 10 includes:
Control color attribute adding device 11, the control for the control color attribute of control to be measured to be added to acquisition belongs to
In property;
Control property reflector element 12, for reflecting the control property using the reflex mechanism to obtain described treating
The color attribute value of observing and controlling part;
Attribute lead-out unit 13, for color attribute value digitlization to be obtained into the control color standard value, and will
The control color standard value is aggregated into after control property recording documents and derives.
In android exploitations, be added various controls in Activity layout interfaces, such as Button,
ImageView etc., each control can have each attribute, coordinate position, comprising class name, font content, color attribute etc..
We here seek to one color category of addition in the attribute obtained by Android automated test tool uiautomator
Property.
Therefore, in the present embodiment, the control color attribute adding device 11 includes:
Control property obtains subelement 111, for obtaining the control by the encapsulation class of Android automated test tool
Attribute;
Specifically, by the encapsulation class of uiautomator carry out obtain control attribute, but obtain these attributes
In, have no control color (Activity Color) this attribute.
Control property imports subelement 112, for the control color attribute of incoming required acquisition, and imports succession
The encapsulation class;
Specifically, after some Activity control is chosen, the incoming required control property for obtaining
BackgroundColor, and the encapsulation class of uiautomator in SDK is imported, and inherit such.
Association subelement 113, for associating the control color attribute and the encapsulation class;
Specifically, the control color attribute and the encapsulation class are associated using UiObject classes.UiObject classes are
One parent (containing the class of all of android control informations) of uiautomator, by BackgroundColor attributes
After importing, control color attribute and uiautomator encapsulation class are connected using UiObject classes.
Further, in the present embodiment, the control property reflector element 12 includes:
Root node locator unit 121, for using the root node that the control to be measured is positioned from the localization method;
Specifically, associated by previous step, come from the QueryController of the encapsulation Similar integral of uiautomator
AccessibilityNodeInfo methods are obtained, the control can be positioned by AccessibilityNodeInfo methods, obtained
The root node of control is specified to user.
Reflection subelement 122, for reflecting the root node using the reflex mechanism, finds the institute of the control to be measured
State color attribute value.
Specifically, with from uiautomator obtain inherit come QueryController obtain
AccessibilityNodeInfo root node objects, by reflecting AccessibilityNodeInfo root nodes, find out user
The color attribute of required control.
Further, after the color attribute value of the control needed for user is found, attribute lead-out unit 13 is digitized,
Then it is aggregated in window_dump.xml files (document of all control properties of uiautomator interface records).
In android system, each page can all generate a window_dump.xml attribute, record current UI interfaces all of
Control property.Collected by previous, the color attribute value of existing control in window_dump.xml files, so, in operation
When, the control color standard value that control property recording documents direct access needs can be passed through.
Further, by control color reflective module 10, when script is made, the color attribute of control has been recorded, has been obtained
To digitized control color standard value (for example, 0*FFFF00);Operationally, numeral distinguishes that color module 20 can be according to control face
Whether colour standard value goes contrast identical with operating color, points out to produce exception if difference.
Advantageously, the automation for ui testing for being provided by the present embodiment distinguishes that colour system is united, and is making script
When, using JAVA reflex mechanisms, precisely reflected from Code Design program, to obtain script in control color category
Property, and be digitized;Thus, operationally, entered using digitized control color standard value and operating control information
Row is compared, you can find whether the color of operating control is correct.Control color value is obtained by source code reflection, is not existed
Error;By digitizing contrast, can improve to specific efficiency.
Embodiment three
Fig. 3 distinguishes that the flow process of color method is illustrated for the automation for ui testing that third embodiment of the invention is provided
Figure.As shown in figure 3, the automation for ui testing distinguishes that color method is comprised the following steps:
Step S1:Control color standard value is obtained using reflex mechanism from source code;
Specifically, in the present embodiment, step S1 includes following sub-step:
Step S11:The control color attribute of control to be measured is added in the control property of acquisition;
Step S12:The color that the control property is reflected using the reflex mechanism to obtain the control to be measured is belonged to
Property value;And
Step S13:Color attribute value digitlization is obtained into the control color standard value, and by the control color
Standard value is aggregated into after control property recording documents and derives.
Further, step S11 includes following sub-step:
Step S111:The control property is obtained by the encapsulation class of Android automated test tool;
Step S112:The control color attribute obtained required for incoming, and import the succession encapsulation class;And
Step S113:Associate the control color attribute and the encapsulation class.
Further, step S12 includes following sub-step:
Step S121:The root node of the control to be measured is positioned using the localization method from the encapsulation Similar integral;And
Step S122:The root node is reflected using the reflex mechanism, the color category of the control to be measured is found
Property value.
Step S2:Contrast the color value and the control color standard value of operating control.
Further, when the color value of operating control is different with the control color standard value, pin is pointed out
This run-time error.
Specifically, in the present embodiment, after some Activity control is chosen, the incoming required control category for obtaining
Property BackgroundColor, and import the encapsulation classes of the uiautomator in SDK, and inherit such;By BackgroundColor
After attribute is imported, control color attribute and uiautomator encapsulation class are connected using UiObject classes;By previous step
Rapid association, can obtain inheriting the AccessibilityNodeInfo methods of coming from uiautomator, can obtain user and specify control
The root node (control can be positioned by it) of part;With from uiautomator obtain inherit come QueryController obtain
AccessibilityNodeInfo root node objects, by reflecting AccessibilityNodeInfo root nodes, find out user
The color attribute of required control;After the color attribute value of the control needed for user is found, digitized, be then aggregated into
In window_dump.xml files;Collected by previous, the color attribute of existing control in window_dump.xml files
Value, so, operationally, can pass through the control color standard value that control property recording documents direct access needs.
Advantageously, color method is distinguished in the automation for ui testing for being provided by the present embodiment, is making script
When, using JAVA reflex mechanisms, precisely reflected from Code Design program, to obtain script in control color category
Property, and be digitized;Thus, operationally, entered using digitized control color standard value and operating control information
Row is compared, you can find whether the color of operating control is correct.Control color value is obtained by source code reflection, is not existed
Error;By digitizing contrast, can improve to specific efficiency.
Presently preferred embodiments of the present invention is the foregoing is only, not to limit the present invention, all essences in the present invention
Any modification, equivalent and improvement made within god and principle etc., should be included within the scope of the present invention.