CN117762786A - Method for generating test case, electronic equipment and storage medium - Google Patents

Method for generating test case, electronic equipment and storage medium Download PDF

Info

Publication number
CN117762786A
CN117762786A CN202311763164.5A CN202311763164A CN117762786A CN 117762786 A CN117762786 A CN 117762786A CN 202311763164 A CN202311763164 A CN 202311763164A CN 117762786 A CN117762786 A CN 117762786A
Authority
CN
China
Prior art keywords
positioning information
element positioning
information
target
generating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311763164.5A
Other languages
Chinese (zh)
Inventor
李愿
王军
韦道蓝
胡利平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ruishi Suzhou Video Technology Co ltd
Original Assignee
Ruishi Suzhou Video Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ruishi Suzhou Video Technology Co ltd filed Critical Ruishi Suzhou Video Technology Co ltd
Priority to CN202311763164.5A priority Critical patent/CN117762786A/en
Publication of CN117762786A publication Critical patent/CN117762786A/en
Pending legal-status Critical Current

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention relates to the technical field of automatic test, and discloses a method for generating test cases, electronic equipment and a storage medium, wherein the method comprises the following steps: acquiring operation behaviors of target elements in a tested page, attribute information of multiple attribute types of the target elements and path information; generating element positioning information corresponding to the attributes one by one and an arrangement sequence among the element positioning information based on the attribute information, the path information and the contents included by the target elements so as to obtain an element positioning information list; and generating test cases of the tested page according to the element positioning information list and the operation behavior. The invention optimizes the rules and the ordering of the original element positioning information, and adds various element positioning information in the element positioning information list, thereby not only improving the positioning accuracy, but also effectively improving the recognition efficiency of the later element positioning information.

Description

