Disclosure of Invention
The invention mainly solves the technical problem of providing a method and a system for testing the compatibility of multiple browsers, which can reduce the workload of manual testing and improve the working efficiency.
In order to solve the technical problems, the invention adopts a technical scheme that: the method for testing the compatibility of the multiple browsers comprises the steps of configuring an operating browser and at least one testing browser; recording the operation behavior of testing the webpage elements in the operation browser in the process of testing the operation browser, and generating an operation instruction; synchronizing the operating instructions to the test browser; simulating the operation behavior on the test browser according to the operation instruction, and recording execution result information generated when the operation behavior is simulated on the test browser; judging whether the execution result information contains error information or not; and if the synchronous test browser contains error information, carrying out error processing according to the error information so as to ensure that the simulation test on the synchronous test browser is completely finished.
Wherein the step of performing error processing according to the error information includes: searching for an error code corresponding to the error information; if the error code is found, searching an error processing model corresponding to the error code; and if the error processing model is found, performing error processing according to the error processing model.
Wherein the error information comprises errors caused by a UI interface; the error processing model comprises switching positioning objects, repositioning web page elements related to operation behaviors and executing again.
The operation instruction comprises a webpage element number, a webpage element coordinate value and a tree bit code of the webpage element, wherein the tree bit code is a number mapped to a tree by each webpage element in a webpage in the browser; the switching positioning object, and the repositioning the webpage elements related to the operation behavior comprise: and if the positioning of the webpage element according to the coordinate value fails, positioning the webpage element according to the corresponding tree bit code, or if the positioning of the webpage element according to the tree bit code fails, positioning the webpage element according to the corresponding coordinate value.
Wherein the step of configuring the operating browser and the at least one test browser comprises: and configuring the operation browser on the operation test equipment, and configuring the at least one test browser on at least one synchronous test equipment, wherein the operation browser and the synchronous test browser are different browsers.
In order to solve the technical problem, the invention adopts another technical scheme that: the multi-browser compatibility testing system comprises operation testing equipment and at least one synchronous testing equipment, wherein the operation testing equipment is provided with an operation browser, and the synchronous testing equipment is provided with a synchronous testing browser; the operation test equipment comprises a record generation module and a synchronization module; the record generating module is used for recording the operation behavior of testing the webpage elements in the operation browser in the process of testing the operation browser and generating an operation instruction; the synchronization module is used for synchronizing the operation instruction to the synchronous test equipment; the synchronous test equipment comprises a receiving module, a simulation module, a recording module, a judgment module and an error processing module; the receiving module is used for receiving the operation instruction; the simulation module is used for simulating the operation behavior in the synchronous test browser according to the operation instruction; the recording module of the synchronous test device is used for recording execution result information generated when the operation behavior is simulated on the synchronous test browser in the process of simulating the operation behavior on the synchronous test browser; the judging module is used for judging whether the execution result information contains error information; and the error processing module is used for carrying out error processing according to the error information when the judging module judges that the execution result information contains the error information so as to ensure that the simulation test on the synchronous test browser is completely finished.
Wherein the error handling module comprises: a first search unit configured to search for an error code corresponding to the error information; the second searching unit is used for searching an error processing model corresponding to the error code when the error code is found by the first searching unit; and the error processing unit is used for finding the error processing model in the second searching unit and then carrying out error processing according to the error processing model.
Wherein the error information comprises errors caused by a UI interface; the error processing model comprises switching positioning objects, repositioning web page elements related to operation behaviors and executing again.
The operation instruction comprises a webpage element number, a webpage element coordinate value and a tree bit code of the webpage element, wherein the tree bit code is the number of the position of each webpage element in the webpage in the browser, which is mapped to a tree structure, in the tree structure; the switching positioning object, and the repositioning the webpage elements related to the operation behavior comprise: and if the positioning of the webpage element according to the coordinate value fails, positioning the webpage element according to the corresponding tree bit code, or if the positioning of the webpage element according to the tree bit code fails, positioning the webpage element according to the corresponding coordinate value.
The operation browser and the synchronous test browser are different types of browsers.
The invention has the beneficial effects that: different from the situation of the prior art, the method records the operation behavior executed by operating the browser, generates the operation instruction, and synchronizes the operation instruction to the synchronous test browser, so that the operation instruction is simulated on the synchronous test browser, the automatic test of the compatibility of the browser is realized, the manual test workload is reduced, and the working efficiency is improved; in addition, when the webpage elements cannot be positioned due to the UI interface problem in the synchronous test browser, the positioning object can be switched, and the webpage elements related to the operation behavior are repositioned, so that the simulation test on the synchronous test browser is continued, the simulation test on the synchronous test browser is prevented from being hung at the error position, and the simulation test is ensured to be smoothly executed and completed.
Detailed Description
The present invention will be described in detail below with reference to the accompanying drawings and embodiments.
Referring to fig. 1 and 2, the multi-browser compatibility testing system includes an operation testing apparatus 21 and at least one synchronization testing apparatus 22. The operation test device 21 is configured with an operation browser, which is an actually operated browser, for example: the tester manually performs the test on the operating browser. The synchronous test device 22 is configured with a synchronous test browser, wherein the operating browser and the synchronous test browser may be different types of browsers to implement a compatibility test of multiple browsers; or the operation browser and the test browser are the same type of browser, but the operation system for operating the test equipment and the synchronous test equipment is different types of systems, so as to realize cross-platform test; or the operating system of the operating test device is different from that of the synchronous test device, and the operating browser and the synchronous test browser can be different browsers, and the compatibility and cross-platform test of multiple browsers can be simultaneously performed.
The operation test device 21 includes a record generation module 211 and a synchronization module 212. The record generating module 211 is configured to record an operation behavior of testing a web page element in an operation browser in a process of testing the operation browser, and generate an operation instruction. A synchronization module 212 for synchronizing the operation instructions to the synchronous test equipment 22. The synchronization test apparatus 22 includes a receiving module 221, a simulation module 222, a recording module 223, a judgment module 224, and an error handling module 225. The receiving module 221 receives an operation instruction. The simulation module 222 simulates the operation behavior in the synchronous test browser according to the operation instruction. The recording module 223 records the execution result information generated when the operation behavior is simulated on the synchronous test browser in the process of simulating the operation behavior on the synchronous test browser. The determination module 224 determines whether the execution result information includes error information. The operation result information carries an operation instruction number, an operation result and error information. When the operation instruction executed by the operation browser is the same as the operation instruction executed by the test browser, if the operation results are different, the execution result information generated by executing the operation instruction on the synchronous test browser contains error information, an error event and an error reason are recorded in the error information in detail, and if the operation results are the same, no content is recorded in the error description; still alternatively, procedural errors occur when operating on a synchronous test browser, such as: the program crash, the inability to locate web page elements, etc. indicates that the execution result information generated by executing the operation instructions on the synchronous browser contains error information, and similarly, the error information also records the error event and the error reason in detail.
When the determining module 224 determines that the execution result information includes the error information, the error processing module 225 performs error processing according to the error information to ensure that all simulation tests on the synchronous test browser are completed. It should be noted that: when the simulation module 222 simulates an operation behavior executed by the operating browser, if the operating browser and the testing browser are incompatible, the problems of error, such as crash of the synchronous testing browser and inaccurate positioning of web page elements in the synchronous testing browser, may be caused. When the synchronous testing browser has an error problem, the error processing module 225 performs error processing so that the simulation module 222 can smoothly execute all operation behaviors, and the synchronous testing browser can be effectively prevented from being hung at the error position when the synchronous testing browser has an error, thereby stopping the test.
An operation behavior corresponds to an operation command, and an operation command corresponds to execution result information, where the execution result information is shown in table 1.
TABLE 1
By comparing the execution result information of different browsers, the compatibility problem of different browsers can be known.
When the operation behavior is simulated in the synchronous test browser, errors may occur in the test browser, and the compatibility test is interrupted. In order to avoid test interruption, errors which may be generated in the test process of the synchronous test browser are encoded in advance to generate error codes; and sets an error handling model in advance. If the error processing model and the error code have a corresponding relationship, the error code can be obtained according to the error information contained in the execution result information, the error code processing model can be obtained according to the error code, and then the error processing can be performed according to the error processing model. Thus, the error handling module 225 includes a first lookup unit 2251, a second lookup unit 2252, and an error handling unit 2253. The first lookup unit 2251 searches for an error code corresponding to the error information. When the first searching unit 2251 does not find the error code corresponding to the error code information, processing is performed according to a preset processing model, for example, restarting the system, restarting the browser, recovering the testing environment, and the like; alternatively, the error process is learned according to a preset learning algorithm to continuously update the error code. The second search unit 2252 searches for an error handling model corresponding to the error code according to the error code found by the first search unit 2251. When the second searching unit 2252 does not find the error processing model corresponding to the error code, the processing is also performed according to the preset processing model, for example, restart the system, restart the browser, recover the testing environment, and so on; alternatively, the error process is learned according to a preset learning algorithm. The error processing unit 2253 performs error processing according to the error processing model found by the second search unit 2252. It is worth mentioning that: the error code and the error processing model are matched separately, so that one or more error processing models are matched according to different error information, and the flexibility of error processing of the system is improved; in addition, according to a preset learning algorithm, a better error processing model can be matched with the error information or generated according to a processing result, and the error processing capability of the system is improved.
One of the error messages may be an error caused by the U I interface, specifically, the interface of the web page displayed in different browsers is different, which causes a failure in positioning web page elements. The corresponding error handling model is used for switching the positioning object, repositioning the webpage elements related to the operation behavior and executing again. In the present embodiment, the operation instruction includes a number of a web page element, a coordinate value of the web page element, and a tree bit code of the web page element, where the tree bit code is a number mapped to a tree by each web page element in a web page in the browser; switching the positioning object, wherein the repositioning of the webpage elements involved in the operation behavior comprises: if the positioning of the webpage elements according to the coordinate values fails, the webpage elements are positioned according to the corresponding tree bit codes, or if the positioning of the webpage elements according to the tree bit codes fails, the webpage elements are positioned according to the corresponding coordinate values.
Further, the operation instruction may further include an operation input device and operation input contents. . The web element coordinate values refer to position values of the manipulated web element, which include X-axis coordinates and Y-axis coordinates. The operation input device is a device used for the current operation, and includes, for example: a mouse or a keyboard, etc. The operation input content refers to an input made on a web page element within the browser, for example: mouse clicks, keyboard entry text, etc. Output results refer to results from inputs made on web page elements within the browser. In the embodiment of the invention, the output result mainly reproduces the operation of a mouse and a keyboard input device of a user. If the keyboard is used for inputting, the output result is the content input by the keyboard; if the mouse is used for clicking and jumping is generated, outputting a result as a website after jumping; and if the window is clicked and popped up by using a mouse, outputting the result as the text contained in the window. The web page element tree bit code is a serial number of a position of a web page element in a tree structure after mapping a currently operated web page element to the tree structure, wherein each web page element has a unique tree bit code, and the code is used for uniquely identifying one web page element, as shown in fig. 3:
wherein, the tree bit code of the first layer web page element html is 1; the tree position code of the second layer webpage element button is 21, and the tree position code of the webpage element menu is 22; the tree bit code of the third level web page element Inputbox is 31, and the tree bit code of the web page element button is 32. In this embodiment, the web page elements may be located by the coordinate values and the tree codes, and the location is performed by the coordinate values in the default case.
For better understanding of the error handling process of the present invention, the following description is given by way of example, where table 2 is a table of correspondence between error codes and error information, table 3 is a table of error code handling models, table 4 is a table of correspondence between error codes and error handling models, and table 5 is a table of execution result information.
TABLE 2
TABLE 3
TABLE 4
For example: when the layout error occurs in the UI of the synchronous test browser, the clicking purchase button is not on the designated coordinate axis, so that the clicking fails. The recording of error information in the execution result information is shown in table 5.
TABLE 5
The first lookup unit 2251 obtains an error code of 1 from the lookup table 4 according to the error information. The second lookup unit 2252 obtains error handling manners 7 and 5 from the error code 1, lookup tables 5 and 6, that is: and switching the object positioning mode and re-executing the previous instruction. Specifically, the synchronous testing device 22 executes the operation command again on the testing browser, and the operation command no longer locates the web page element by the coordinates, but locates the web page element by the tree bit code. The tester checks the execution result information and knows that the compatibility problem of the UI (user interface) exists on the synchronous test browser when the purchase button is clicked. When the compatibility error of the UI interface of the browser is tested, the test system automatically processes the error, the test interruption is avoided, and the next operation instruction can be continuously executed for testing, so that the normal operation of the multi-browser compatibility test is ensured, and more compatibility problems are found in the automatic compatibility test.
To facilitate management of the test information, the system further comprises a server 23. The operation test device 21 synchronizes the operation instruction to the synchronization test device 22 through the server 23. The method specifically comprises the following steps: the operation test device 21 sends an operation instruction to the server 23, and after receiving the operation instruction, the server 23 forwards the operation instruction to the synchronization test device 22. The execution result information generated by executing the operation on the operating browser and the execution result information generated by executing the operation on the test browser are both returned to the server 23. The error processing section may also be executed by the server 23. The server 23 sends the found error handling model to the synchronization test device 22, and the synchronization test device 22 performs error handling. Therefore, the judgment module 224 and the error processing module 225 may not be provided in the synchronous testing device 22, and the server 23 includes the judgment module 224 and the error processing module 225.
It should be noted that: in the present embodiment, the operation test device 21 and the synchronization test device 22 are preferably computers. Wherein the operation test device 21 and the synchronization test device 22 are connected through a network; the number of the synchronous test devices 22 is plural, and one browser is provided on one synchronous test device 22. In short, the inventive system may be a distributed system. In the distributed test system of the invention, a plurality of test devices are adopted for testing. Compared with the scheme of running a plurality of browsers on 1 test device for testing: the invention has the advantages that each testing device takes the role of the test device, the occupied space is low, and the reuse rate is highest. If a plurality of browsers are operated on a single test device, the occupied space is large, and the multiplexing rate is low. The interaction between the test devices is avoided, the communication and matching efficiency is low, and additional test personnel are required to be added for processing. In effect, according to the distributed test system, only 1 tester is needed to synchronize the test operation to other test equipment. And after the test is finished, the result is automatically collected for feedback. The concurrency of multiple browsers or the concurrency of multiple virtual machine deployments running on one test device is simulated operation level, and the concurrency of real operation level cannot be generated. For example, 10 login requests are sent to the server at the same time, it is possible that the values returned by the server are all successful, which is the simulation operation level. The method can be carried out on one test device and a plurality of test devices, but 10 login buttons on 10 browsers cannot be clicked on one machine at the same time, the script can be executed quickly, but only 1 click can be clicked, and therefore the efficiency is greatly different from that of distributed deployment.
In the embodiment of the invention, the operation behavior executed by operating the browser is recorded, the operation instruction is generated, and the operation instruction is synchronized to the test browser, so that the operation instruction is simulated on the test browser, the automatic test of the compatibility of the browser is realized, the manual test workload is reduced, and the working efficiency is improved; in addition, when the webpage elements cannot be positioned due to the UI interface problem in the synchronous test browser, the positioning object can be switched, and the webpage elements related to the operation behavior are repositioned, so that the simulation test on the synchronous test browser is continued, the simulation test on the synchronous test browser is prevented from being hung at the error position, and the simulation test is ensured to be smoothly executed and completed.
Referring to fig. 4, the method for testing compatibility of multiple browsers includes:
step S300: the operating browser and the at least one synchronous test browser are configured.
The operating browser is the browser that is actually operated.
Step S301: in the process of testing the operation browser, recording the operation behavior of testing the webpage elements in the operation browser, and generating an operation instruction.
A web page element refers to an element within a web page that can be manipulated, such as: buttons, input boxes, and the like. In order to increase the testing speed, it is preferable that the operation browser is started in the operation testing device, and the synchronous testing browser is started in the synchronous testing device, wherein the operation browser and the testing browser are different types of browsers. The operation browser is started in the operation test equipment, and the synchronous test browser is started in the synchronous test equipment, so that the distributed architecture is realized, and the test speed is favorably improved. It is worth mentioning that: the number of the synchronous test devices can be multiple, such as 3, 4, etc., and one synchronous test browser is started on one synchronous test device.
Step S302: and synchronizing the operation instruction to the synchronous test browser.
The operation on the operation browser is simulated on the synchronous test browser, which is equivalent to the actual test on the synchronous test browser, so that the compatibility of the operation browser and the synchronous test browser is detected, and a tester does not need to manually test each browser one by one.
Step S303: and simulating the operation behavior on the synchronous test browser according to the operation instruction, and recording the execution result information generated when the operation behavior is simulated on the synchronous test browser.
Each operation behavior corresponds to an operation instruction, and a specific description of the execution result information corresponding to an operation instruction corresponding to an execution result information can refer to the above embodiments, which are not repeated herein.
Step S304: it is determined whether the execution result information includes an error message, if so, the step S305 is performed, otherwise, the processing is not performed.
The error information refers to the test result on the operation browser is different from the test result on the synchronous test browser, and the error generated by the simulation operation on the synchronous test browser includes the programming error and the system error, for example: testing browser crash, testing browser to perform a dead cycle suspended, etc.
Step S305: and carrying out error processing according to the error information so as to ensure that the simulation test on the synchronous test browser is completely finished.
When the simulation operation on the test browser has errors, the errors are processed, a certain test behavior is prevented from being hung at the error position, and the whole test can be smoothly completed. The tester can find out the place where the operation browser is incompatible with the synchronous test browser by looking up the execution result information.
Specifically, the error that may occur in the synchronous test browser is encoded in advance, an error code is generated, and an error handling model is established, as shown in fig. 5, step S305 further includes:
step S3051: and searching for an error code corresponding to the error information, if the error code is found, entering a step S3053, and if not, entering a step S3052.
For matching between the error information and the error code, matching may be performed by a keyword.
Step S3052: processing is performed according to a predetermined error handling model.
The predetermined error handling model may be a restart of the system, a restart of the browser, etc., or a learning of error handling according to a learning algorithm.
Step S3052: and searching for an error processing model corresponding to the error code, if the error processing model is found, entering the step S3053, and if not, returning to the step S3052.
Step S3053: and carrying out error processing according to the error processing model.
One of the error messages may be an error caused by the U I interface, specifically, the interface of the web page displayed in different browsers is different, which causes a failure in positioning web page elements. The corresponding error handling model is used for switching the positioning object, repositioning the webpage elements related to the operation behavior and executing again. In the present embodiment, the operation instruction includes a number of a web page element, a coordinate value of the web page element, and a tree bit code of the web page element, where the tree bit code is a number mapped to a tree by each web page element in a web page in the browser; switching the positioning object, wherein the repositioning of the webpage elements involved in the operation behavior comprises: if the positioning of the webpage elements according to the coordinate values fails, the webpage elements are positioned according to the corresponding tree bit codes, or if the positioning of the webpage elements according to the tree bit codes fails, the webpage elements are positioned according to the corresponding coordinate values. Of course, the error information and the error handling model also include other contents, which may specifically refer to the description of the above embodiments, and are not described in detail here.
In the embodiment of the invention, the operation behavior executed by operating the browser is recorded, the operation instruction is generated, and the operation instruction is synchronized to the test browser, so that the operation instruction is simulated on the test browser, the automatic test of the compatibility of the browser is realized, the manual test workload is reduced, and the working efficiency is improved; in addition, when the webpage elements cannot be positioned due to the U I interface problem in the synchronous test browser, the positioning object can be switched to reposition the webpage elements, so that the simulation test on the synchronous test browser is continued, the simulation test on the synchronous test browser is prevented from being hung at a wrong position, and the simulation test is ensured to be successfully executed.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes performed by the present specification and drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.