Selector processing method and device, equipment and medium
By obtaining and processing information of web page elements, the optimization selector is automatically generated, which solves the problem of insufficient stability and uniqueness of selectors in automated tests, and improves the reliability and effectiveness of web page tests.
Patent Information
- Application Number
- CN202411215149.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-12-06
AI Technical Summary
In the existing automated testing tools, the generation and maintenance of selectors have insufficient stability and uniqueness in web testing, especially in complex and dynamically changing web structures, which leads to frequent failure of selectors, affecting the effectiveness of tests and reliability.
By obtaining the element information of the target element, extracting its target features and inputting the selector generation model, automatically generate an optimized selector, and saving it in the test file to locate the target element during subsequent testing, and improve the selector's Stability and uniqueness.
It significantly improves the stability and uniqueness of the selector, reduces the selector failure caused by dynamic changes, improves the effectiveness and reliability of web page testing, and reduces manual maintenance costs.
Smart Images

Figure CN119088703A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of automated testing technology, and in particular to a selector processing method, device, equipment and medium. Background Art
[0002] Automated testing tools face huge technical challenges in web page testing, especially the generation and maintenance of selectors for web page elements. In related technologies, selectors are usually generated based on the static attributes, combinations or hierarchies of web page elements. However, when the web page content is complex and changes frequently, the stability and uniqueness of the selector are difficult to guarantee, which may cause the selector to fail and the test to be interrupted, affecting the effectiveness and reliability of the test. Summary of the invention
[0003] In order to solve the above technical problems, the present disclosure provides a selector processing method, device, equipment and medium.
[0004] The present disclosure provides a selector processing method, the method comprising:
[0005] In response to a selection operation on a target element, acquiring element information of the target element;
[0006] Determining a target feature of the element information of the target element;
[0007] Input the target feature into a selector generation model, and output a first target selector corresponding to the target element;
[0008] The first target selector of the target element is saved in a test file, so as to locate the target element based on the first target selector in the test file during the test process.
[0009] The present disclosure also provides a selector processing device, the device comprising:
[0010] An acquisition module, configured to acquire element information of a target element in response to a selection operation on the target element;
[0011] A feature module, used to determine a target feature of the element information of the target element;
[0012] A generation module, used for inputting the target feature into a selector generation model, and outputting a first target selector corresponding to the target element;
[0013] A saving module is used to save the first target selector of the target element into a test file, so as to locate the target element based on the first target selector in the test file during the test process.
[0014] An embodiment of the present disclosure also provides an electronic device, comprising: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the selector processing method provided in the embodiment of the present disclosure.
[0015] The embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the selector processing method provided by the embodiment of the present disclosure.
[0016] The technical solution provided by the embodiment of the present disclosure has the following advantages over the prior art: the selector processing solution provided by the embodiment of the present disclosure obtains the element information of the target element in response to the selection operation of the target element; determines the target feature of the element information of the target element; inputs the target feature into the selector generation model, and outputs the first target selector corresponding to the target element; saves the first target selector of the target element into the test file, so as to locate the target element based on the first target selector in the test file during the test process. With the above technical solution, by extracting the element information of the target element selected by the user and automatically generating an optimized selector using the selector generation model, the target element can be located in the subsequent test process. Generating the selector through the model can significantly improve the stability and uniqueness of the selector, reduce the problem of test interruption caused by selector failure caused by dynamic changes, and thus improve the effectiveness and reliability of web page testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0018] Figure 1 A flowchart of a selector processing method provided by an embodiment of the present disclosure;
[0019] Figure 2 A flowchart of another selector processing method provided by an embodiment of the present disclosure;
[0020] Figure 3 A schematic diagram of a training process of a selector generation model provided in an embodiment of the present disclosure;
[0021] Figure 4 A schematic diagram of a selector generation process provided by an embodiment of the present disclosure;
[0022] Figure 5 A schematic diagram of a selector adjustment process provided by an embodiment of the present disclosure;
[0023] Figure 6 A schematic diagram of the structure of a selector processing device provided in an embodiment of the present disclosure;
[0024] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0026] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0027] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0028] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0029] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0030] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0031] Selectors are the key to locating web page elements in automated testing. Once the selector generation is unstable or invalid, the entire test case cannot be executed normally. The generation of selectors in related technologies is generated in the following ways: 1. Selector generation based on static attributes such as identification (ID), class (class), tag name (tagName), etc. The stability and uniqueness of these attributes directly affect the effectiveness of the selector; 2. Combination and hierarchical selectors. When a single attribute cannot uniquely locate an element, the test tool will combine multiple attributes, such as using hierarchical selectors. In this way, the uniqueness of the selector can be improved to a certain extent.
[0032] The existing selector generation methods based on static attributes and simple hierarchical relationships have limited effects in complex web page structures, and it is difficult to generate stable selectors and cannot adapt to complex web page structures. Specifically, there are the following defects: 1. The fragility of the selector. Since the structure of the website's Document Object Model (DOM) is very complex, the attributes of the elements often change, especially when the page is dynamically updated or the content is generated by JavaScript, these attributes are more likely to change, resulting in selector failure. 2. The uniqueness of the selector is insufficient. Relying solely on a single static attribute, these selectors may not guarantee to uniquely identify an element in the entire page, especially in complex pages, where multiple elements may have the same class attribute or no clear identification attribute, resulting in the generated selector being unable to uniquely identify the target element. 3. Unable to cope with dynamic content changes. With the development of front-end technology, web page content is increasingly dynamically generated and modified by JavaScript. The traditional selector generation method that relies on static attributes is difficult to adapt to the environment where dynamic content changes frequently, resulting in the selector being prone to frequent failure. In summary, existing automated testing tools face problems of insufficient stability and uniqueness in selector generation and maintenance. In particular, selector failure is particularly prominent in web pages with dynamic content and complex document object model structures. These problems seriously affect the effectiveness and reliability of automated testing. An innovative method is needed to solve these challenges in selector generation.
[0033] In order to solve the above problems, an embodiment of the present disclosure provides a selector processing method, which is introduced below in conjunction with a specific embodiment.
[0034] Figure 1 The present invention provides a flow chart of a selector processing method provided by an embodiment of the present invention. The method can be executed by a selector processing device, wherein the device can be implemented by software and / or hardware and can generally be integrated in an electronic device. Figure 1 As shown, the method includes:
[0035] Step 101: In response to a selection operation on a target element, obtain element information of the target element.
[0036] Among them, the target element can be the web page element corresponding to the user's selection operation on the current page. The selection operation can include click, long press, double click, input and other operations, without limitation. The web page element can be the basic unit that constitutes the content and structure of the web page, and can include text, pictures, links, multimedia content, etc.
[0037] The element information of the target element may include the attribute information of the target element, the hierarchical information of the target element on the web page where it is located, and the contextual information. The attribute information of the target element may include static attributes such as the target element's identification (ID), class list (classList), tag name (tagName), global attributes (data-* attributes), etc. These static attributes directly reflect the characteristics of the target element. The hierarchical information of the target element on the web page where it is located may include the number and attribute information of the target element's parent nodes, the number and attribute information of the child nodes, the number and attribute information of the sibling nodes, the position of the target element in the sibling nodes, etc., which may be obtained by recursive acquisition. The contextual information of the target element on the web page where it is located may include the attribute information and hierarchical information of other elements near the target element, the position and attributes of other elements in the document object model tree, etc.
[0038] Specifically, the selector processing device may receive a user's selection operation on a target element, and then may use a data collection tool to obtain element information of the target element.
[0039] Step 102: Determine target features of element information of the target element.
[0040] Among them, the target feature can be a feature vector obtained by extracting and vectorizing the element information of the target element. The target feature includes rich context, hierarchy and other information and is suitable for input model.
[0041] Specifically, after obtaining the element information of the target element, the selector processing device can extract high-level features from the element information of the target element, which can include using the context information of the target element in the web page to extract the position of the target element in the document object model, including node depth, number of adjacent sibling nodes, leaf nodes, etc., and extracting the relative position and importance of the target element in the web page. The relative position can include, for example, whether it is in the main view area, etc., and the importance can include, for example, whether it contains interactive functions such as click and input. Afterwards, the element information of the target element and the above-mentioned high-level features can be normalized and standardized to generate the corresponding target features. Ensure that the dimension of the feature vector of the target feature is uniform and the numerical range is reasonable.
[0042] In some embodiments, determining the target feature of the element information of the target element may include: encoding the attribute information in the element information of the target element to obtain a first feature vector; numerating the hierarchical information in the element information of the target element to obtain a second feature vector; vectorizing the context information in the element information of the target element to obtain a third feature vector; combining, normalizing and standardizing the first feature vector, the second feature vector and the third feature vector to obtain the target feature.
[0043] When determining the target feature of the target element, the selector processing device can encode the attribute information in the element information of the target element to obtain a first feature vector. Specifically, the identification information and the global attributes in the attribute information can be encoded and added to the first feature vector, the class list in the attribute information can be one-hot encoded and added to the first feature vector, and the label name in the attribute information can be label encoded and added to the first feature vector; the hierarchical information in the element information of the target element can be numerically processed to obtain a second feature vector; the upper and lower information in the element information of the target element can be vectorized to obtain a third feature vector; and then the first feature vector, the second feature vector and the third feature vector can be combined to obtain a high-dimensional feature vector, and the high-dimensional feature vector can be normalized and standardized to obtain the target feature.
[0044] Step 103: Input the target feature into the selector generation model, and output a first target selector corresponding to the target element.
[0045] A selector can be a mechanism in Cascading Style Sheets (CSS) for selecting Hypertext Markup Language (HTML) elements to which style rules will be applied. It can be represented by a string, and depending on the selection basis, the selector can include an identifier selector, a class selector, a tag name selector, a combination selector, a hierarchical selector, etc. For an element, an identifier selector can be used first, because the identifier is usually unique on a page. If the element does not have a unique identifier, a class selector can be used. When neither the identifier nor the class is available, a tag name selector can be used. When a single attribute cannot uniquely locate an element, a combination selector can be used in combination with multiple attributes, or a hierarchical selector can be selected through a parent-child relationship or a sibling relationship. The first target selector can be a selector that can be screened from multiple selectors corresponding to the target element in the embodiment of the present disclosure to ensure uniqueness and validity.
[0046] The selector generation model can be a model for generating unique and stable selectors for web page elements. The selector generation model can select a model architecture suitable for processing the document object model structure and context information to ensure that the model can handle long sequence data and complex context dependencies.
[0047] Specifically, after determining the target feature of the element information of the target element, the selector processing device may input the target feature into the selector generation model for forward reasoning, and output a first target selector corresponding to the target element.
[0048] In some embodiments, before the above step 103, the selector processing method may also include: obtaining a selector sample data set, wherein the selector sample data set includes multiple sample data, each sample data includes a sample element and its corresponding selector label; training a basic model based on the selector sample data set to obtain a selector generation model.
[0049] Among them, the selector sample data set can be a data set used to train the above-mentioned selector generation model, and can include multiple selected sample data. Specifically, a large number of elements and attribute information, hierarchical information and context information before and after the change can be collected from various types of web pages to generate the multiple sample data. Each sample data includes a sample element and a stable selector before and after the change of the sample element manually annotated by experienced experts as a selector label. The selector label can uniquely and stably label the sample element and is still valid even when the document object model structure of the page changes.
[0050] The selector processing device can obtain a selector sample data set, specifically, a large amount of web page data can be collected using a data collection tool, and the data can be labeled after data cleaning and formatting to obtain the final selector sample data set; then the selector sample data set can be used to train the basic model, and a supervised learning method can be used to guide the model to update weights by calculating a loss function, where the loss function can include a cross entropy loss function, and the model parameters are continuously iterated to maximize the accuracy of the selector prediction to obtain a trained selector generation model. Then, the selector generation model is used to generate the first target selector of the target element.
[0051] Step 104: Save the first target selector of the target element into the test file, so as to locate the target element based on the first target selector in the test file during the test process.
[0052] The test file may be a file used in a web page automated testing process, and the test file may be an automated testing code file, a configuration file or a database of an automated testing tool, and the like.
[0053] After determining the first target selector of the target element, the selector processing device can output the first target selector. The format of the first target selector can be a string or a JSON object. The first target selector is saved in a test file for use in automated testing or other operations. The embodiment of the present disclosure takes web page automated testing as an example. During the automated testing of the web page where the target element is located, the first target selector in the test file can be called to locate the target element and test the target element.
[0054] Optionally, the embodiment of the present disclosure may also record the generation process and results of the first target selector into a log to facilitate subsequent tracking and debugging. The recorded content may include element information of the target element, generated target features, the first target selector generated by the selector generation model, and verification results.
[0055] The selector processing scheme provided by the embodiment of the present disclosure obtains the element information of the target element in response to the selection operation of the target element; determines the target feature of the element information of the target element; inputs the target feature into the selector generation model, and outputs the first target selector corresponding to the target element; saves the first target selector of the target element into the test file, so as to locate the target element based on the first target selector in the test file during the test process. By adopting the above technical scheme, by extracting the element information of the target element selected by the user, and automatically generating an optimized selector using the selector generation model, the target element can be located in the subsequent test process. Generating the selector through the model can significantly improve the stability and uniqueness of the selector, reduce the problem of test interruption caused by selector failure caused by dynamic changes, and thus improve the effectiveness and reliability of web page testing.
[0056] The dynamic changes of web pages may include the following: logo changes, developers may change the logo of web page elements at any time, thus invalidating the selectors that rely on the logo; class changes, class attributes are usually used for multiple different elements, and the class attributes of the same element will change frequently to adapt to different styles and states; tag changes, with the continuous evolution of web page design, the tag structure may change, especially when modifying the front-end framework, resulting in the invalidation of selectors based on specific tags; dynamic content such as single-page applications is dynamically loaded and updated through JavaScript, making selector generation and maintenance more difficult; user interaction operations may trigger changes in the web page document object model tree, such as the insertion of new elements, the deletion of old elements and changes in attributes, all of which put higher requirements on the stability of the selector.
[0057] In the related art, when a selector fails, manual maintenance and updating of the selector is required, especially in web pages where the document object model structure changes frequently. This will greatly increase the maintenance cost and lead to high manual maintenance costs. In addition, when the selector of an automated test case fails, it is difficult for existing tools to quickly and automatically adjust, resulting in test interruption and low automated fault tolerance.
[0058] For the above problems, for example, Figure 2 A flow chart of another selector processing method provided by an embodiment of the present disclosure is shown as follows: Figure 2 As shown, in a feasible implementation manner, the selector processing method of the embodiment of the present disclosure may also include the following steps:
[0059] Step 201: Perform a validity check on the first target selector to determine a validity check result.
[0060] The first target selector may be the selector generated by the selector generation model, or may include other selectors that are currently being used in the webpage and need to be verified, which is determined according to actual conditions. The validity detection result may include two types: the first target selector is invalid and the first target selector is valid.
[0061] Specifically, the selector processing device can perform validity detection by querying whether the first target selector uniquely matches the target element in the document object model tree of the web page where it is located. Specifically, the first target selector can be used to query the number of matching elements on the web page where the target element is located; if the number of matching elements is only one, and the element matched by the first target selector is the target element, then the validity detection result is determined to be that the first target selector is valid; otherwise, if the number of matching elements queried by the first target selector is multiple or zero, then the validity detection result is determined to be that the first target selector is invalid.
[0062] Step 202: If it is determined that the validity check result is that the first target selector is invalid, new element information of the target element is obtained.
[0063] The new element information may be the element information obtained for the target element when it is determined that the first target selector is invalid, and the attribute information, hierarchical information and context information of the target element may be extracted according to the document object model structure of the current web page. If the selector processing device determines that the validity detection result of the first target selector is that the first target selector is invalid, the new element information may be obtained for the target element.
[0064] Optionally, after determining that the first target selector is invalid, the number of matching elements of the validity check query of the first target selector and the reason for the invalidation can be recorded to generate a list of invalid selectors. The reason for the invalidation can be determined by analyzing the change event list of the web page where the target element is located. The change event list can monitor the document object model tree in real time through a change observer to capture events such as the addition, deletion, and property modification of nodes, record the changed elements and their property changes, and perform preliminary processing on the changed data, such as deduplication and classification. The change observer can pre-set observation options such as whether to observe the addition or deletion of target child nodes, whether to observe node property changes, and whether to monitor changes in descendant nodes.
[0065] In some embodiments, after determining that the validity check result is that the first target selector is invalid, the selector processing method may also include: determining whether the number of failures of the first target selector reaches a number threshold and whether the calling frequency of the selector generation model is less than the frequency threshold; obtaining new element information of the target element, including: if the number of failures of the first target selector reaches a number threshold and the calling frequency of the selector generation model is less than the frequency threshold, then obtaining the new element information of the target element; otherwise, continue to return for judgment.
[0066] The number of failures of the first target selector may be the number of times the validity test result obtained by performing the validity test on the first target selector is invalid, and the number threshold may be set according to the actual situation, for example, the number threshold may be set to 5. The calling frequency of the selector generation model may be determined according to the number of times the selector generation model is called within a preset time, and the preset time may be set according to the actual situation, for example, the preset time may be one day, and the frequency threshold may be a maximum value set for the calling frequency, and the frequency threshold may be set according to the actual situation.
[0067] After determining that the validity check result is that the first target selector is invalid, the selector processing device can count the number of failures of the first target selector and the calling frequency of the selector generation model, and determine whether the number of failures of the first target selector is greater than or equal to the number threshold, and whether the calling frequency of the selector generation model is less than the frequency threshold. If so, the operation of obtaining new element information of the target element can be performed; otherwise, no operation can be performed, and the judgment can be continued after the next validity check result is determined to be the failure of the first target selector. By setting the number threshold of the number of failures and the frequency threshold of the calling frequency of the selector generation model, performance problems caused by frequent failure detection and frequent calls to the selector generation model can be avoided.
[0068] Step 203: Generate a second target selector of the target element by using a selector generation model based on the new element information of the target element.
[0069] The second target selector may be a selector of a target element that is re-determined after the first target selector becomes invalid.
[0070] After obtaining the new element information of the target element, the selector processing device can use the above-mentioned step 102 to determine the high-dimensional features corresponding to the new element information, and then input the high-dimensional features into the selector generation model for forward reasoning, and output a second target selector for the target element. The second target selector can then be verified to ensure that the target element is uniquely identified in the current web page.
[0071] Step 204: Replace the first target selector corresponding to the target element in the test file with the second target selector.
[0072] After determining the second target selector of the target element, the selector processing device can replace the original first target selector in the test file with the second target selector, and update the selector usage record and record the process and results of the dynamic adjustment of the selector to facilitate subsequent analysis and optimization.
[0073] In the above scheme, when the selector fails, the selector generation model can be used to dynamically generate a new selector to achieve dynamic adjustment of the selector, ensuring that the selector of the automated test can continue to be effective when the web page changes. The above process of dynamically adjusting the selector forms a robust closed-loop system through failure detection, model prediction and selector update steps, which improves the reliability and flexibility of automated testing. Especially in frequently updated and complex web page environments, this mechanism is particularly important and efficient.
[0074] Next, the selector generation scheme of the embodiment of the present disclosure is further described by a specific example. Figure 3 A schematic diagram of a training process of a selector generation model provided in an embodiment of the present disclosure, such as Figure 3As shown, the figure shows the training process of the selector generation model, which may include: Step 301, start. Step 302, data collection, which may specifically include: 1. Web page collection, using data collection tools to automatically collect data of various types of web pages, including static web pages and dynamic web pages, and record the initial document object model structure of the page, the attribute information of each element, and the hierarchical information; 2. Data collection before and after changes, collecting the same web page again at different time points, and recording the changes in its document object model. These changes include the addition, deletion, and modification of attributes of elements, especially focusing on the elements that have changed, recording the attribute information of these elements before and after the change and other related information, and obtaining an original data set containing a large number of web pages and elements, recording the initial document object model structure and the document object model structure after the change. Step 303, data preprocessing, including: 1. Data cleaning, removing invalid elements and tags in HTML, such as comments, unnecessary blank nodes, etc.; excluding invalid attribute values and duplicate data entries; processing outliers to ensure data quality and consistency; 2. Data formatting: formatting the collected web page data into a structured data format to facilitate subsequent processing and analysis, unifying the naming and structure of the data, standardizing the data format, and obtaining a high-quality data set that has been cleaned and formatted, including the attribute information and hierarchical information of the web page elements, ensuring the consistency and integrity of the data, and laying the foundation for subsequent labeling and feature extraction.
[0075] Step 304, annotated data, manually annotating the stable selectors of the elements before and after the change, providing high-quality supervisory signals for model training and verification, which may specifically include: 1. Selector annotation, experienced experts manually annotating the stable selectors of each page element before and after the change. These selectors should be able to uniquely and stably identify page elements, and remain valid even when the document object model structure changes. 2. Annotated data storage, storing the annotated selector data in a structured database for subsequent model training. During the annotation process, the logic and basis for the generation of each selector are recorded to facilitate further optimization and reverse analysis in the future, and to obtain an accurately annotated selector sample data set, containing a unique stable selector for each element before and after the change. Step 305, feature extraction, specifically includes: 1. Basic feature extraction, extracting basic features from the attribute information of the element, and extracting the hierarchical information of the element, such as the relationship attributes of the parent node, child node, and sibling node. 2. Advanced feature extraction: Use context information to extract the position of elements in the entire document object model structure, such as node depth, number of adjacent sibling nodes, leaf nodes, etc.; extract the relative position and importance of elements in the page, such as whether it is in the main view area, whether it contains interactive functions such as click and input; 3. Feature vector generation: Combine basic features and advanced features to generate feature vectors suitable for input into machine learning models. Use feature normalization and standardization techniques to ensure that the dimensions of feature vectors are consistent and the numerical range is reasonable, and obtain a feature vector dataset containing rich context and hierarchical information to prepare for training models.
[0076] Step 306, model training. The extracted features and labeled selectors are used to train the model to generate a model of a stable selector, that is, the above-mentioned selector generation model. Specifically, it may include: 1. Select a basic model, select a basic model suitable for processing the document object model structure and context information, and ensure that the model can handle long sequence data and complex context dependencies; 2. Prepare training data, divide the extracted feature vectors and labeled selectors into training sets and validation sets, and ensure that the model can generalize on different data sets; 3. Model training, use the training set to train the basic model, optimize the model parameters through iteration, maximize the accuracy of selector prediction, use supervised learning methods, use labeled selectors as labels, and guide the model to update weights by calculating loss functions (such as cross entropy); 4. Adjust training parameters, according to the performance of the model on the validation set, continuously adjust the hyperparameters to optimize the training process. Hyperparameters may include (such as learning rate, batch size, number of layers, etc.; use early stopping (Early Stopping) technology is used to prevent the model from overfitting. Step 307, model verification and optimization, evaluate the selector generation accuracy of the model, and further improve the model performance through optimization, specifically including: 1. Model verification, use the verification set that does not participate in the training to evaluate the selector generation accuracy of the model, and comprehensively evaluate the model performance by calculating the accuracy, precision, recall and other indicators; identify the common errors when the model generates selectors through confusion matrix and error analysis, and analyze the error types and causes of the model; 2. Model optimization, according to the verification results, adjust the model's feature extraction method, hyperparameters and architecture design, optimize the model performance, and improve the robustness and generalization ability of the model by increasing the training data set and adding features of more dimensions, so as to obtain a verified and optimized selector generation model that can stably generate selectors that are effective in complex and changing environments. Step 308, end.
[0077] For example, Figure 4 A schematic diagram of a selector generation process provided by an embodiment of the present disclosure, such as Figure 4As shown, the figure shows the selector generation process, which may include: Step 401, start. Step 402, monitor user operations, capture user operations on the web page in real time, capture the target element of the user operation, and specifically, when the user performs operations such as clicking and inputting, use the event monitoring mechanism to capture user operation behaviors in real time, obtain the target element of the user operation, and trigger the subsequent data acquisition and selector generation process. Step 403, obtain the element information of the target element, specifically including: 1. Attribute information acquisition, obtain the ID, classList, tagName, data-* attributes and other static attributes of the target element, these static attributes are the basic attributes of the selector generation, and directly reflect the characteristics of the element; 2. Hierarchical information acquisition, recursively obtain the parent node, child node and sibling node of the target element, and collect hierarchical information, which includes the number of parent nodes, the number of sibling nodes, the position of the element in the sibling node (such as whether it is the first child node), and the attribute information of the parent node; 3. Context information acquisition: obtain the attributes and hierarchical information of the elements around the target element to understand its context, which includes other elements near the target element and their positions and attributes in the document object model tree. Step 404, model input preparation. Feature extraction and vectorization processing are performed on the element information of the acquired target element to generate a feature vector suitable for the input model, that is, the above-mentioned target feature, which may specifically include: 1. Feature vector generation, feature extraction is performed in combination with attribute information, hierarchical information and context information, the ID information of the element is extracted and encoded into a part of the feature vector, the classList of the element is extracted, one-hot encoding is performed and then added to the feature vector, the tagName of the element is extracted, the tag encoding is performed and then added to the feature vector, the data-* attribute of the element is extracted, and the necessary processing is performed and then added to the feature vector, hierarchical information such as the number of parent nodes, the number and position of sibling nodes at the same level are extracted, and the numerical processing is performed and then added to the feature vector, contextual information such as the neighboring elements of the target element and other main elements of the page are extracted, the attributes and positional relationships of these elements are extracted, and the vectorization processing is performed and then added to the feature vector; 2. Input format construction, all the above-mentioned extracted features are combined into a high-dimensional feature vector, ensuring that the vector format is consistent with the input requirements of the training model, and the feature vector is normalized and standardized to ensure that the feature value is within a reasonable range, thereby improving the accuracy of model prediction.
[0078] Step 405, call the model to predict the selector. Use the trained model, combined with the input feature vector, to predict and generate a unique and stable selector, input the prepared feature vector into the trained selector generation model, and after forward reasoning, output a predicted selector string for preliminary verification to ensure that the selector generated by the model can uniquely identify the target element in the current page. The verification method includes using the generated selector to find the element in the document object model tree to ensure the uniqueness and validity of the selector. If the generated selector cannot uniquely identify the target element, it may be necessary to readjust the features or call the model again for generation. Step 406, output the selector. Output the generated selector for automated testing, case recording or other automated operations, specifically including: outputting the generated stable selector together and saving it to a related data structure or file. The output format can be a string, a JSON object, or directly written to the configuration file of the automated testing tool; and recording the process and results of the selector generation in the log to facilitate subsequent tracking and debugging. The recorded content includes detailed information such as the attribute information of the target element, the generated target features, the generated selector, and the verification results. Step 407, end.
[0079] For example, Figure 5 A schematic diagram of a selector adjustment process provided by an embodiment of the present disclosure, such as Figure 5As shown, the figure shows the selector adjustment process, which may include: Step 501, start. Step 502, selector failure detection, detect whether the currently used selector is invalid due to changes in the document object model, identify the selector that needs to be updated in time, and generate a list of invalid selectors. Specifically, for each selector that needs to be verified, verify its validity by querying whether the selector can uniquely match the target element in the current document object model tree. If the selector query returns multiple elements or the element cannot be found, the selector is considered invalid; failure record, record the detected invalid selectors, including the results returned by the selector query and the reasons for the failure. The failure threshold and detection frequency can be set to avoid performance problems caused by frequent detection. Step 503, whether the selector is invalid, if so, execute step 504; otherwise, execute step 506. Step 504, call the model to generate the selector. Use the trained selector generation model to generate a new stable selector based on the element information of the current target element, re-extract the element information of the target element and generate a new feature vector, ensure that the input data meets the requirements of the model, input the new feature vector into the trained selector generation model, perform forward reasoning, generate a new selector, perform preliminary verification on the generated new selector, ensure that it uniquely identifies the target element in the current page, and obtain a newly generated stable selector. Step 505, update the selector, replace the invalid selector with the newly generated selector, and apply it to the automated test case to ensure the continued effectiveness of the test case. Specifically, save the newly generated selector to the automated test code or database, update the selector usage record, and ensure that the latest version of each selector is recorded; record the process and results of the dynamic adjustment of the selector, including detailed information and verification results of the new selector generation. The log content provides detailed debugging information to facilitate subsequent analysis and optimization. Step 506, continue detection. Step 507, end.
[0080] This solution provides a method for generating unique and stable selectors based on context and hierarchical information. It uses model training and hierarchical awareness algorithms to automatically generate optimized and stable selectors, which can solve the problem of poor selector stability in automated testing tools, significantly improve the stability and uniqueness of selectors, and reduce the failure of test cases caused by page changes. By combining models and context-aware technology, the stability of selector generation is improved to ensure that the selector remains valid when the page document object model structure changes, improve the uniqueness of the selector, and ensure unique identification in the page; dynamically adjust the selector when the selector fails to ensure the stability of automated testing and enhance the robustness and reliability of automated testing.
[0081] Figure 6 This is a schematic diagram of the structure of a selector processing device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and can generally be integrated into an electronic device. Figure 6 As shown, the device comprises:
[0082] The acquisition module 601 is used to acquire element information of the target element in response to a selection operation on the target element;
[0083] A feature module 602 is used to determine a target feature of the element information of the target element;
[0084] A generation module 603 is used to input the target feature into a selector generation model, and output a first target selector corresponding to the target element;
[0085] The saving module 604 is used to save the first target selector of the target element into a test file, so as to locate the target element based on the first target selector in the test file during the test process.
[0086] Optionally, the element information of the target element includes attribute information of the target element, level information of the target element in the web page, and context information.
[0087] Optionally, the feature module 602 is used to:
[0088] Encoding the attribute information in the element information of the target element to obtain a first feature vector;
[0089] Numerically processing the hierarchical information in the element information of the target element to obtain a second eigenvector;
[0090] Vectorizing the context information in the element information of the target element to obtain a third feature vector;
[0091] The first feature vector, the second feature vector and the third feature vector are combined, normalized and standardized to obtain target features.
[0092] Optionally, the device further comprises a training module, which is used to:
[0093] Acquire a selector sample data set, wherein the selector sample data set includes a plurality of sample data, each of the sample data includes a sample element and its corresponding selector tag;
[0094] The basic model is trained based on the selector sample data set to obtain the selector generation model.
[0095] Optionally, the device further includes an effective detection module, including:
[0096] A first unit is used to perform a validity test on the first target selector and determine a validity test result;
[0097] A second unit is configured to obtain new element information of the target element if it is determined that the validity detection result is that the first target selector is invalid;
[0098] A third unit is used to generate a second target selector of the target element by using the selector generation model based on the new element information of the target element;
[0099] The fourth unit is used to replace the first target selector corresponding to the target element in the test file with the second target selector.
[0100] Optionally, the first unit is used for:
[0101] Using the first target selector to query the number of matching elements on the webpage where the target element is located;
[0102] If the number of the matching elements is only one, then the validity check result is determined to be that the first target selector is valid; otherwise, the validity check result is determined to be that the first target selector is invalid.
[0103] Optionally, the device further comprises a control module, which is used to: after determining that the validity detection result is that the first target selector is invalid,
[0104] Determine whether the number of failures of the first target selector reaches a number threshold and whether the calling frequency of the selector generation model is less than a frequency threshold;
[0105] Get new element information of the target element, including:
[0106] If the number of failures of the first target selector reaches the number threshold and the calling frequency of the selector generation model is less than the frequency threshold, the step of obtaining new element information of the target element is executed; otherwise, the step of returning to make a judgment continues.
[0107] The selector processing device provided in the embodiments of the present disclosure can execute the selector processing method provided in any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0108] The embodiments of the present disclosure also provide a computer program product, including a computer program / instruction, which implements the selector processing method provided by any embodiment of the present disclosure when the computer program / instruction is executed by a processor.
[0109] Figure 7 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. Figure 7, which shows a schematic diagram of the structure of an electronic device 700 suitable for implementing the embodiment of the present disclosure. The electronic device 700 in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0110] like Figure 7 As shown, the electronic device 700 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the electronic device 700 are also stored. The processing device 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0111] Typically, the following devices may be connected to the I / O interface 705: an input device 706 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 708 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 709. The communication device 709 may allow the electronic device 700 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 7 The electronic device 700 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0112] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 709, or installed from a storage device 708, or installed from a ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the selector processing method of the embodiment of the present disclosure are executed.
[0113] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0114] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0115] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0116] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: obtains element information of the target element in response to a selection operation on the target element; determines the target feature of the element information of the target element; inputs the target feature into a selector generation model, and outputs a first target selector corresponding to the target element; saves the first target selector of the target element to a test file, so as to locate the target element based on the first target selector in the test file during the test process.
[0117] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0118] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0119] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, limit the unit itself.
[0120] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0121] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0122] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0123] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0124] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0125] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A selector processing method, characterized in that: include: In response to a selection operation on a target element, acquiring element information of the target element; determining a target feature of the element information of the target element; Input the target feature into a selector generation model, and output a first target selector corresponding to the target element; The first target selector of the target element is saved in a test file, so as to locate the target element based on the first target selector in the test file during a test process.
2. The method according to claim 1, characterized in that The element information of the target element includes attribute information of the target element, level information of the target element in the web page, and context information.
3. The method according to claim 2, characterized in that Determining a target feature of the element information of the target element includes: Encoding the attribute information in the element information of the target element to obtain a first feature vector; Numerically processing the hierarchical information in the element information of the target element to obtain a second eigenvector; performing vectorization processing on the context information in the element information of the target element to obtain a third eigenvector; The first eigenvector, the second eigenvector, and the third eigenvector are combined, normalized, and standardized to obtain target features.
4. The method according to claim 1, wherein The method further comprises: Acquire a selector sample data set, wherein the selector sample data set includes a plurality of sample data, each of the sample data includes a sample element and its corresponding selector tag; The basic model is trained based on the selector sample data set to obtain the selector generation model.
5. The method according to claim 1, wherein The method further comprises: Performing a validity test on the first target selector to determine a validity test result; If it is determined that the validity check result is that the first target selector is invalid, obtaining new element information of the target element; Generate a second target selector for the target element using the selector generation model based on the new element information of the target element; The first target selector corresponding to the target element in the test file is replaced with the second target selector.
6. The method according to claim 5, characterized in that Performing a validity check on the first target selector and determining a validity check result includes: Using the first target selector to query the number of matching elements on the web page where the target element is located; If the number of the matching elements is only one, the validity check result is determined to be that the first target selector is valid; otherwise, the validity check result is determined to be that the first target selector is invalid.
7. The method according to claim 5, characterized in that After determining that the validity detection result is that the first target selector is invalid, the method further includes: Determining whether the number of failures of the first target selector reaches a number threshold and whether the call frequency of the selector generation model is less than a frequency threshold; Get the new element information of the target element, including: If the number of failures of the first target selector reaches the number threshold and the calling frequency of the selector generation model is less than the frequency threshold, the step of obtaining the new element information of the target element is executed; otherwise, the step of returning to judgement is continued.
8. A selector processing device, characterized in that: include: an acquisition module, configured to acquire element information of a target element in response to a selection operation on the target element; A feature module, configured to determine target features of element information of the target element; A generation module, configured to input the target feature into a selector generation model and output a first target selector corresponding to the target element; A saving module is configured to save the first target selector of the target element into a test file, so as to locate the target element based on the first target selector in the test file during a test process.
9. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the selector processing method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and the computer program is used to execute the selector processing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Automated testing script recording method and device, computer equipment and medium
CN115481025A
Element operation method and device for automatic test
CN116775447A
Just in Time Scriptless Test Automation Selectors and Interactions
US20200356467A1
Browser extension with automation testing support
US20230195825A1