Method for generating test case, electronic equipment and storage medium
Technical Field
The present invention relates to the field of automated testing technologies, and in particular, to a method for generating test cases, an electronic device, and a storage medium.
Background
In recent years, with the rapid development of the internet, web sites have been widely used in various fields. Automated testing refers to the automatic execution of web application operations by a computer by writing or recording test scripts and checking whether the output results meet expectations. Wherein the automated recording tool may automatically record the user's operational steps and generate corresponding test scripts that typically identify and manipulate elements on the web page based on the element location information. However, because the structure and content of the web page may change over time, the element positioning information is invalid or inaccurate, resulting in a failure of the test case.
Disclosure of Invention
In view of the above, the invention provides a method, electronic equipment and storage medium for generating test cases, so as to solve the problem of test case operation failure caused by inaccurate element positioning information positioning in the prior art.
In a first aspect, the present invention provides a method for generating test cases, the method comprising:
acquiring operation behaviors of target elements in a tested page, attribute information of multiple attribute types of the target elements and path information;
Generating element positioning information corresponding to the attributes one by one and an arrangement sequence among the element positioning information based on the attribute information, the path information and the contents included by the target elements so as to obtain an element positioning information list;
and generating test cases of the tested page according to the element positioning information list and the operation behavior.
According to the method for generating the test case, provided by the embodiment of the invention, the element positioning information corresponding to the attribute one by one and the arrangement sequence among the element positioning information are generated based on the attribute information, the path information and the contents included in the target element, so that the rule and the arrangement sequence of the original element positioning information are optimized, and various element positioning information are added in the element positioning information list. The method not only improves the positioning accuracy, but also can effectively improve the recognition efficiency of the later element positioning information, thereby avoiding the problems of low efficiency and invalid or inaccurate element positioning information in the process of restoring the user operation caused by poor readability of the generated test cases due to the adoption of a fixed arrangement sequence.
In an alternative embodiment, generating element positioning information and an arrangement sequence between the element positioning information corresponding to the attribute one by one based on the attribute information, the path information and contents included in the target element to obtain an element positioning information list includes:
If the content included in the target element has a visible text, searching upwards by utilizing the path information to obtain a searching result, and generating a path of the target element based on the searching result and the visible text included in the target element to obtain first element positioning information, wherein the first element positioning information is first element positioning information in an element positioning information list.
According to the method for generating the test case, provided by the embodiment of the invention, the visible text content contained in the target element is fully combined, the first element positioning information in the element positioning information list is generated according to the path information, and the rules and the sequence of the original element positioning information are optimized, so that the readability of the element positioning information list is good, and the recognition efficiency and the accuracy of the later element positioning information can be effectively improved.
In an alternative embodiment, generating element positioning information and an arrangement sequence between the element positioning information corresponding to the attribute one by one based on the attribute information, the path information and contents included in the target element to obtain an element positioning information list includes:
searching parent-level target elements step by step upwards from the target elements;
if the attribute information of the parent-level target element has the unique identification attribute and has no change information, generating a relative path of the target element by taking the unique identification attribute of the parent-level target element as a starting point so as to obtain second element positioning information of the target element;
If the attribute information of the parent-level target element does not have the unique identification attribute, generating an absolute path of the target element based on a root node corresponding to the tested page where the target element is located, so as to obtain second element positioning information of the target element, wherein the second element positioning information is the last element positioning information in the element positioning information list.
According to the method for generating the test case, provided by the embodiment of the invention, the parent-level target element is searched step by step from the target element, the relative path element or the absolute path of the target element is generated as the last element positioning information in the element positioning information list, and the element can be accurately positioned under the condition that the tested page is unchanged.
In an alternative embodiment, based on the attribute information, the path information and the content included in the target element, generating element positioning information corresponding to the attribute one to one and an arrangement sequence between the element positioning information to obtain an element positioning information list, and further including:
screening the attribute information to remove the attribute information including the change information in the attribute information and obtain other attribute information;
third element positioning information in the element positioning information list is generated based on the other attribute information.
According to the method for generating the test case, provided by the embodiment of the invention, the attribute information containing the change information is removed, so that the influence of the change information on element positioning is avoided, the reliability of the generated element positioning information can be effectively improved, the accuracy of element positioning information positioning is ensured, and the positioning efficiency can be effectively improved.
In an alternative embodiment, generating element positioning information and an arrangement sequence between the element positioning information corresponding to the attribute one by one based on the attribute information, the path information and contents included in the target element to obtain an element positioning information list includes:
generating element positioning information based on the attribute information, the path information and contents included in the target element;
querying the elements based on the element positioning information;
if the unique element is queried and the queried element is consistent with the target element, adding the element positioning information into the element positioning information list.
According to the method for generating the test case, after element positioning information is generated based on the attribute information, the path information and the content included in the target element, reverse searching is performed by using the corresponding element positioning information. If the searching and matching are successful, the element positioning information list is added, and the accuracy of element positioning information positioning in the element positioning information list is ensured.
In an alternative embodiment, generating test cases according to the element positioning information list and the operation behavior includes:
generating a test case of the tested page based on the element positioning information list and the operation behavior;
and starting the tested page and debugging the test case to update the element positioning information list to obtain an updated test case.
The method for generating the test cases provided by the embodiment of the invention debugs the generated test cases to further ensure the accuracy of the element positioning information in the element positioning information list.
In an alternative embodiment, updating the element positioning information list to obtain an updated test case includes:
extracting first element positioning information in the element positioning information list to perform element searching;
if the element searching fails, extracting target element positioning information which can successfully find the target element from the element positioning information list;
determining a target element based on the target element positioning information, and analyzing the determined target element to obtain attribute information and path information of the target element;
and regenerating an element positioning information list of the target element based on the determined attribute information and path information and in the same mode of generating the element positioning information list so as to obtain an updated test case.
According to the method for generating the test case, when the current element positioning information cannot find the target element, the search can be continued according to other element positioning information, and after the search is completed, the element positioning information list can be automatically corrected, so that the positioning accuracy after the tested page is changed is further improved.
In an alternative embodiment, updating the element positioning information list to obtain an updated test case includes:
if the element positioning information currently debugged is path element positioning information and the digital index exists, activating an index control on a debugging page;
acquiring interactive operation of an index control, and cutting off currently debugged element positioning information from a first position with a digital index to obtain parent element positioning information;
determining and displaying corresponding parent elements based on the parent element positioning information;
acquiring a selection operation in a parent element, and determining a relative path corresponding to the selection operation;
and replacing the digital index in the currently debugged element positioning information based on the relative path, and updating the currently debugged element positioning information to obtain an updated test case.
According to the method for generating the test case, provided by the embodiment of the invention, an intelligent index function is added, when the element positioning information currently debugged is path element positioning information and the digital index exists, the element positioning information can be subjected to secondary element positioning by utilizing the intelligent index button, and the accurate positioning of the target element after the sequence of the target element is changed is ensured, so that the accuracy of element positioning information positioning is improved.
In a second aspect, the present invention provides an apparatus for generating test cases, where the apparatus includes:
the acquisition module is used for acquiring the operation behaviors of the target elements in the tested page, the attribute information of various attribute types of the target elements and the path information;
the element positioning information generation module is used for generating element positioning information corresponding to the attributes one by one and an arrangement sequence among the element positioning information based on the attribute information, the path information and the contents included in the target elements so as to obtain an element positioning information list;
and the test case generation module is used for generating the test case of the tested page according to the element positioning information list and the operation behavior.
In a third aspect, the present invention provides an electronic device, comprising: the memory and the processor are in communication connection, computer instructions are stored in the memory, and the processor executes the computer instructions, so that the method for generating the test case according to the first aspect or any implementation manner corresponding to the first aspect is executed.
In a fourth aspect, the present invention provides a computer readable storage medium storing computer instructions for causing a computer to execute the method for generating test cases according to the first aspect or any implementation manner corresponding to the first aspect.
It should be noted that, because the device for generating test cases, the electronic device and the computer readable storage medium provided by the present invention correspond to the method for generating test cases described above. Therefore, regarding the beneficial effects of the device for generating test cases, the electronic device and the computer readable storage medium, please refer to the description of the corresponding beneficial effects of the method for generating test cases above, which is not repeated herein.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are needed in the description of the embodiments or the prior art will be briefly described, and it is obvious that the drawings in the description below are some embodiments of the present invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow diagram of a method of generating test cases according to an embodiment of the invention;
FIG. 2 is a schematic diagram illustrating a process of recording test cases according to an embodiment of the present invention;
FIG. 3 is a schematic representation of the type of selector according to an embodiment of the invention;
FIG. 4 is a schematic page diagram of one of the element location information lists according to an embodiment of the present invention;
FIG. 5 is a schematic page view of another element location information list according to an embodiment of the invention;
FIG. 6 is a flow chart of a method of generating a test case according to an embodiment of the present invention;
FIG. 7 is a flow chart of another method of generating test cases according to an embodiment of the invention;
FIG. 8 is a page schematic of a correction log according to an embodiment of the invention;
FIG. 9a is a schematic page view of a smart index button according to an embodiment of the present invention;
FIG. 9b is a schematic diagram of a tested page according to an embodiment of the present invention;
FIG. 10 is a schematic diagram of a page highlighting processed positioning element information according to an embodiment of the present invention;
FIG. 11 is a schematic diagram of a page after replacing with a relative path with a smart index button in accordance with an embodiment of the present invention;
FIG. 12 is a block diagram of an apparatus for generating test cases according to an embodiment of the present invention;
Fig. 13 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In the related art, the automatic recording of the test cases is performed by adopting a Selenium IDE browser plug-in, and the browser plug-in for automatic testing provides a simple and easy-to-use interface for recording and playing back the operation of the user on the webpage. And automatically recording the operation steps of the user in the process of operating the web application by the user through a browser plug-in mechanism, and generating a corresponding test script. The programming or recording process of the automatic test script is simplified, and the efficiency and usability of the automatic test are improved. However, the Selenium IDE also has some disadvantages, mainly in the following aspects:
With the continuous upgrade of the browser, there are many problems. There are few steps to pass through for a recording. Users are often required to become familiar with the various instructions of Selenium and to make repeated debugging modifications based on the recorded script.
In addition, the generated test scripts typically identify and manipulate elements on the web page, such as id, name, class, xpath, based on element location information. Element positioning information is a string expression that describes the location and attributes of an element on a page. However, since the structure and content of the web page may change at any time, element positioning information is invalid or inaccurate, thereby affecting the execution result of the test script. Thus, users need to constantly maintain and update element positioning information to accommodate changes in web pages.
Moreover, most of the current web applications are dynamic sites, and are refreshed dynamically according to server data. When an element on a page, such as: tr, list, etc., when the sequence is changed, the element positioning information may fail or be positioned to other elements, thereby affecting the execution result of the test script. And the element positioning information is invalid or inaccurate, so that the operation of the test case is failed.
In view of the above, in accordance with an embodiment of the present invention, there is provided a method embodiment of generating test cases, it should be noted that the steps illustrated in the flowcharts of the figures may be performed in a computer system such as a set of computer-executable instructions, and that although a logical order is illustrated in the flowcharts, in some cases the steps illustrated or described may be performed in an order other than that herein.
In this embodiment, a method for generating a test case is provided, which may be executed by an electronic device, such as a computer, a mobile terminal, etc., and fig. 1 is a flowchart of a method for generating a test case according to an embodiment of the present invention, as shown in fig. 1, where the flowchart includes the following steps:
step S101, obtaining operation behaviors of target elements in a tested page, attribute information of multiple attribute types of the target elements and path information.
Specifically, the user may manually install the user interface recording plug-in the browser. The plug-in provides a visual page of the UI recording function, and the Web UI automation test platform can integrate the UI recording function in a nested mode. The UI recording visual interface can be accessed through a test platform or a patrol platform. The interface has two main functions: recording and local debugging.
After clicking recording and inputting the web page address of the tested page, the plug-in will automatically start the tested page and start recording, that is, when the tested page is opened, the plug-in will inject content scripts (the content scripts are scripts for interacting with web page content in the browser plug-in) into the tested page, and the content scripts will monitor user actions, such as common operation events of a mouse, a keyboard, touch, etc., through a window. When a user performs a certain operation on a target element in a tested page, the plug-in unit collects operation behaviors of the user on the target element, attribute information of multiple attribute types of the target element and path information through a content script and sends the attribute information and the path information to a test platform, which can be shown by referring to fig. 2.
Wherein, the target element may be a dom element in Html. Such as: div, span, etc. The location is generally performed by using attributes such as identification id, name, class of the dom element or path information xpath. The path information xpath, which expresses the position of the dom element in the Html document, is generally used for element localization. Referring specifically to FIG. 3, the selector types for automated testing include identification id, name, class, etc., and path xpath. When the corresponding element attribute type or path xpath is input, specific element positioning information can be acquired through a corresponding selector, wherein the selector type is judged in code logic according to an element positioning information character string. For example, if there is "//", it indicates that the string is path xpath, and if there is "#", it indicates that the selector type is id. The element positioning information is a character string for expressing the element position, and corresponds to a specific parameter of the selector. The selector is a development end term and is a built-in function of the browser.
In this embodiment, the attribute types may include: identification id, name, class, etc., and path xpath, etc. are included for element localization. That is, for the collected target element, the plug-in obtains attribute information and path information of the corresponding attribute type.
Step S102, based on the attribute information, the path information and the contents included in the target element, generating element positioning information corresponding to the attribute one by one and an arrangement sequence among the element positioning information to obtain an element positioning information list.
Specifically, each target element may include text, attribute information, path information, and the like. In this embodiment, corresponding element positioning information may be generated according to attribute information, path information, and content included in a corresponding target element, where the content included in the target element may be specific attribute, details of the path, text, and the like, for example, if the content included in the target element has visible text, the element positioning information is generated based on the visible text included in the target element, and referring to fig. 4, a first piece "xpath=// span [ start-with (fig., 'search in graphs') ] in the element positioning information list, that is, element positioning information generated according to the visible text and the path information, where 'search in graphs' is the visible text, and all attributes included in the visible text may be put into the element positioning information.
The element positioning information can be a character string expression describing the position or attribute of the element on the tested page, and the generated element positioning information is ordered according to the generated order, so that an element positioning information list is obtained. The element location information list is a string list describing the location or attribute of an element, and may refer to a target box in fig. 4 or 5. The content in the target frame is one element positioning information in the element positioning information list; instructions refer to what operation actions need to be done after an element is located, such as clicking, double clicking, dragging, and the like; the value is an option, and some instructions require more parameters to be entered to simulate the complete actions of the user, such as the user filling in an input box, the value will store the user's input content.
It should be noted that, in the related art, the sequence of the element positioning information is: identification id, name, class, path. However, such a sort is not reasonable in practical use. The reason is that these attributes are invisible to the user, and the recorded script is poorly readable. Post-maintenance is not facilitated, and the identification id is often random, resulting in element location information failure. Based on this, in this embodiment, the element positioning information and the sequence are associated with the attribute information and the content of the target element in combination with the content determination element positioning information included in the target element and the arrangement sequence between the plurality of element positioning information corresponding to the same target element, so that the positioning accuracy and the recognition efficiency of the element positioning information can be improved. For example, based on the content and attribute ordering of the target element, when the visible element or the visible content exists, the visible content is ensured to be placed in element positioning information, and the element positioning information is placed in the first position of an element positioner list, so that the readability is improved, and the maintenance is convenient; if the attribute information of the target element comprises the change information, deleting the attribute information, and improving the positioning success rate of the positioning information of the subsequent element.
Step S103, according to the element positioning information list and the operation behavior, generating a test case of the tested page.
When in actual recording, each step of operation of the user can generate a corresponding test case, and the test case comprises the operation behaviors of the user and a corresponding element positioning information list. After the test case of the tested page is generated, clicking to stop, and ending recording. After the recording is finished, the plug-in unit starts the tested page and runs the recorded test cases. By reading the operation behaviors and the element positioning information list in each test case, the content script in the plug-in can simulate the user action through a method such as a mouse_event (a computer function) and the like, so that the operation process of the user is restored.
According to the method for generating the test case, based on the attribute information, the path information and the content included in the target element, the element positioning information corresponding to the attribute one by one and the arrangement sequence among the element positioning information are generated, rules and sequences of original element positioning information of the Selenium IDE are improved and optimized, and various element positioning information is added in an element positioning information list. The method not only improves the positioning accuracy, but also can effectively improve the recognition efficiency of the later element positioning information, thereby avoiding the problems of low efficiency and invalid or inaccurate element positioning information in the process of restoring the user operation caused by poor readability of the generated test cases due to the adoption of a fixed arrangement sequence.
In this embodiment, a method for generating a test case is provided, which may be executed by an electronic device, such as a computer, a mobile terminal, etc., and fig. 6 is a flowchart of a method for generating a test case according to an embodiment of the present invention, as shown in fig. 6, where the flowchart includes the following steps:
step S201, obtaining operation behaviors of target elements in the tested page, attribute information of multiple attribute types of the target elements and path information.
The details of step S101 are not repeated here.
Step S202, based on the attribute information, the path information and the contents included in the target element, generating element positioning information corresponding to the attribute one by one and an arrangement sequence between the element positioning information to obtain an element positioning information list.
Specifically, the step S202 includes:
in step S2021, if the content included in the target element has a visible text, the path information is used to find the target element upward to obtain a finding result, and based on the finding result and the visible text included in the target element, a path of the target element is generated to obtain first element positioning information, where the first element positioning information is the first piece of element positioning information in the element positioning information list.
Specifically, the generated path of the target element may be a relative path or an absolute path, if the content contained in the target element has visible text, the path information is utilized to find the uniquely located target element step by step upwards to generate a corresponding path, and xpath path information containing the visible text is generated according to the visible text contained in the target element, so as to obtain the first element location information. The path information and the visible text are adopted as the first element positioning information to perform relative positioning, and the readability is good. Further, if the father-level target element is searched step by step from the target element based on the Xpath path information until a path capable of uniquely positioning the target element is generated, if the root node is not searched, the path at the moment is a relative path, if the root node (such as an HTML node) is searched, the path at the moment is an absolute path, and the Xpath path information and the visible text are combined to generate the first element positioning information. Illustrating: if the target element is div and the upper level is p, the element positioning information is spliced into a relative path// p/div, and the first element positioning information is generated by combining the visible text: xpath=// div/span [ start with= (, 'visible text') ]. Specifically, the visible text contains a plurality of attributes, and "" in the first element location information means all the attributes in the element to which the visible text is matched.
Second, the second piece of element positioning information may be set with a certain attribute of the visible text, for example, in the above example, xpath=// div/span [ @ title= 'visible text' ] is taken as the second piece of element positioning information, and this example indicates the title attribute in the element to which the visible text is matched; then generating element positioning information by using identification id, name, class and the like, and then generating an element positioning information list according to the generation sequence. The list of element positioning information generated according to the rule is shown with reference to fig. 4. In Html, it is only necessary to determine whether the content included in the target element has visible text, and whether the property of the incertext of the target element (incertext is generally used to acquire or set the text content in the Html) has a value.
In some optional embodiments, the step S202 further includes:
step a1, searching parent-level target elements step by step upwards from the target elements;
step a2, if the attribute information of the parent target element has unique identification attribute and has no change information, generating a relative path of the target element by taking the unique identification attribute of the parent target element as a starting point so as to obtain second element positioning information of the target element;
And a3, if the attribute information of the parent target element does not have the unique identification attribute, generating an absolute path of the target element based on the root node corresponding to the tested page where the target element is positioned, so as to obtain second element positioning information of the target element, wherein the second element positioning information is the last element positioning information in the element positioning information list.
The unique identification attribute can be identification id, whether the parent-level target element has identification id or not can be searched step by step from the target element, if the identification id exists, whether the identification id has change information is judged, and when the identification id has no change information, the relative path of the target element is generated based on the identification id as a starting point. Wherein, the change information of the identification id refers to information such as a time stamp; if none of the parent target elements has an identification id, generating an absolute path of the complete target element from the root node, namely, when the root node is searched upwards and the path is returned, the path is the absolute path.
The path xpath is searched up step by step from the current position and then combined by the code logic. If a certain parent target element searched upwards has an identification id and the identification id has no change information (such as no timestamp is included), stopping searching, and generating element positioning information, namely a relative path of the target element. Otherwise, finding out the Html node of the top level, and then, finding out the full path, namely, the absolute path of the target element, so as to ensure that each target element can find the corresponding full path and is unique.
Based on the full path xpath or the second element positioning information generated by the path xpath taking the identification id as the starting point as the last element positioning information in the element positioning information list, the element can be ensured to be positioned by 100% under the condition that the tested page is unchanged.
In some optional embodiments, the step S202 further includes:
step b1, screening the attribute information to remove the attribute information including the change information in the attribute information and obtain other attribute information;
and b2, generating third element positioning information in the element positioning information list based on other attribute information.
Other attribute information may be identification id, name, category class, cascading style css, etc., and change information may be time information, etc. Other attribute information may be filtered, for example, if the attribute information of the id includes information of a change such as a timestamp, the attribute is ignored, that is, the third element location information is generated using other attribute information except the id attribute information. If the visible text exists, the third element positioning information refers to element positioning information located between the first element positioning information and the last element positioning information, and a plurality of third element positioning information can be generated, for example, corresponding element positioning information is generated based on names name, stacking patterns css and the like respectively. If the visible text does not exist, the third element positioning information is other element positioning information except the last element positioning information. As shown in fig. 5, id=ui_ username, name =username, css= #ui_username are the third element positioning information defined herein.
The attribute information containing the change information is removed, the situation that the element positioning information cannot effectively position the target element due to the change of the subsequent change information is avoided, the reliability of the generated element positioning information can be effectively improved, the accuracy of element positioning information positioning is ensured, and the positioning efficiency can be effectively improved.
In some optional embodiments, the step S202 further includes:
and step c1, generating element positioning information based on the attribute information, the path information and contents included in the target element.
And c2, inquiring the element based on the element positioning information.
And c3, if the unique element is queried and the queried element is consistent with the target element, adding the element positioning information into an element positioning information list.
For example, element positioning information generated by using identification id is used for inquiring: if the query selection (the '# userName') can be matched with the target element operated by the user, the successful positioning is indicated, and the plugin adds the element positioning information into the element positioning information list. When all the attribute information is analyzed and matched, a list containing a plurality of element positioning information is generated, namely, each target element corresponds to the element positioning information list.
The target element has a one-to-many relationship with the element location information. In element locating, a specific selector function is used for searching according to the recorded element locating information character string. For example, if the content of the element locator string a is css, the document.
In the searching process, if the relative positions or attributes of a plurality of target elements are the same, firstly ensuring that the searched target elements are unique, and if a plurality of elements are searched, discarding the element positioning information; if the element positioning information is used for finding out that the element is unique, judging whether the found element is equal to the target element, and if so, adding the element positioning information into an element positioning information list corresponding to the target element. That is, after the reverse search and verification are successful, the element positioning information list is added, so that the accuracy and reliability of the positioning of the element positioning information in the element positioning information list are ensured.
After the test cases are generated, the reverse search function in the embodiment can be used for searching and matching so as to improve the positioning accuracy.
Step S203, according to the element positioning information list and the operation behavior, generating a test case of the tested page.
The details of step S103 are not repeated here.
According to the method for generating the test case, the visible text content contained in the target element is fully combined, the visible text and the path information are combined to generate first element positioning information in the element positioning information list, then the parent-level target element is searched step by step upwards according to the target element, and last element positioning information in the element positioning information list is generated based on the absolute path of the target element or path information taking the unique identification attribute (id) as a starting point. Compared with the related art, the rule and the sequence of the element positioning information in the element positioning information list are adjusted, so that the obtained element positioning information list is good in readability, the obtained element positioning information list is ensured to be in line with the actual use condition, and the recognition efficiency and the accuracy of the later-stage element positioning information can be effectively improved.
In this embodiment, a method for generating a test case is provided, which may be executed by an electronic device, such as a computer, a mobile terminal, etc., and fig. 7 is a flowchart of a method for generating a test case according to an embodiment of the present invention, as shown in fig. 7, where the flowchart includes the following steps:
Step S301, obtaining the operation behavior of the target element in the tested page, the attribute information of multiple attribute types of the target element, and the path information.
The details of step S101 are not repeated here.
Step S302, based on the attribute information, the path information and the contents included in the target element, generating element positioning information corresponding to the attribute one by one and an arrangement sequence among the element positioning information to obtain an element positioning information list.
The details of step S202 are not repeated here.
Step S303, according to the element positioning information list and the operation behavior, generating a test case of the tested page.
Specifically, the step S303 includes:
step S3031, test cases of the tested page are generated based on the element positioning information list and the operation behaviors.
Step S3032, the tested page is started and the test case is debugged to update the element positioning information list, so that the updated test case is obtained.
And generating a test step once by the user, and finally generating test cases of the tested page based on multiple operations of the user, wherein the test cases comprise all the test steps, and the plug-in can automatically start the tested page and run the recorded test cases by clicking local debugging. And simulating the action of the user by reading the operation behaviors and the element positioning information list in each test case, so as to restore the operation process of the user. In the restoration process, the test case can be debugged, corrected or replaced, and the like, so that the updated test case can be obtained.
And debugging the generated test case again, so that the positioning accuracy of the element positioning information list can be effectively ensured.
In some optional embodiments, the updating the element positioning information list in step S3032 to obtain an updated test case includes:
and d1, extracting first element positioning information in the element positioning information list to search the element.
And d2, if the element searching fails, extracting target element positioning information which can successfully find the target element from the element positioning information list.
Specifically, if the first element positioning information element fails to find, the elements are found by using other element positioning information according to the sequence in the element positioning information list until the target element is found.
And d3, determining a target element based on the target element positioning information, and analyzing the determined target element to obtain attribute information and path information of the target element.
And d4, regenerating an element positioning information list of the target element based on the determined attribute information and path information and according to the same mode of generating the element positioning information list, so as to obtain an updated test case.
In general, the plug-in will first take the first element location information from the element location information list to search for the element. If part of the attributes of the elements in the tested page change, when the first element positioning information fails to search, the plug-in unit can take out other element positioning information from the element positioning information list according to the sequence in the element positioning information list to position until the target element is searched. After the search is successful, the plug-in unit re-analyzes the attribute information and the path information xpath of the target element, and generates a new element positioning information list according to the logic in the recording process, and the correction log can refer to fig. 8 to obtain an updated test case.
The present embodiment is adopted only when the target element cannot be found by the current element positioning information selected in the target frame. The application scene is: the later tested page is changed, and part of the attributes or positions of the elements are changed, so that part of the element positioning information list is invalid. If some other element positioning information in the list can still be positioned, the whole element positioning information list can be automatically updated, the real-time effectiveness of the element positioning information is ensured, and the user is not required to record the target element manually.
When the current element positioning information selected in the target frame cannot find the target element, the target element can be continuously found according to other element positioning information, and after the target element positioning information is found, an element positioning information list can be automatically corrected, so that the positioning accuracy of the page to be tested after the page to be tested is changed is further improved.
In some optional embodiments, the updating the element positioning information list in step S3032 to obtain an updated test case includes:
and e1, if the element positioning information currently debugged is path element positioning information and the digital index exists, activating an index control on the debug page.
And e2, acquiring interactive operation of the index control, and cutting off the currently debugged element positioning information from the first position with the digital index to obtain parent element positioning information.
And e3, determining and displaying the corresponding parent element based on the parent element positioning information.
And e4, acquiring a selection operation in the parent element, and determining a relative path corresponding to the selection operation.
And e5, replacing the digital index in the currently debugged element positioning information based on the relative path, and updating the currently debugged element positioning information to obtain an updated test case.
Because there are often table and ul (table is an Html element for creating a table on a web page, ul is an abbreviation for creating an unordered list, and is generally used for creating an unordered list) and other elements in the tested page, the sub-elements of these lists often undergo sequential changes. When the sequence is changed, the elements searched according to the element positioning information list are not wanted by the user, so that the test case fails to execute. At this time, the user can perform secondary element positioning through the intelligent indexing function provided by the plug-in, so as to lock specific data. When the sequence of the elements is changed, the plug-in units can be positioned normally. The method comprises the following steps:
when the currently debugged element positioning information is path element positioning information xpath, and a digital index [ index ] exists in the xpath, other elements exist under the same level of the positioning information, such as: xpath=// tr [2]/td [3]/div/span [ starts-with (, 'edit') ]. At this time, the index control is activated, that is, an intelligent index button is added to the right of the element positioning information input box. Reference may be made to fig. 9a and 9b, where fig. 9a is visual element positioning information provided by the plug-in and fig. 9b is a measured page. That is, the smart index button will be automatically illuminated when there are numbers in the selected element locator information string in the target frame. The user can autonomously judge whether the selection is to be subjected to intelligent index replacement or not.
Clicking on the Smart index button icon, the plug-in will truncate from the first band index position in the xpath. Such as: the// tr [2]/td [3]/div/span process becomes// tr [2], and the processed xpath is used for positioning and highlighting, as shown in FIG. 10 (thick line box area in FIG. 10). Specifically, if the index has the number, it indicates that the same-level brother node exists in the index, and the parent-level element positioning information needs to be positioned to the position, so that the position of the brother element which is the same as the parent-level element positioning information can be avoided, and the user can select more accurate content continuously. The way to locate this can be to remove the path behind the number, the intelligent index can only replace one number at a time, if there are numbers after replacement, the intelligent index button can be clicked again to continue replacement.
The user may continue to select elements in the highlight region such as: by selecting the other text ipc98_audio_code_type in the tr line, the plug-in will replace the index in the original element positioning information with the x path opposite path selected twice, which can be shown in fig. 11. After the replacement is complete, an xpath lookup can be performed with $x. If the search is successful, the new xpath passes the verification, and the plug-in can replace the original element positioning information. And then, even if the element position changes, positioning can be performed according to the keywords, wherein the keywords are words selected in the height area after the user clicks the intelligent index button.
What needs to be stated is: the intelligent index button function is a pre-operation executed by a user, and is used for avoiding errors occurring after the errors occur in the positioning target element. That is, if there are elements such as tables and ul in the tested page, these list sub-elements are likely to change, and in order to prevent the sub-elements from changing in order, the element positioning information list is incorrect according to the target element positioned by the path. When the element positioning type is xpath and index exists in the xpath path, the plug-in triggers and displays an intelligent index button, and a user can click the intelligent index button to replace the index in the original element positioning information with a relative path. That is, the highlighted data element in the diagram is not changed or wrong, but the user expects that the element is changed in a large program, and the element positioning information is corrected secondarily; for example, for a table, the original path of the element positioned by the element positioning information is a unit cell of the third row and the third column of the table, but since the table is changed later, for example, new data is updated, the element may become the fourth row or the fifth row data, and when the element is positioned by using the element positioning information later, the third row and the third column are searched, but at this time, the third row and the third column are not the target element. Therefore, in order to avoid this, before the content script is executed, the element is located by using the keyword corresponding to the line where the element is located, if "Zhang Sanu" is selected, then the element location information becomes to find the line where "Zhang Sanu" is located, and even if the line where the element is located changes, the element can be accurately located.
By adding the intelligent indexing function, when the currently debugged element positioning information is path element positioning information and the numerical index exists, the intelligent indexing button can be utilized to perform secondary element positioning on the element positioning information, so that the target element can still be positioned accurately after the sequence of the target element is changed, and the accuracy of element positioning information positioning is improved.
Further, after the debugging is completed, clicking to finish the debugging and clicking to save. The complete test case is synchronized to the server in the form of a side file. The user may again modify the saved test case. Clicking the local debug button returns to local debug. The generated test cases can also independently run on the server side and can be matched with timing instructions to finish complex test tasks such as daily inspection and the like.
The method for generating the test case realizes high element positioning stability during automatic recording. Different effects can be achieved by being matched with different test platforms, scripts produced by the automatic recording tool are transmitted to the server side to be executed in cooperation with timing tasks, and automatic execution of test cases is achieved. Because of the high stability of script execution, the method is currently used for daily inspection of on-site projects, and the inspection efficiency, accuracy and timeliness of on-site operation and maintenance personnel on web sites are greatly improved.
The embodiment also provides a device for generating a test case, which is used for implementing the above embodiment and the preferred implementation manner, and is not described in detail. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. While the means described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and contemplated.
The present embodiment provides an apparatus for generating a test case, as shown in fig. 12, including:
an obtaining module 401, configured to obtain operation behaviors of a target element in a tested page, attribute information of multiple attribute types of the target element, and path information;
an element positioning information generating module 402, configured to generate element positioning information corresponding to the attribute one-to-one and an arrangement sequence between the element positioning information based on the attribute information, the path information, and contents included in the target element, so as to obtain an element positioning information list;
the test case generation module 403 generates a test case of the tested page according to the element positioning information list and the operation behavior.
In some alternative embodiments, the element location information generation module 402 includes:
The first generation unit is used for searching upwards by utilizing the path information to obtain a searching result if the content included in the target element has a visible text, and generating the path of the target element based on the searching result and the text included in the target element to obtain first element positioning information, wherein the first element positioning information is first element positioning information in an element positioning information list.
In some alternative embodiments, the element positioning information generation module 402 further includes:
the searching unit is used for searching the parent-level target element step by step upwards from the target element;
the second generation unit is used for generating a relative path of the target element by taking the unique identification attribute of the parent target element as a starting point if the unique identification attribute exists in the attribute information of the parent target element and no change information exists, so as to obtain second element positioning information of the target element; and if the attribute information of the parent target element does not have the unique identification attribute, generating an absolute path of the target element based on the root node corresponding to the tested page where the target element is located, so as to obtain second element positioning information of the target element, wherein the second element positioning information is the last element positioning information in the element positioning information list.
In some alternative embodiments, the element positioning information generation module 402 further includes:
the screening unit is used for screening the attribute information to remove the attribute information comprising the change information from the attribute information and obtain other attribute information;
and a third generation unit configured to generate third element positioning information in the element positioning information list based on the other attribute information.
In some alternative embodiments, the element location information generation module 402 includes:
a fourth generation unit configured to generate element positioning information based on the attribute information, the path information, and contents included in the target element;
the query unit is used for querying the elements based on the element positioning information;
and the adding unit is used for adding the element positioning information into the element positioning information list if the unique element is inquired and the inquired element is consistent with the target element.
In some alternative embodiments, the test case generation module 403 includes:
the test case generation unit is used for generating a test case of the tested page based on the element positioning information list and the operation behavior after recording;
and the test case updating unit is used for starting the tested page and debugging the test case so as to update the element positioning information list and obtain an updated test case.
In some alternative embodiments, the test case update unit includes:
the extraction subunit is used for extracting the first element positioning information in the element positioning information list to perform element searching;
the searching subunit is used for extracting target element positioning information which can successfully find the target element from the element positioning information list if the element searching fails;
the determining subunit is used for determining a target element based on the target element positioning information, and analyzing the determined target element to obtain attribute information and path information of the target element;
and the updating subunit is used for regenerating the element positioning information list of the target element based on the determined attribute information and the path information and according to the same mode of generating the element positioning information list so as to obtain an updated test case.
In some alternative embodiments, the test case update unit includes:
an activating subunit, configured to activate an index control on the debug page if the element positioning information currently debugged is path element positioning information and there is a digital index;
the truncated subunit is used for acquiring interactive operation of the index control, and carrying out truncated processing on the currently debugged element positioning information from the first position with the digital index to obtain parent element positioning information;
The positioning subunit is used for determining and displaying the corresponding parent element based on the parent element positioning information;
an operation subunit, configured to obtain a selection operation for the inside of the parent element, and determine a relative path corresponding to the selection operation;
and the replacing subunit is used for replacing the digital index in the currently debugged element positioning information based on the relative path, and updating the currently debugged element positioning information to obtain an updated test case.
The apparatus for generating test cases in this embodiment is presented in the form of functional units, where the units refer to ASIC circuits, processors and memories that execute one or more software or firmware programs, and/or other devices that may provide the functionality described above.
Further functional descriptions of the above respective modules and units are the same as those of the above corresponding embodiments, and are not repeated here.
The embodiment of the invention also provides electronic equipment, which is provided with the device for generating the test case shown in the figure 12.
Referring to fig. 13, fig. 13 is a schematic structural diagram of an electronic device according to an alternative embodiment of the present invention, as shown in fig. 13, the electronic device includes: one or more processors 10, memory 20, and interfaces for connecting the various components, including high-speed interfaces and low-speed interfaces. The various components are communicatively coupled to each other using different buses and may be mounted on a common motherboard or in other manners as desired. The processor may process instructions executing within the electronic device, including instructions stored in or on memory to display graphical information of the GUI on an external input/output device, such as a display device coupled to the interface. In some alternative embodiments, multiple processors and/or multiple buses may be used, if desired, along with multiple memories and multiple memories. Also, multiple electronic devices may be connected, each providing a portion of the necessary operations (e.g., as a server array, a set of blade servers, or a multiprocessor system). One processor 10 is illustrated in fig. 13.
The processor 10 may be a central processor, a network processor, or a combination thereof. The processor 10 may further include a hardware chip, among others. The hardware chip may be an application specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general-purpose array logic, or any combination thereof.
Wherein the memory 20 stores instructions executable by the at least one processor 10 to cause the at least one processor 10 to perform the methods shown in implementing the above embodiments.
The memory 20 may include a storage program area that may store an operating system, at least one application program required for functions, and a storage data area; the storage data area may store data created from the use of the electronic device of the presentation of one applet landing page, and the like. In addition, the memory 20 may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, memory 20 may optionally include memory located remotely from processor 10, which may be connected to the electronic device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk, or solid state disk; the memory 20 may also comprise a combination of the above types of memories.
The electronic device also includes a communication interface 30 for the electronic device to communicate with other devices or communication networks.
The embodiments of the present invention also provide a computer readable storage medium, and the method according to the embodiments of the present invention described above may be implemented in hardware, firmware, or as a computer code which may be recorded on a storage medium, or as original stored in a remote storage medium or a non-transitory machine readable storage medium downloaded through a network and to be stored in a local storage medium, so that the method described herein may be stored on such software process on a storage medium using a general purpose computer, a special purpose processor, or programmable or special purpose hardware. The storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, a solid state disk or the like; further, the storage medium may also comprise a combination of memories of the kind described above. It will be appreciated that a computer, processor, microprocessor controller or programmable hardware includes a storage element that can store or receive software or computer code that, when accessed and executed by the computer, processor or hardware, implements the methods illustrated by the above embodiments.
Although embodiments of the present invention have been described in connection with the accompanying drawings, various modifications and variations may be made by those skilled in the art without departing from the spirit and scope of the invention, and such modifications and variations fall within the scope of the invention as defined by the appended claims.

