A method for porting GUI test code between apps
By using model-driven and natural language processing technologies, GUI test code can be ported between apps with similar functions, solving the problem of high time and manpower costs in writing GUI test code in existing technologies, and achieving efficient code porting and semantic consistency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING UNIV
- Filing Date
- 2022-06-07
- Publication Date
- 2026-07-24
AI Technical Summary
Existing technologies lack efficient methods for porting GUI test code between apps, resulting in high time and manpower costs for writing GUI test code.
Using model-driven, dynamic analysis, and natural language processing techniques, a model representing the runtime state of an app and its changing relationships is designed. By modifying the testing framework and using automated exploration tools, a greedy search backtracking method is used to match state transition paths in the target app and translate them into GUI test code suitable for the app testing framework.
It enables efficient porting of GUI test code between apps with similar functions, saving time and manpower costs in writing GUI test code.
Smart Images

Figure CN114936162B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of code testing technology, and in particular to a method for porting GUI test code between apps. Background Technology
[0002] Model-Driven Engineering (MDE) is a branch of software engineering that extends models and modeling to all aspects of software development, forming a multi-dimensional modeling space. This allows engineering activities to be built upon the mapping and transformation of these models. The fundamental principle of MDE is to treat the model as the primary entity and all software artifacts as models or model elements.
[0003] Dynamic analysis is computer software analysis performed by running programs on real or virtual processors. For dynamic program analysis to be effective, the target program must be run with sufficient test inputs to cover all possible outputs. Using software testing measures such as code coverage helps ensure that possible program behaviors are observed. Furthermore, care must be taken to minimize the impact of testing on execution. Unit testing, integration testing, system testing, and acceptance testing utilize dynamic analysis techniques.
[0004] Natural Language Processing (NLP) is a branch of artificial intelligence and linguistics. This field explores how to process and utilize natural language; NLP includes multiple aspects and steps, fundamentally comprising cognition, understanding, and generation. Natural language cognition and understanding involve enabling computers to transform input language into meaningful symbols and relationships, and then process them according to the intended purpose. Natural language generation systems, on the other hand, convert computer data into natural language. Summary of the Invention
[0005] In view of the above problems, the present invention aims to provide a method for porting GUI test code between apps. This method uses model-driven, dynamic analysis, natural language processing and other technologies to port GUI test code to two apps with similar functions and make them have similar test semantics, thereby saving time and manpower costs in writing GUI test code.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] A method for porting GUI test code between apps includes the following steps:
[0008] Step 1: Enter two apps and the GUI test code for one of the apps, and name them Source App, Source GUI Test Code, and Target App;
[0009] Step 2: Design a model to represent the runtime state of the App and its changing relationships;
[0010] Step 3: Modify the App testing framework to record App runtime information, use the modified testing framework to execute the source GUI test code on the source App, and use the obtained information to establish the state transition path of the source App;
[0011] Step 4: Modify the App auto-exploration tool to record App runtime information, run the target App using the modified App auto-exploration tool, and use the obtained information to build the target App's state transition diagram;
[0012] Step 5: Use a greedy search backtracking method to match a similar state transition path of the source App in Step 3 on the state transition graph of the target App in Step 4;
[0013] Step 6: Translate the state transition path obtained in Step 5 into GUI test code suitable for the App testing framework;
[0014] Step 7: Obtain the final ported GUI test code.
[0015] The method for porting GUI test code between apps described above is characterized in that the implementation process of the model representing the runtime state of the app and its changing relationships established in step 2 includes the following steps:
[0016] Step 21: Obtain the layout structure and screenshots of all interfaces in the App, as well as all events that cause changes between interfaces;
[0017] Step 22: Remove information related to the App's operating platform from all layout structures and screenshots;
[0018] Step 23: Remove duplicate layout structures and screenshots;
[0019] Step 24: Treat each pair of layout structures and screenshots as a runtime state of the App;
[0020] Step 25: Treat the events that cause changes in the runtime states of the two apps as edges.
[0021] The above-described method for porting GUI test code between Apps is characterized in that step 3, which involves executing the source GUI test code on the source App using the modified test framework and establishing the state transition path of the source App using the obtained information, includes the following steps:
[0022] Step 31: Record the interface layout structure and screenshots, target control, operation event type, and operation event parameters of the source App before and after each operation is executed during the execution of the source GUI test code;
[0023] Step 32: Using the information obtained above, establish the state transition model of the source App during the execution of the source GUI test code according to the methods in steps 21-25;
[0024] Step 33: Organize the model obtained above into the form of state transition paths.
[0025] The above-described method for porting GUI test code between apps is characterized by the following steps in step 4: running the target app using the modified app auto-exploration tool and using the obtained information to build the target app's state transition diagram.
[0026] Step 41: Record the interface layout structure and screenshots, target controls, operation event types, and operation event parameters of the target App before and after each operation during the automatic exploration period;
[0027] Step 42: Use the information obtained above to build a state transition model of the target App during automatic exploration, following the methods in steps 21-25;
[0028] Step 43: Organize the model obtained above into a state transition diagram.
[0029] The method for porting GUI test code between apps described above is characterized in that step 5 includes the following steps:
[0030] Step 51: Build a word2vec model using the Google Play corpus and default parameters;
[0031] Step 52: Traverse each edge in the state transition path of the source App in Step 3, and find the target control and the controls near the target control in its initial state;
[0032] Step 53: Extract the text attribute information of the two parts of the control obtained in Step 52, and calculate their weighted vectorized information by preprocessing, word segmentation and word filtering, and then using the word2vec model established in Step 51.
[0033] Step 54: Traverse each edge of the state transition graph of the target App in Step 4, and find the target control and the controls near the target control in its initial state;
[0034] Step 55: Extract the text attribute information of the two parts of the control obtained in Step 54, and calculate their weighted vectorized information by preprocessing, word segmentation and word filtering, and then using the word2vec model established in Step 51.
[0035] Step 56: For each weighted information sum obtained in step 53, calculate the cosine similarity with all weighted information sums obtained in step 54, sort them, and take the highest result as the similar control of its corresponding operation target control;
[0036] Step 57: Find the corresponding state on the state transition graph of the target App for all similar controls obtained in Step 56, traverse these states, and calculate the shortest path connecting these states step by step;
[0037] Step 58: Check whether the final assertion condition of the path obtained in step 57 is met. If not, go back to the previous step and reselect a similar control or the shortest path until the assertion condition is met.
[0038] Step 59: Obtain the state transition path that meets the assertion conditions.
[0039] The above-described method for porting GUI test code between Apps is characterized in that the specific implementation process of translating the state transition path obtained in step 5 into GUI test code suitable for the App testing framework in step 6 includes the following steps:
[0040] Step 61: Determine the correspondence between the App testing framework's API and the target control, event type, and event parameters in the state transition path obtained in Step 5;
[0041] Step 62: Traverse the edges in the state transition path obtained in Step 5, and translate the corresponding operation target control, operation event type, and operation event parameters into code according to the correspondence determined in Step 61;
[0042] Step 63: Organize the code obtained in Step 62 into GUI test code suitable for the App testing framework.
[0043] Beneficial effects: By adopting the above technical solutions, this invention uses model-driven, dynamic analysis, and natural language processing technologies to port GUI test code for two Apps with similar functions and make them have similar test semantics, thereby saving time and manpower costs in writing GUI test code. Attached Figure Description
[0044] Figure 1 This is a schematic diagram illustrating the overall structure and working principle of an embodiment of the present invention.
[0045] Figure 2 This is a schematic diagram of the state transition model structure according to an embodiment of the present invention.
[0046] Figure 3 This is a schematic diagram of the state transition path file structure according to an embodiment of the present invention.
[0047] Figure 4 This is a schematic diagram of the state transition diagram file structure according to an embodiment of the present invention.
[0048] Figure 5 This is a flowchart illustrating the event matching process in an embodiment of the present invention. Detailed Implementation
[0049] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0050] Figure 1 This is a schematic diagram illustrating the overall structure and working principle of an embodiment of the present invention. The purpose of this invention is to provide a method for porting GUI test code between apps. This method uses model-driven development, dynamic analysis, natural language processing, and other technologies to port GUI test code between two apps with similar functions, ensuring they have similar test semantics, thereby saving time and manpower costs associated with writing GUI test code. Figure 1 As shown, the present invention includes the following steps:
[0051] Step 1: Enter two apps and the GUI test code for one of the apps, and name them Source App, Source Test Code, and Target App;
[0052] Step 2: Design a model to represent the runtime state of the App and its changing relationships;
[0053] Step 3: Modify the App testing framework to record App runtime information, use the modified testing framework to execute the source GUI test code on the source App, and use the obtained information to establish the state transition path of the source App;
[0054] Step 4: Modify the App auto-exploration tool to record App runtime information, run the target App using the modified App auto-exploration tool, and use the obtained information to build the target App's state transition diagram;
[0055] Step 5: Use a greedy search backtracking method to match a similar state transition path of the source App in Step 3 on the state transition graph of the target App in Step 4;
[0056] Step 6: Translate the state transition path obtained in Step 5 into GUI test code suitable for the App testing framework;
[0057] Step 7: Obtain the final ported GUI test code.
[0058] Figure 2This is a schematic diagram of the state transition model structure according to an embodiment of the present invention, illustrating a model that can describe the runtime states of an App and their changing relationships. The design process specifically includes the following steps:
[0059] Step 21: Obtain the layout structure and screenshots of all interfaces in the App, as well as all events that cause changes between interfaces;
[0060] Step 22: Remove information related to the App's operating platform from all layout structures and screenshots;
[0061] Step 23: Remove duplicate layout structures and screenshots;
[0062] Step 24: Treat each pair of layout structures and screenshots as a runtime state of the App;
[0063] Step 25: Treat the events that cause changes in the runtime states of the two apps as edges.
[0064] Figure 3 This is a schematic diagram of the state transition path file structure according to an embodiment of the present invention, illustrating the file structure of the state transition path of the source App during the execution of the source GUI test code. Its specific implementation process includes the following steps:
[0065] Step 31: Record the interface layout structure and screenshots, target control, operation event type, and operation event parameters of the source App before and after each operation is executed during the execution of the source GUI test code;
[0066] Step 32: Using the information obtained above, establish the state transition model of the source App during the execution of the source GUI test code according to the methods in steps 21-25;
[0067] Step 33: Organize the model obtained above into the form of state transition paths.
[0068] Figure 4 This is a schematic diagram of the state transition graph file structure according to an embodiment of the present invention, illustrating the file structure of the state transition graph of the target App during automatic exploration. Its specific implementation process includes the following steps:
[0069] Step 41: Record the interface layout structure and screenshots, target controls, operation event types, and operation event parameters of the target App before and after each operation during the automatic exploration period;
[0070] Step 42: Use the information obtained above to build a state transition model of the target App during automatic exploration, following the methods in steps 21-25;
[0071] Step 43: Organize the model obtained above into a state transition diagram.
[0072] Figure 5 This is an event matching flowchart of an embodiment of the present invention, illustrating the process of event matching in the state transition diagram obtained in step 4 from the state transition path obtained in step 3. The specific implementation process includes the following steps:
[0073] Step 51: Build a word2vec model using the Google Play corpus and default parameters;
[0074] Step 52: Traverse each edge in the state transition path of the source App in Step 3, and find the target control and the controls near the target control in its initial state;
[0075] Step 53: Extract the text attribute information of the two parts of the control obtained in Step 52, and calculate their weighted vectorized information by preprocessing, word segmentation and word filtering, and then using the word2vec model established in Step 51.
[0076] Step 54: Traverse each edge of the state transition graph of the target App in Step 4, and find the target control and the controls near the target control in its initial state;
[0077] Step 55: Extract the text attribute information of the two parts of the control obtained in Step 54, and calculate their weighted vectorized information by preprocessing, word segmentation and word filtering, and then using the word2vec model established in Step 51.
[0078] Step 56: For each weighted information sum obtained in step 53, calculate the cosine similarity with all weighted information sums obtained in step 55, sort them, and take the highest result as the similar control of its corresponding operation target control;
[0079] Step 57: Find the corresponding state on the state transition graph of the target App for all similar controls obtained in Step 56, traverse these states, and calculate the shortest path connecting these states step by step;
[0080] Step 58: Check whether the final assertion condition of the path obtained in step 57 is met. If not, go back to the previous step and reselect a similar control or the shortest path until the assertion condition is met.
[0081] Step 59: Obtain the state transition path that meets the assertion conditions.
[0082] In step 6 of this method, the state transition path obtained in step 5 is translated into GUI test code suitable for the App testing framework. The specific implementation process includes the following steps:
[0083] Step 61: Determine the correspondence between the App testing framework's API and the target control, event type, and event parameters in the state transition path obtained in Step 5;
[0084] Step 62: Traverse the edges in the state transition path obtained in Step 5, and translate the corresponding operation target control, operation event type, and operation event parameters into code according to the correspondence determined in Step 61;
[0085] Step 63: Organize the code obtained in Step 62 into GUI test code suitable for the App testing framework.
[0086] The above descriptions are embodiments of the present invention, but the specific embodiments described herein are merely illustrative and not intended to limit the invention. Any omissions, modifications, or equivalent substitutions made within the scope of the claims of this invention without departing from the principles and spirit of the invention should be included within the protection scope of the claims.
Claims
1. A method for porting GUI test code between apps, comprising the following steps: Step 1: Enter two apps and the GUI test code for one of the apps, and name them Source App, Source GUI Test Code, and Target App; Step 2: Design a model to represent the runtime state of the App and its changing relationships; Step 3: Modify the App testing framework to record App runtime information, use the modified testing framework to execute the source GUI test code on the source App, and use the obtained information to establish the state transition path of the source App; Step 4: Modify the App auto-exploration tool to record App runtime information, run the target App using the modified App auto-exploration tool, and use the obtained information to build the target App's state transition diagram; Step 5: Use a greedy search backtracking method to match a similar state transition path between the source App's state transition path in Step 3 and the target App's state transition graph in Step 4; the specific implementation process of Step 5 includes the following steps: Step 51: Build a word2vec model using the Google Play corpus and default parameters; Step 52: Traverse each edge in the state transition path of the source App in Step 3, and find the target control and the controls near the target control in its initial state; Step 53: Extract the text attribute information of the two parts of the control obtained in Step 52, and calculate their weighted vectorized information by preprocessing, word segmentation and word filtering, and then using the word2vec model established in Step 51. Step 54: Traverse each edge of the state transition graph of the target App in Step 4, and find the target control and the controls near the target control in its initial state; Step 55: Extract the text attribute information of the two parts of the control obtained in Step 54, and calculate their weighted vectorized information by preprocessing, word segmentation and word filtering, and then using the word2vec model established in Step 51. Step 56: For each weighted information sum obtained in step 53, calculate the cosine similarity with all weighted information sums obtained in step 54, sort them, and take the highest result as the similar control of its corresponding operation target control; Step 57: Find the corresponding state on the state transition graph of the target App for all similar controls obtained in Step 56, traverse these states, and calculate the shortest path connecting these states step by step; Step 58: Check whether the final assertion condition of the path obtained in step 57 is met. If not, go back to the previous step and reselect a similar control or the shortest path until the assertion condition is met. Step 59: Obtain the state transition path that meets the assertion conditions; Step 6: Translate the state transition path obtained in Step 5 into GUI test code suitable for the App testing framework; Step 7: Obtain the final ported GUI test code.
2. The method for porting GUI test code between Apps according to claim 1, characterized in that, The implementation process of establishing the model representing the runtime state of the App and its changing relationships in step 2 includes the following steps: Step 21: Obtain the layout structure and screenshots of all interfaces in the App, as well as all events that cause changes between interfaces; Step 22: Remove information related to the App's operating platform from all layout structures and screenshots; Step 23: Remove duplicate layout structures and screenshots; Step 24: Treat each pair of layout structures and screenshots as a runtime state of the App; Step 25: Treat the events that cause changes in the runtime states of the two apps as edges.
3. The method for porting GUI test code between Apps according to claim 1, characterized in that, Step 3, which involves using the modified testing framework to execute the source GUI test code on the source App and using the obtained information to establish the state transition path of the source App, includes the following steps: Step 31: Record the interface layout structure and screenshots, target control, operation event type, and operation event parameters of the source App before and after each operation is executed during the execution of the source GUI test code; Step 32: Using the information obtained above, establish the state transition model of the source App during the execution of the source GUI test code according to the methods in steps 21-25; Step 33: Organize the model obtained above into the form of state transition paths.
4. The method for porting GUI test code between Apps according to claim 1, characterized in that, The specific implementation process of step 4, which involves running the target app using the modified App auto-exploration tool and using the obtained information to build the state transition diagram of the target app, includes the following steps: Step 41: Record the interface layout structure and screenshots, target controls, operation event types, and operation event parameters of the target App before and after each operation during the automatic exploration period; Step 42: Use the information obtained above to build a state transition model of the target App during automatic exploration, following the methods in steps 21-25; Step 43: Organize the model obtained above into a state transition diagram.
5. The method for porting GUI test code between Apps according to claim 1, characterized in that, The specific implementation process of translating the state transition path obtained in step 5 into GUI test code suitable for the App testing framework in step 6 includes the following steps: Step 61: Determine the correspondence between the App testing framework's API and the target control, event type, and event parameters in the state transition path obtained in Step 5; Step 62: Traverse the edges in the state transition path obtained in Step 5, and translate the corresponding operation target control, operation event type, and operation event parameters into code according to the correspondence determined in Step 61; Step 63: Organize the code obtained in Step 62 into GUI test code suitable for the App testing framework.