Color system and method are distinguished in a kind of automation for ui testing
Technical field
The present invention relates to ui testing fields, and in particular to a kind of automation for ui testing is distinguished
Color system and method.
Background technique
Current Android system version updating is getting faster, and version function interface also becomes increasingly complex, and is had many tiny
The color of control and element can not distinguish, manually distinguish that colour efficiency is low by traditional, and be unable to judge accurately.
In existing Android system automatic test, by screenshot capture, picture color comparison is carried out.By Android system
When operation, the point needed carries out screenshot capture and the comparison of original Target Photo.The method has certain error, and efficiency
It is lower.
Summary of the invention
The purpose of the present invention is to provide a kind of automations for ui testing to distinguish color system and method to improve
Have the defects that 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, comprising:
Control color reflective module, for obtaining control color standard value from source code using reflection mechanism;
Number distinguishes color module, for compare running control color value and the control color standard value.
Preferably, the control color reflective module includes:
Control color attribute adding unit, is added to the control property of acquisition for the control color attribute by control to be measured
In;
Control property reflector element is obtained described to be measured for being reflected the control property using the reflection mechanism
The color attribute value of control;
Attribute lead-out unit, for digitizing to obtain the control color standard value for the color attribute value, and by institute
It states after control color standard value is aggregated into control property recording documents and exports.
Preferably, the control color attribute adding unit 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 incoming required control color attribute obtained, and imports and inherits institute
State encapsulation class;
It is associated with subelement, for being associated with 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;
Subelement is reflected, for reflecting the root node using the reflection mechanism, finds the described of the control to be measured
Color attribute value.
Preferably, when the color value of running control and the control color standard value difference, script is prompted
Run-time error.
The embodiment of the present invention also provides a kind of automation for ui testing and distinguishes color method, comprising:
Control color standard value is obtained from source code using reflection mechanism;And
Compare running control color value and the control color standard value
Preferably, the step of control color standard value is obtained from source code using reflection mechanism when making script
Suddenly include:
The control color attribute of control to be measured is added in the control property of acquisition;
The control property is reflected using the reflection mechanism to obtain the color attribute value of the control to be measured;And
The color attribute value is digitized to obtain the control color standard value, and the control color standard value is converged
It is total to exporting after control property recording documents.
Preferably, the control color attribute of control to be measured is added to the step 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 and inherit the encapsulation class;And
It is associated with the control color attribute and the encapsulation class.
Preferably, the control property is reflected using the reflection 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 reflection mechanism, finds the color attribute value of the control to be measured.
Preferably, when the color value of running control and the control color standard value difference, script is prompted
Run-time error.
Color system and method are distinguished in the automation for ui testing provided through the invention, when making script,
Using JAVA reflection mechanism, precisely reflected from Code Design program, to obtain the color attribute of the control in script, and
It is digitized;As a result, at runtime, compared using digitized control color standard value with running control information
It is right, can find whether the color of running control is correct.It is reflected by source code and obtains control color value, there is no miss
Difference;It is compared, is can be improved to specific efficiency by digitlization.
Detailed description of the invention
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below
There is attached drawing needed in technical description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this
Some embodiments of invention for those of ordinary skill in the art without creative efforts, can be with
It obtains other drawings based on these drawings.
Fig. 1 is the schematic diagram that colour system system is distinguished in the automation for ui testing that first embodiment of the invention provides.
Fig. 2 is the schematic diagram that colour system system is distinguished in the automation for ui testing that second embodiment of the invention provides.
Fig. 3 is the process signal that color method is distinguished in the automation for ui testing that third embodiment of the invention provides
Figure.
Specific embodiment
In order to make the objectives, technical solutions, and advantages of the present invention clearer, with reference to the accompanying drawings and embodiments, right
The present invention is further elaborated.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, and
It is not used in the restriction present invention.
Embodiment one
Fig. 1 is the schematic diagram that colour system system is distinguished in the automation for ui testing that first embodiment of the invention provides.
As shown in Figure 1, the automation for ui testing distinguishes that colour system system includes that control color reflective module 10 and number distinguish color mould
Block 20.Wherein, the control color reflective module 10 is used to obtain control color standard from source code using reflection mechanism
Value;The digital color distinguish color module 20 for compare running control color value and the control color standard value.Tool
Body obtains using JAVA reflection mechanism the control color standard value of the control in script when making script;At runtime
The control color standard value and running control information are compared, if the running control information and the control face
Colour standard value is different, then prompts script run-time error.
JAVA reflection mechanism is, for any one class, can to know all properties of this class in operating status
And method;For any one object, its any one method and attribute can be called;The information of this dynamic acquisition with
And the function of the method for dynamic call object is known as the reflection mechanism of java language.
The automation for ui testing provided through this embodiment distinguishes that colour system is united, and when making script, utilizes
JAVA reflection mechanism is precisely reflected from Code Design program, with the color attribute of the control in script, and carries out number
Change, obtains control color standard value;At runtime, using digitized control color standard value and running control information into
Row compares, and can find whether the color of running control is correct.It is reflected by source code and obtains control color value, be not present
Error;It is compared, is can be improved to specific efficiency by digitlization.
Embodiment two
Fig. 2 is the schematic diagram that colour system system is distinguished in the automation for ui testing that second embodiment of the invention provides.
As shown in Fig. 2, the automation for ui testing distinguishes that colour system system includes for utilizing reflection mechanism from source generation
Code in come obtain control color standard value control color reflective module 10 and the color value for comparing running control and
The number 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 unit 11, for the control color attribute of control to be measured to be added to the control category of acquisition
In property;
Control property reflector element 12, obtained for reflecting the control property using the reflection mechanism it is described to
The color attribute value of observing and controlling part;
Attribute lead-out unit 13 obtains the control color standard value for digitizing the color attribute value, and will
The control color standard value exports after being aggregated into control property recording documents.
In android exploitation, it is added various controls in the interface Activity layout, such as Button,
ImageView etc., each control can have each attribute, coordinate position, include class name, font content, color attribute etc..
We here seek to add a color category in the attribute obtained by Android automated test tool uiautomator
Property.
Therefore, in the present embodiment, the control color attribute adding unit 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, however obtain these attributes
In, have no control color (Activity Color) this attribute.
Control property imports subelement 112, for the incoming required control color attribute obtained, and imports succession
The encapsulation class;
Specifically, after choosing some Activity control, the control property of acquisition required for being passed to
BackgroundColor, and the encapsulation class of the uiautomator in SDK is imported, and inherit such.
It is associated with subelement 113, for being associated with the control color attribute and the encapsulation class;
Specifically, the control color attribute and the encapsulation class are associated with using UiObject class.UiObject class is
A parent (containing the class of all android control informations) of uiautomator, by BackgroundColor attribute
After importing, control color attribute and uiautomator encapsulation class are connected using UiObject class.
Further, in the present embodiment, the control property reflector element 12 includes:
Root node locator unit 121, for utilizing the root node for positioning the control to be measured from the localization method;
Specifically, it is associated with by previous step, is come from the QueryController of the encapsulation Similar integral of uiautomator
AccessibilityNodeInfo method is obtained, which can be positioned by AccessibilityNodeInfo method, obtained
The root node of control is specified to user.
Subelement 122 is reflected, for reflecting the root node using the reflection 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 object finds out user by reflecting AccessibilityNodeInfo root node
The color attribute of required control.
Further, after the color attribute value of the control needed for finding user, attribute lead-out unit 13 is digitized,
Then (documents of all control properties of uiautomator interface record) are aggregated into window_dump.xml file.?
In android system, each page can all generate a window_dump.xml attribute, and it is all to record the current interface UI
Control property.Summarized by previous, has the color attribute value of control in window_dump.xml file, in this way, running
When, the control color standard value of needs can be directly acquired by control property recording documents.
Further, the color attribute of control has been recorded, has been obtained when making script by control color reflective module 10
To digitized control color standard value (for example, 0*FFFF00);At runtime, number distinguishes that color module 20 can be according to control face
Whether colour standard value goes comparison identical with running color, prompts to generate if different abnormal.
Advantageously, the automation for ui testing provided through this embodiment distinguishes that colour system is united, in production script
When, it using JAVA reflection mechanism, is precisely reflected from Code Design program, to obtain the color category of the control in script
Property, digitized of going forward side by side;As a result, at runtime, using digitized control color standard value and running control information into
Row compares, and can find whether the color of running control is correct.It is reflected by source code and obtains control color value, be not present
Error;It is compared, is can be improved to specific efficiency by digitlization.
Embodiment three
Fig. 3 is the process signal that color method is distinguished in the automation for ui testing that third embodiment of the invention provides
Figure.As shown in figure 3, for ui testing automation distinguish color method the following steps are included:
Step S1: control color standard value is obtained from source code using reflection mechanism;
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 control property is reflected using the reflection mechanism to obtain the color category of the control to be measured
Property value;And
Step S13: digitizing to obtain the control color standard value for the color attribute value, and by the control color
Standard value exports after being aggregated into control property recording documents.
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 and inherit the encapsulation class;And
Step S113: the control color attribute and the encapsulation class are associated with.
Further, step S12 includes following sub-step:
Step S121: the root node that the control to be measured is positioned from the localization method of the encapsulation Similar integral is utilized;And
Step S122: the root node is reflected using the reflection mechanism, finds the color category of the control to be measured
Property value.
Step S2: compare running control color value and the control color standard value.
Further, when the color value of running control and the control color standard value difference, foot is prompted
This run-time error.
Specifically, in the present embodiment, after choosing some Activity control, the control category of acquisition required for being passed to
Property BackgroundColor, and import the encapsulation class of the uiautomator in SDK, and inherit such;By BackgroundColor
After attribute imports, control color attribute and uiautomator encapsulation class are connected using UiObject class;Pass through previous step
Rapid association can obtain inheriting the AccessibilityNodeInfo method of coming from uiautomator, can obtain the specified control of user
The root node of part (control can be positioned by it);With from uiautomator obtain inherit come QueryController obtain
AccessibilityNodeInfo root node object finds out user by reflecting AccessibilityNodeInfo root node
The color attribute of required control;It after the color attribute value of the control needed for finding user, is digitized, is then aggregated into
In window_dump.xml file;Summarized by previous, has the color attribute of control in window_dump.xml file
Value, in this way, at runtime, the control color standard value of needs can be directly acquired by control property recording documents.
Advantageously, color method is distinguished in the automation for ui testing provided through this embodiment, in production script
When, it using JAVA reflection mechanism, is precisely reflected from Code Design program, to obtain the color category of the control in script
Property, digitized of going forward side by side;As a result, at runtime, using digitized control color standard value and running control information into
Row compares, and can find whether the color of running control is correct.It is reflected by source code and obtains control color value, be not present
Error;It is compared, is can be improved to specific efficiency by digitlization.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all in essence of the invention
Made any modifications, equivalent replacements, and improvements etc., should all be included in the protection scope of the present invention within mind and principle.