Claims (10)

1. A method of generating test cases, the method comprising:
acquiring operation behaviors of target elements in a tested page, attribute information of multiple attribute types of the target elements and path information;
generating element positioning information corresponding to the attributes one by one and an arrangement sequence among the element positioning information based on the attribute information, the path information and the contents included by the target elements so as to obtain an element positioning information list;
and generating the test case of the tested page according to the element positioning information list and the operation behavior.
2. The method according to claim 1, wherein generating element positioning information corresponding to attributes one by one and an arrangement order between the element positioning information based on the attribute information, the path information, and contents included in the target element to obtain an element positioning information list includes:
If the content included in the target element has a visible text, searching upwards by utilizing the path information to obtain a searching result, and generating a path of the target element based on the searching result and the visible text included in the target element to obtain first element positioning information, wherein the first element positioning information is first element positioning information in the element positioning information list.
3. The method according to claim 1, wherein generating element positioning information corresponding to attributes one by one and an arrangement order between the element positioning information based on the attribute information, the path information, and contents included in the target element to obtain an element positioning information list includes:
searching parent-level target elements step by step upwards from the target elements;
if the attribute information of the parent target element has unique identification attribute and has no change information, generating a relative path of the target element by taking the unique identification attribute of the parent target element as a starting point so as to obtain second element positioning information of the target element;
if the unique identification attribute does not exist in the attribute information of the parent target element, generating an absolute path of the target element based on a root node corresponding to a tested page where the target element is located, so as to obtain second element positioning information of the target element, wherein the second element positioning information is last element positioning information in the element positioning information list.
4. The method according to claim 1, wherein the generating element positioning information corresponding to attributes one by one and an arrangement order between the element positioning information based on the attribute information, the path information, and contents included in the target element to obtain an element positioning information list, further comprises:
screening the attribute information to remove the attribute information including the change information in the attribute information and obtain other attribute information;
and generating third element positioning information in the element positioning information list based on the other attribute information.
5. The method according to claim 1, wherein generating element positioning information corresponding to attributes one by one and an arrangement order between the element positioning information based on the attribute information, the path information, and contents included in the target element to obtain an element positioning information list includes:
generating element positioning information based on the attribute information, the path information and contents included in the target element;
querying the element based on the element positioning information;
and if the unique element is queried and the queried element is consistent with the target element, adding the element positioning information into the element positioning information list.
6. The method according to any one of claims 1 to 5, wherein generating test cases from the list of element positioning information and the operation behavior comprises:
generating a test case of the tested page based on the element positioning information list and the operation behavior;
and starting the tested page and debugging the test case to update the element positioning information list to obtain an updated test case.
7. The method of claim 6, wherein updating the element positioning information list to obtain an updated test case comprises:
extracting first element positioning information in the element positioning information list to perform element searching;
if the element searching fails, extracting target element positioning information which can successfully find the target element from the element positioning information list;
determining the target element based on the target element positioning information, and analyzing the determined target element to obtain attribute information and path information of the target element;
and regenerating the element positioning information list of the target element based on the determined attribute information and path information and in the same mode of generating the element positioning information list so as to obtain an updated test case.
8. The method of claim 6, wherein updating the element positioning information list to obtain an updated test case comprises:
if the element positioning information currently debugged is path element positioning information and the digital index exists, activating an index control on a debugging page;
acquiring interactive operation of the index control, and cutting off the currently debugged element positioning information from a first position with a digital index to obtain parent element positioning information;
determining and displaying corresponding parent elements based on the parent element positioning information;
acquiring a selection operation in the parent element, and determining a relative path corresponding to the selection operation;
and replacing the digital index in the currently debugged element positioning information based on the relative path, and updating the currently debugged element positioning information to obtain an updated test case.
9. An electronic device, comprising:
a memory and a processor, the memory and the processor being communicatively coupled to each other, the memory having stored therein computer instructions, the processor executing the method of generating test cases of any of claims 1-8 by executing the computer instructions.
10. A computer-readable storage medium storing computer instructions for causing the computer to perform the method of generating test cases of any one of claims 1-8.
CN202311763164.5A 2023-12-20 2023-12-20 Method for generating test case, electronic equipment and storage medium Pending CN117762786A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311763164.5A CN117762786A (en) 2023-12-20 2023-12-20 Method for generating test case, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311763164.5A CN117762786A (en) 2023-12-20 2023-12-20 Method for generating test case, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117762786A true CN117762786A (en) 2024-03-26

