The positioning system of browser page element and method and automated testing method thereof
Technical field
The present invention relates to automatic test field, particularly relate to a kind of positioning system of browser page element and method and automated testing method thereof.
Background technology
At present; all need to use some testing tools in a lot of automatic test; such as in the test to page elements content, often can use this automated test tool of RobotFramework; for this kind of testing tool of RobotFramework, need the positioning result of input to browser page element.Current way is, manually goes to search in the source code of page front end, captures out corresponding element positioning result in the source code of front end, and is input in testing tool by the element positioning result captured out.This mode not only needs a large amount of human costs, inefficiency, and the accuracy obtaining element locating content is low, easily causes the inaccurate problem of test result.
Summary of the invention
For problems of the prior art, the invention provides a kind of positioning system of browser page element and method and automated testing method thereof, can accurately locate the element of browser page accurately, more quick and easy when using RobotFramework to write test script, and effectively improve the efficiency of compile script.
The present invention adopts following technical scheme:
A localization method for browser page element, described localization method comprises:
Location Request is produced according to the operation of page elements;
Resolve according to the front end source code of described Location Request to the page, and obtain the locating content of page elements corresponding in the source code of described front end;
The described locating content obtained is combined, and produces the positioning result of described page elements.
Preferably, comprised before the step of Location Request is produced to the operation of page elements:
Preset the definition vocabulary that comprises multiple defined terms, at least corresponding described Location Request of each described defined terms;
Resolve according to the front end source code of described Location Request to the page, and the step obtaining the locating content of page elements corresponding in the source code of described front end specifically comprises:
Described defined terms corresponding in described definition vocabulary is obtained according to described Location Request;
Described defined terms according to obtaining is resolved described front end source code, obtains content corresponding with described defined terms in the source code of described front end, and using the described content of acquisition as described page elements locating content.
Preferably, the step that the described page elements locating content obtained carries out combining specifically is comprised: the corresponding content obtained from the source code of described front end according to described defined terms is integrated.
Preferably, in described method, described defined terms comprises: address and/or title and/or path and/or route text.
Preferably, the described locating content obtained is combined, and also comprises after producing the step of the positioning result of described page elements: the positioning result showing described page elements.
A positioning system for browser page element, is characterized in that, be applied in the page elements position fixing process of automatic test, described positioning system comprises:
Task start module, according to producing the operation of page elements and sending Location Request;
Main program module, with described task start model calling, resolves according to the front end source code of described Location Request to the page, and obtains the locating content of page elements corresponding in the source code of described front end;
Processing module, is connected with described main program module, is combined by the locating content of the described page elements obtained, produces the positioning result of described page elements.
Preferably, described positioning system also comprises:
Definition memory module, store a definition vocabulary, described definition vocabulary comprises multiple defined terms, and at least corresponding described Location Request of each defined terms;
Described main program module comprises:
Defined terms acquiring unit, obtains defined terms corresponding in described definition vocabulary according to described Location Request;
Resolution unit, the described defined terms according to obtaining is resolved described front end source code, and obtains content corresponding with described defined terms in the source code of described front end, and using the content of acquisition as element locating content.
Preferably, the described locating content of the correspondence obtained from the source code of described front end according to described defined terms is integrated by described processing module, obtains described positioning result.
Preferably, the positioning system of described browser page element also comprises:
Display module, is connected with described processing module, shows the positioning result of described page elements.
A kind of automated testing method, described automated testing method comprises:
Be matched in testing tool by above-mentioned positioning result according to described Location Request, described testing tool carries out automatic test according to described positioning result.
The invention has the beneficial effects as follows:
The present invention is after unlatching native system, as long as the page elements of user to browser operates, a button small icon will be ejected in side, now click this button small icon and will eject a display box, it is exactly its element positioning result in display box, this location mechanism has very large effect for compile script in automatic test, such as the most frequently used at present RobotFramework automated test frame, just need when writing case to carry out element location, existing location mechanism is or can not satisfies the demands, some problems that the present invention exists in effectively solving and locating at present, substantially increase testing efficiency.
Accompanying drawing explanation
Fig. 1 is the structural representation of the positioning system of a kind of browser page element of the present invention;
Fig. 2 is the corresponding relation figure in main program module of the present invention between Location Request and locating content;
Fig. 3 is the schematic diagram of the localization method of browser page element of the present invention.
Embodiment
It should be noted that, when not conflicting, following technical proposals, can combine between technical characteristic mutually.
Below in conjunction with accompanying drawing, the specific embodiment of the present invention is further described:
Embodiment one
As shown in Figure 1, present embodiments provide the method for a kind of browser page element location, the present embodiment is mainly used in the process positioned browser page element, when user operates at browser page element, user can obtain the prompting of an inquiry property afterwards, namely confirm whether producing Location Request, if user confirms to produce Location Request, then task start module produces Location Request, this Location Request can be an instruction, and the content of instruction can be mainly the value obtaining defined terms in Location Request.Wherein, page elements can be the content of the display such as word, picture on browser page, the operation that user carries out can be the word and/or picture etc. chosen in browser, the positioning system of the browser page element in the present embodiment, can comprise: task start module, main program module, processing module.
First, the operation of the page elements that task start module can be selected according to user produces and sends Location Request, application scenarios can be: user selectes certain section of word of a browser page, browser page ejects the icon whether send Location Request more afterwards, and user can carry out click to this icon and confirm produce and send Location Request, main program module, can with task start model calling, resolve according to the front end source code of Location Request to the page, and obtain the locating content of page elements corresponding in the source code of described front end, the main resolving of task start module is: before carrying out resolving, have a definition memory module to be pre-stored with a definition vocabulary, this definition vocabulary comprises multiple defined terms, and defined terms acquiring unit can obtain defined terms corresponding in this definition vocabulary according to Location Request after at least corresponding Location Request of each defined terms, described front end source code is resolved according to the defined terms obtained by resolution unit again, and obtain content corresponding with described defined terms in the source code of front end, and using the content of acquisition as element locating content.Acquisition defined terms is eliminated in Fig. 2, and according to the process of defined terms determination locating content, as commend (Location Request) hurdle input in 2 is the instruction of Location Request, and Target (object content) hurdle is namely by locating content that above-mentioned resolving obtains, such as, the first row in Fig. 2, click both can be the instruction of Location Request, can determine in above-mentioned definition vocabulary that defined terms corresponding to this instruction of click is link according to the such positioning instruction of click, resolution unit is resolved front end source code according to the defined terms link obtained, obtaining locating content is summary.But the defined terms in the present embodiment is not limited to limit in table, can add as the case may be.
Processing module is connected with main program module, is combined by the locating content of the page elements of acquisition, produces the positioning result of page elements.In the present invention's preferred embodiment, locating content is integrated by processing module, obtains positioning result.In the above embodiments, the locating content obtained can simply be enumerated by processing module, is integration, enumerates be combination if need to carry out the conversion such as arrangement restructuring.After locating content processes by processing module, both can obtain positioning result, positioning result can be shown by a display module, and display module, is connected with processing module, can the positioning result of display page element.
Embodiment two
As shown in Figure 3, based on above-mentioned system, present embodiments provide a kind of localization method of browser page element, the concrete steps of this localization method comprise: first preset the definition vocabulary that comprises multiple defined terms, the at least corresponding Location Request of each defined terms, namely Location Request and a defined terms have corresponding relation, user can operate page elements afterwards, Location Request can be produced according to the operation of page elements, preferably, whether can be produced the process of request by an inquiry before producing Location Request, if user confirms, then request can be produced.As shown in Figure 3, the page elements of user Quan Xuan or the required location of click, start above-mentioned positioning system afterwards, the side of the page elements chosen there will be icon, clicks the icon that side occurs, confirmation produces Location Request.
Browser backstage responds according to the front end source code of Location Request to the page, resolves, and obtain the locating content of page elements corresponding in the source code of front end, above-mentioned steps is specifically as follows and obtains defined terms corresponding in definition vocabulary according to Location Request, this defined terms can for resolving front end source code according to the defined terms obtained, obtain content corresponding with defined terms in the source code of front end, and using the content of acquisition as page elements locating content.Wherein defined terms can comprise: address (ID) and/or title (name) and/or path (xpath) and/or route text (linktext).But defined terms is not limited to above-mentioned enumerating, can carry out as the case may be adding or selecting.
Afterwards, browser is inner to be combined the described locating content obtained, and produces the positioning result of described page elements.Wherein combination can be to operations such as locating content rearrange.Preferably, the locating content obtained from the source code of front end according to defined terms is carried out integration process, integration can be simply enumerate, and does not need to carry out sorting etc. step.Afterwards positioning result is fed back, the positioning result of display page element in text box.
Embodiment three
The automatic test that the present embodiment carries out based on the system and method for above-described embodiment one and embodiment two, positioning result can be obtained according to above-mentioned system and method, no longer the step obtaining positioning result is repeated herein, after obtaining positioning result, positioning result coupling can be inputed in testing tool according to Location Request, in testing tool, Location Request can a corresponding positioning result, and testing tool carries out automatic test according to positioning result more afterwards.
In sum, the present invention is after unlatching native system, as long as the page elements of user to browser operates, a button small icon will be ejected in side, now click this button small icon and will eject a display box, it is exactly its element positioning result in display box, this location mechanism has very large effect for compile script in automatic test, such as the most frequently used at present RobotFramework automated test frame, just need when writing case to carry out element location, existing location mechanism is or can not satisfies the demands, some problems that the present invention exists in effectively solving and locating at present, substantially increase testing efficiency.
By illustrating and accompanying drawing, giving the exemplary embodiments of the ad hoc structure of embodiment, based on the present invention's spirit, also can do other conversion.Although foregoing invention proposes existing preferred embodiment, but these contents are not as limitation.
For a person skilled in the art, after reading above-mentioned explanation, various changes and modifications undoubtedly will be apparent.Therefore, appending claims should regard the whole change and correction of containing true intention of the present invention and scope as.In Claims scope, the scope of any and all equivalences and content, all should think and still belong to the intent and scope of the invention.