Family

ID=90311857

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311763164.5A Pending CN117762786A (en) 2023-12-20 2023-12-20 Method for generating test case, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117762786A (en)

Similar Documents

Publication Publication Date Title
US10613971B1 (en) Autonomous testing of web-based applications
US9507700B1 (en) Generic method for automated software testing
CN102804147B (en) Perform the code check executive system of the code check of ABAP source code
CN111832236B (en) Chip regression testing method and system, electronic equipment and storage medium
CN108762743B (en) Data table operation code generation method and device
US8875103B2 (en) Method of testing multiple language versions of a software system using one test script
CN104657274B (en) software interface test method and device
CN111108481B (en) Fault analysis method and related equipment
CN113177168B (en) Positioning method based on Web element attribute characteristics
CN112241370B (en) API interface class checking method, system and device
CA3112132A1 (en) Improved spreadsheet and method for updating same
CN111679976A (en) Method and device for searching page object
CN112799718A (en) Enumerated document generation method and device, electronic equipment and storage medium
CN111949607A (en) Method, system and device for monitoring UDT file
CN111427577A (en) Code processing method and device and server
US20230195825A1 (en) Browser extension with automation testing support
CN117762786A (en) Method for generating test case, electronic equipment and storage medium
CN115238655A (en) Json data editing method and device
CN115481025A (en) Script recording method and device for automatic test, computer equipment and medium
US20220237108A1 (en) Source traceability-based impact analysis
CN112579456A (en) Web automatic testing method and device
CN112257392A (en) Method, device and equipment for generating computer program operation document
US11995146B1 (en) System and method for displaying real-time code of embedded code in a browser-window of a software application
US20240176728A1 (en) Plug and play language acceptance testing
EP4386562A1 (en) Automated testing of database commands

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination