Intelligent conversion method and system for natural language requirements to selenium script based on large language model
By using a large language model-based approach, natural language requirements are transformed into structured test elements and executable scripts are generated. This solves the problems of lack of one-to-one semantic traceability and DOM fragility in existing technologies, and realizes the adaptive correction and self-healing capabilities of automatically generated scripts, thereby improving the stability and maintenance efficiency of automated testing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HEBEI GEOLOGICAL STAFF UNIV
- Filing Date
- 2026-04-07
- Publication Date
- 2026-07-03
AI Technical Summary
In existing technologies, the conversion from natural language to scripts often relies on surface text matching or a single positioning strategy. This results in a lack of strict one-to-one traceability between the generated use cases and the original requirements at the semantic level. The generated scripts are extremely vulnerable to minor changes in the DOM and lack a systematic execution feedback loop and self-healing mechanism, which leads to shortcomings in long-term maintenance and compliance auditing.
A large language model-based approach is adopted. By standardizing the requirement text, extracting test elements and mapping them to the interface, an enhanced contextual representation is constructed, a robust localization strategy is generated, the initial Selenium script is executed, and adaptive correction and redundancy removal are performed through execution feedback to form a closed-loop adaptive process, ensuring the traceability and robustness of the script set.
It achieves accurate mapping from unstructured natural language requirements to structured test elements. The generated scripts have runtime adaptive correction and self-healing capabilities, significantly improving requirement-test consistency, reducing the risk of test case misjudgment and omission, alleviating maintenance burden, and improving the scalability of the automation system.
Smart Images

Figure CN122332283A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software engineering technology, specifically to an intelligent conversion method and system for converting natural language requirements based on a large language model into Selenium scripts. Background Technology
[0002] Web automation testing is gradually shifting from scripting and manual coding to engineering and platform-based approaches, with open-source tools (such as Selenium) becoming the mainstream execution framework. Simultaneously, breakthroughs in natural language processing and large-scale pre-trained language models in semantic understanding and text generation have led research and industry to explore feasible paths for mapping requirement texts to test cases or automation scripts. In parallel, several engineering practices based on attribute fingerprints, topological relationships, and wait / rollback strategies have emerged to address page location and stability issues. Continuous execution and maintenance of automated test cases in CI / CD pipelines have also become crucial aspects of artifact quality assurance.
[0003] Existing automated generation solutions typically rely on surface text matching or single positioning strategies for the conversion from natural language to scripts. This results in a lack of strict one-to-one semantic traceability between generated use cases and original requirements. Furthermore, the generated scripts are extremely vulnerable to minor changes in the DOM and lack a systematic execution feedback loop and self-healing mechanism, thus presenting significant shortcomings in long-term maintenance and compliance auditing.
[0004] In response to this problem, this application proposes an intelligent conversion method and system for converting natural language requirements based on a large language model into Selenium scripts, in order to solve the aforementioned issues. Summary of the Invention
[0005] The purpose of this invention is to provide an intelligent conversion method and system for converting natural language requirements into Selenium scripts based on a large language model. This addresses the problems in existing technologies where the conversion from natural language to scripts relies heavily on surface text matching or a single positioning strategy, resulting in a lack of strict one-to-one traceability between the generated use cases and the original requirements at the semantic level. Furthermore, the generated scripts are extremely vulnerable to minor changes in the DOM and lack a systematic execution feedback loop and self-healing mechanism, thus presenting significant shortcomings in long-term maintenance and compliance auditing.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] One aspect of this application is to provide an intelligent conversion method for natural language requirements based on large language models to Selenium scripts, including:
[0008] Receive the requirement text, process it for normalization, and obtain the normalized requirement text;
[0009] Test elements are extracted from the standardized requirement text and mapped to the interface to obtain structured test elements;
[0010] An enhanced contextual representation is constructed based on the structured test elements, the target DOM, and domain knowledge;
[0011] The enhanced context representation is mapped to a parameterizable script template and a robust localization strategy is generated, resulting in a script template and a localization strategy.
[0012] Based on the script template and positioning strategy, an initial Selenium script is generated and executed to obtain an executable Selenium script and execution feedback.
[0013] Based on the execution feedback, the structured test elements and the script template are adaptively corrected and redundancy is removed to obtain an optimized Selenium script set.
[0014] Further, the received requirement text is used for normalization processing to obtain normalized requirement text, including:
[0015] The original requirement text is segmented, ambiguous, and prioritized using a domain dictionary, regular expressions, and contextual hints to obtain the standardized requirement text.
[0016] Furthermore, the structured test elements include: clearly generating action vectors, target location descriptions, preconditions and expected assertions for each use case, and the structured test elements maintain a traceable one-to-one mapping relationship with the original requirement sentences to ensure the semantic correspondence of subsequent data flows.
[0017] Furthermore, the construction of the enhanced context representation based on the structured test elements, the target DOM, and domain knowledge includes:
[0018] By integrating the structured test elements, target DOM snapshots, and a lightweight domain knowledge graph, and aligning them step by step according to the lexical layer, element attribute layer, and semantic role layer, an enhanced context representation containing element semantic annotations and positional semantics is generated. The enhanced context representation ensures that each test step has a clear semantic mapping with at least one DOM element.
[0019] Further, the step of mapping the enhanced context representation to a parameterizable script template and generating a robust localization strategy, resulting in the script template and localization strategy, includes:
[0020] A parameterizable script template (including action sequences and assertion placeholders) is generated based on the enhanced context representation, and a candidate location set is generated for each target element. The candidate location set is sorted by fingerprint scores based on attributes, relative topology, visible text and neighborhood features. The fingerprint includes the element attribute set, visible text hash and relative DOM neighborhood signature, which is used to improve the robustness of runtime location and serve as the basis for subsequent self-healing matching.
[0021] Further, the step of generating and executing an initial Selenium script based on the script template and positioning strategy to obtain an executable Selenium script and execution feedback includes:
[0022] When the executable Selenium script is executed, element matching scores, action success rates, exception stacks, and page DOM differences are collected. When a match fails, location candidate rollback, element migration based on DOM differences, and relocation strategies based on text fuzzy matching are triggered in order of priority. The execution feedback is used to update the location priority of the script template and the target mapping of the structured test elements, thereby forming a closed-loop adaptive correction process.
[0023] Furthermore, the optimized Selenium script set, obtained by adaptively correcting and deduplicating the structured test elements and script templates based on the execution feedback, includes:
[0024] The generated scripts are subjected to coverage-aware clustering analysis based on requirement traceability and execution path similarity to identify use cases with overlapping functions or insufficient coverage; use cases marked as redundant are merged or deleted according to priority, and supplementary branches are automatically generated for requirements with insufficient coverage. Finally, the optimized Selenium script set that meets the coverage threshold and minimizes redundancy is output.
[0025] Furthermore, the method also includes:
[0026] The manually verified execution feedback, correction records, and new examples are used as training samples to periodically update the prompting project and lightweight knowledge graph. These updates are used to improve the accuracy of subsequent normalization, element extraction, and template generation, thereby achieving continuous learning and performance evolution.
[0027] Another aspect of this application is to provide an intelligent conversion system for natural language requirements based on a large language model to Selenium scripts, including:
[0028] The requirement text normalization module is used to receive requirement text, perform normalization processing, and obtain normalized requirement text.
[0029] The test element structuring module is used to extract test elements from the standardized requirement text and map them to the interface to obtain structured test elements.
[0030] An enhanced context building module is used to construct an enhanced context representation based on the structured test elements, the target DOM, and domain knowledge;
[0031] The script template and localization strategy generation module is used to map the enhanced context representation into a parameterizable script template and generate a robust localization strategy, thereby obtaining the script template and localization strategy.
[0032] The initial script generation and execution module is used to generate and execute an initial Selenium script based on the script template and the positioning strategy, so as to obtain an executable Selenium script and execution feedback.
[0033] The script adaptive optimization module is used to adaptively correct and remove redundancy from the structured test elements and the script template based on the execution feedback, so as to obtain an optimized Selenium script set.
[0034] Compared with existing technologies, this invention provides an intelligent conversion method and system for natural language requirements to Selenium scripts based on a large language model. This invention can accurately map unstructured natural language requirements to structured test elements and generate executable scripts. Throughout the process, it preserves sentence-by-sentence traceability and semantic alignment, allowing each automated test case to be traced back to the original requirement. This significantly improves requirement-test consistency and reduces the risk of misjudgment and omission of test cases due to misunderstanding biases. By enhancing context representation, location fingerprints, and execution feedback loops, this solution enables automatically generated scripts to have runtime adaptive correction and self-healing capabilities. Manual corrections are fed back as incremental samples to the prompting engineering and knowledge graph, achieving continuous learning and long-term stability improvement of the script set. This reduces maintenance burden and improves the scalability of the automation system. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0036] Figure 1 A flowchart of an intelligent conversion method for natural language requirements based on a large language model to Selenium scripts, provided for embodiments of the present invention;
[0037] Figure 2 This is a block diagram of an intelligent conversion system for natural language requirements to Selenium scripts based on a large language model, provided as an embodiment of the present invention. Detailed Implementation
[0038] To enable those skilled in the art to better understand the technical solution of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings.
[0039] As attached Figure 1 As shown:
[0040] Example 1:
[0041] A method for intelligently converting natural language requirements based on a large language model into Selenium scripts includes:
[0042] S1. Receive the requirement text, process it for normalization, and obtain the normalized requirement text;
[0043] In step S1, the original requirement text is segmented, ambiguous, and prioritized using a domain dictionary, regular expressions, and contextual hints to obtain the standardized requirement text.
[0044] Specifically, the sources of information can include product requirement documents, user stories, test instructions, or verbal records. The implementation involves language detection, character set normalization, noise removal, and sentence segmentation.
[0045] Abbreviations, colloquial descriptions, and terms are mapped to controlled vocabulary using a domain dictionary, thesaurus, and normalization rules, and metadata (source ID, sentence order, confidence level) is generated for each sentence. The output is a normalized sequence of sentences with traceability information, facilitating subsequent mapping and auditing.
[0046] S2. Extract test elements from the standardized requirement text and map them to the interface to obtain structured test elements;
[0047] In step S2, the structured test elements include: clearly generating action vectors, target location descriptions, preconditions and expected assertions for each use case, and the structured test elements maintain a traceable one-to-one mapping relationship with the original requirement sentences to ensure the semantic correspondence of subsequent data streams;
[0048] Specifically, for each standardized sentence, a combination of rules and a large model is used to extract actions (clicks, inputs, navigation, etc.), target location descriptions (text, attribute hints), preconditions, and expected assertions, generating standardized fields (action vector, location description, preconditions, assertions, and priority). Simultaneously, based on DOM snapshots or design drafts, candidate UI element annotations are generated, maintaining a traceable one-to-one correspondence between each test element and the original sentence.
[0049] S3. Construct an enhanced context representation based on the structured test elements, the target DOM, and domain knowledge;
[0050] In step S3, the structured test elements, target DOM snapshot and a lightweight domain knowledge graph are integrated and aligned step by step according to the word layer, element attribute layer and semantic role layer to generate an enhanced context representation containing element semantic annotation and position semantics. The enhanced context representation ensures that each test step has a clear semantic mapping with at least one DOM element.
[0051] Specifically, structured elements are aligned with real-time / offline DOM snapshots and lightweight domain knowledge graphs in three layers: lexical layer (keywords to DOM attributes), element attribute layer (id / class / role mapping), and semantic role layer (operation objects, assertion targets). Enhanced representations are generated through attribute injection, relative position encoding, and semantic annotation to ensure that each test step maps to at least one or a group of DOM element candidates with semantic tags.
[0052] S4. Map the enhanced context representation to a parameterizable script template and generate a robust localization strategy to obtain the script template and localization strategy.
[0053] In step S4, a parameterizable script template (including action sequences and assertion placeholders) is generated based on the enhanced context representation, and a candidate location set is generated for each target element; the candidate location set is sorted according to fingerprint scores based on attributes, relative topology, visible text and neighborhood features. The fingerprint includes the element attribute set, visible text hash and relative DOM neighborhood signature, which is used to improve runtime location robustness and serve as the basis for subsequent self-healing matching.
[0054] Specifically, a parameterizable Selenium script template (action sequence and assertion placeholders) is generated from the enhanced representation, and a candidate location set is generated for each target element. Each candidate location is fingerprinted and scored according to "attribute set + visible text hash + relative DOM neighborhood signature". The template also has built-in location fallback logic, waiting strategy and parameterized input points to support stable execution in different environments and data-driven scenarios.
[0055] S5. Generate and execute an initial Selenium script based on the script template and positioning strategy to obtain an executable Selenium script and execution feedback;
[0056] In step S5, when the executable Selenium script is executed, the element matching score, action success rate, exception stack, and page DOM differences are collected. When the matching fails, the location candidate rollback, element migration based on DOM differences, and relocation strategy based on text fuzzy matching are triggered in order of priority. The execution feedback is used to update the location priority of the script template and the target mapping of the structured test elements, thereby forming a closed-loop adaptive correction process.
[0057] Specifically, templates are instantiated using candidate locations and test data and executed in a controlled environment. During runtime, element matching scores, action success rates, exception stacks, and DOM difference snapshots are collected. In case of failure, rollbacks are triggered based on candidate sorting, element migrations based on DOM differences, or fuzzy text matching attempts are made. All feedback is written back as structured logs as input for location prioritization and template correction.
[0058] S6. Based on the execution feedback, adaptively correct and remove redundancy from the structured test elements and the script template to obtain an optimized Selenium script set;
[0059] In step S6, the generated scripts are subjected to coverage-aware clustering analysis based on requirement traceability and execution path similarity to identify use cases with overlapping functions or insufficient coverage; use cases marked as redundant are merged or deleted according to priority, and supplementary branches are automatically generated for requirements with insufficient coverage. Finally, the optimized Selenium script set that meets the coverage threshold and minimizes redundancy is output.
[0060] Specifically, closed-loop corrections are made to structured elements and templates based on execution feedback: coverage-aware clustering is performed based on demand traceability and execution path similarity to identify and merge redundant use cases, automatically generate supplementary branches with insufficient coverage, and adjust positioning priorities and rollback strategies; manually verified corrections are used as incremental samples to fill the prompting project and lightweight knowledge graph to achieve continuous learning and measurable improvement of script sets.
[0061] Furthermore, the method also includes: using manually verified execution feedback, correction records, and new examples as training samples to periodically update the prompting project and lightweight knowledge graph. The updates are used to improve the accuracy of subsequent normalization, element extraction, and template generation, thereby achieving continuous learning and performance evolution.
[0062] As can be seen from the above, the present invention can accurately map unstructured natural language requirements into structured test elements and generate executable scripts. Furthermore, it preserves the traceability relationship and semantic alignment of each sentence throughout the entire process, enabling each automated test case to trace back to the original requirement. This significantly improves requirement-test consistency and reduces the risk of test case misjudgment and omission due to misunderstanding bias.
[0063] Example 2:
[0064] Experiment setup and key parameters (global):
[0065] Project time: 2026-01-20 (Example of DOM snapshot collection time);
[0066] Original number of requirements: 120 requirement texts;
[0067] Number of sentences after normalization: 118 (denoising and merging);
[0068] Initial number of generated scripts (corresponding to structured test elements): 210 test cases;
[0069] Fingerprint scoring formula: Score = 0.5*AttrSim + 0.3*TextSim + 0.2*TopoSim (AttrSim: similarity of attribute sets; TextSim: similarity of visible text; TopoSim: similarity of relative DOM neighborhood signatures)
[0070] Fingerprint threshold (acceptable for location tracking): 0.70
[0071] Maximum number of rollback candidates: 5; Number of location retries: 3; Display wait timeout: 10s
[0072] Clustering similarity threshold (redundancy removal): Path similarity ≥ 0.85 is considered overlapping.
[0073] 1) Receive requirement text → Standardize requirement text;
[0074] enter:
[0075] "After logging in, users can click 'My Orders', filter the order list for orders with a status of 'Pending Payment', and make the first payment."
[0076] Standardized requirement text (output) (including metadata):
[0077] [R01-1] Login: Users log in with username / password and must be successfully redirected to the homepage (Source: Product Story 2026-01-10)
[0078] [R01-2] Payment Scenario: On the homepage, go to "My Orders," filter the status as "Pending Payment," click "Pay Now" on the first order, complete the payment, and display a payment success assertion. Processing Methods and Techniques: Batch export raw text from JIRA / Confluence; first perform language detection → character set normalization → regular abbreviations → replace synonyms based on domain dictionary → sentence segmentation and sentence order numbering, generating a normalized sentence sequence (traceable) with source ID and confidence level.
[0079] 2) Standardize the requirements text → Extract test elements and map them to the interface (structured test elements).
[0080] Using the standardized requirement text as input, the structured fields extracted for each sentence are shown in Table 1 below;
[0081] Table 1
[0082] Feature ID Requirement ID Action vectors Positioning Description (Candidate) Prerequisites assertion Priority T210 R01-2 [Navigation -> Filter -> Click -> Pay] The text contains "My Orders"; XPath candidate 1 / 2; CSS candidate Logged in (R01-1) The page includes a "Payment successful" message. high
[0083] Implementation method: Use rule templates + LLM (prompt: extract actions / targets / preconditions / assertions), and perform pattern validation on the output fields to form structured test element JSON (maintaining a one-to-one traceable ID for the original sentence).
[0084] 3) Structured test elements + target DOM + domain knowledge → enhanced contextual representation;
[0085] Input: Structured test elements, target DOM snapshot (fetched via Chrome DevTools Protocol), lightweight domain knowledge graph (e.g., button semantics "Pay Now" → operation type "Pay"). Operation:
[0086] Terminology layer: Maps action keywords ("filter", "pay immediately") to DOM attributes (aria-label, data-test-id, innerText).
[0087] Element attribute layer: Reads the DOM attribute collection (id / class / role / data-*) and generates attribute vectors.
[0088] Semantic Role Layer: Elements are labeled as "action trigger / assertion target / input domain" based on the knowledge graph.
[0089] Output (Enhanced Context Representation): Each step yields an enhanced context representation (including element semantic tags, attribute vectors, position encodings, and candidate location sets), ensuring that "each test step maps to at least one DOM element candidate".
[0090] 4) Enhanced context representation → Parameterizable script templates + robust localization strategy;
[0091] Using the enhanced contextual representation as input, generate:
[0092] Script template (parameterized placeholder):
[0093] Such as navigate_to("my_orders"); filter_by_status("{status}"); click_order(index=0); pay_with("{method}"); assert_contains("Payment successful")
[0094] The candidate location set is shown in Table 2 below;
[0095] Table 2
[0096] Element semantics Candidate positioning Attribute fingerprint Visible text hash Neighborhood Signature Score My Orders Entry / / a[text()="My Orders"] {role:link,class:nav-item} h1a2f... nbsig_34 0.92 Filter dropdown / / select[@id="order-status"] {id:order-status} d4b3... nbsig_45 0.88 Pay Now button / / button[contains(text(),"Pay Now")] {class:btn-pay,data-action:pay} c9e2... nbsig_78 0.81
[0097] Generation strategy: Sort by score in descending order, embed the positioning backtracking sequence, wait / retry and parameter points in the template; and record the priority positioning ID for write-back.
[0098] 5) Script Templates and Location Strategies → Generate and execute the initial Selenium script, and collect execution feedback;
[0099] Generate instantiation script (Python / Selenium fragment):
[0100] #Automatically generated
[0101] driver.get(BASE_URL)
[0102] # Locate "My Orders": Try candidate 1 -> candidate 2
[0103] el=try_locators(driver, [" / / a[text()='My Orders']","css=nav .orders"])
[0104] el.click()
[0105] except LocatorFail: raise
[0106] # Filtering status
[0107] select = try_locators(driver, ["id=order-status"," / / select[@name='status']"])
[0108] Select(select).select_by_visible_text("Pending Payment") # Click to pay for the first order
[0109] btn = try_locators(driver, [" / / button[contains(text(),'Pay Now')]","css=.btn-pay"]) btn.click() # Assertions
[0110] assert "Payment successful" in driver.page_source
[0111] Execution environment and data collection methods: Selenium Grid is used for batch execution (node 8), and WebDriverEventListener and custom hooks are used to record: element matching score, action success / failure, exception stack, DOM snapshot differences (before and after comparison), and structured logs are written to ElasticSearch.
[0112] The single-use case execution feedback is shown in Table 3 below;
[0113] Table 3
[0114] Use Case ID Match score Action success rate Number of retries Exception / Remarks DOM Difference Markup T210 0.81 success 0 none 0
[0115] 6) Based on execution feedback → adaptive correction and redundancy removal, output an optimized script set;
[0116] Input: Execution feedback log (all 210 test cases) and original structured test elements.
[0117] Processing and Results:
[0118] Automatically adjust positioning priority: If a candidate has a matching failure rate of >40% in 10 executions, it will be downgraded and the second-best candidate will be promoted in the template.
[0119] For example, the self-healing strategy is triggered for 18 use cases that failed due to minor changes in the DOM structure. "Text fuzzy matching + neighborhood signature migration" is triggered, which enables 14 of them to recover successfully (and the new location is written back to the template).
[0120] Coverage-aware clustering analysis (redundancy removal): 210 use cases were clustered according to execution path / assertion similarity. Clustering result: 170 clusters. 60 use cases were found to be highly overlapping (repeated paths), which were merged into 30 merged use cases → The number of scripts was reduced from 210 to 150 (a reduction of 28.6%).
[0121] The comparison between coverage and pass rate is shown in Table 4 below;
[0122] Table 4
[0123] index Initial (after generation) After optimization Number of use cases 210 150 Number of items to cover 118 / 120 (98.3%) 118 / 120 (98.3%) Automatically calculate average pass rate 62% 88% Maintenance hours (estimated / week) 12 hours 5 hours Average execution time per test case 14.2s 12.8s
[0124] Continuous learning: Add the manually verified corrections (about 20) to the training samples, update the lightweight knowledge graph and prompt templates, and improve the accuracy of the next generation (from 62% to 68% initial pass rate improvement).
[0125] The specific data acquisition method is as follows:
[0126] Requirement text: Export CSV / Markdown from JIRA / Confluence; automatically import into the database using the pipeline (retain time / source fields).
[0127] DOM Snapshot: Captures a snapshot of document.documentElement.outerHTML and element attributes (and records a timestamp) during test node execution via Chrome DevTools Protocol (CDP).
[0128] Run log: Selenium's WebDriverEventListener + custom Hook export JSON line log (each step includes candidate location, matching score, time consumed, and exception stack).
[0129] Manual verification records: Change entries that are "manually confirmed / adjusted" are recorded on the internal verification platform (as samples for continuous learning).
[0130] Knowledge graph construction: Export triples (label→semantic_role→examples) from product dictionary and UI specifications, and save them as lightweight JSON-LD.
[0131] As shown above, the pass rate has been significantly improved: the automated pass rate has increased from 62% to 88%. This is achieved through the collaboration of "enhanced context representation" and "location fingerprint + rollback strategy", which is significantly better than the conventional approach based solely on text or a single XPath.
[0132] Maintenance costs decreased: the number of scripts decreased by 28.6%, and the estimated weekly maintenance man-hours decreased from 12 hours to 5 hours, indicating that this method brings substantial benefits in redundancy removal and adaptive correction.
[0133] Coverage and traceability are maintained: The optimized version still covers 118 / 120 requirements, and each script maintains a one-to-one traceability relationship with the standardized requirements, meeting audit and backtracking requirements.
[0134] Continuous learning loop: Using manual corrections as training samples for periodic refilling avoids static template degradation and achieves long-term performance evolution. This is an engineering-based improvement path.
[0135] As can be seen from the above, this invention enhances context representation, localization fingerprints, and execution feedback loops, enabling automatically generated scripts to have runtime adaptive correction and localization self-healing capabilities. Furthermore, it feeds back manual corrections as incremental samples to the prompting project and knowledge graph, achieving continuous learning and long-term stability improvement of the script set. This reduces the maintenance burden and improves the scalability of the automation system.
[0136] Example 3:
[0137] In one embodiment, this application provides an intelligent conversion system for natural language requirements based on a large language model to Selenium scripts, comprising:
[0138] The requirement text normalization module is used to receive requirement text, perform normalization processing, and obtain normalized requirement text.
[0139] The test element structuring module is used to extract test elements from the standardized requirement text and map them to the interface to obtain structured test elements.
[0140] An enhanced context building module is used to construct an enhanced context representation based on the structured test elements, the target DOM, and domain knowledge;
[0141] The script template and localization strategy generation module is used to map the enhanced context representation into a parameterizable script template and generate a robust localization strategy, thereby obtaining the script template and localization strategy.
[0142] The initial script generation and execution module is used to generate and execute an initial Selenium script based on the script template and the positioning strategy, so as to obtain an executable Selenium script and execution feedback.
[0143] The script adaptive optimization module is used to adaptively correct and remove redundancy from the structured test elements and the script template based on the execution feedback, so as to obtain an optimized Selenium script set.
[0144] The beneficial effects of this method, which is based on a large language model and is used to intelligently convert natural language requirements into Selenium scripts, will not be elaborated here.
[0145] The foregoing has only described certain exemplary embodiments of the present invention by way of illustration. Undoubtedly, those skilled in the art can modify the described embodiments in various ways without departing from the spirit and scope of the present invention. Therefore, the foregoing drawings and descriptions are illustrative in nature and should not be construed as limiting the scope of protection of the claims of the present invention.
Claims
1. A method for intelligent conversion of natural language requirements to Selenium scripts based on large language models, characterized in that, Includes the following steps: Receive the requirement text, process it for normalization, and obtain the normalized requirement text; Test elements are extracted from the standardized requirement text and mapped to the interface to obtain structured test elements; An enhanced contextual representation is constructed based on the structured test elements, the target DOM, and domain knowledge; The enhanced context representation is mapped to a parameterizable script template and a robust localization strategy is generated, resulting in a script template and a localization strategy. Based on the script template and positioning strategy, an initial Selenium script is generated and executed to obtain an executable Selenium script and execution feedback. Based on the execution feedback, the structured test elements and the script template are adaptively corrected and redundancy is removed to obtain an optimized Selenium script set.
2. The intelligent conversion method for natural language requirements based on a large language model to Selenium scripts according to claim 1, characterized in that, The received request text is used for normalization processing to obtain normalized request text, including: The original requirement text is segmented, ambiguous, and prioritized using a domain dictionary, regular expressions, and contextual hints to obtain the standardized requirement text.
3. The intelligent conversion method for natural language requirements based on a large language model to Selenium scripts according to claim 1, characterized in that, The structured test elements include: clearly generating action vectors, target location descriptions, preconditions and expected assertions for each use case, and maintaining a traceable one-to-one mapping relationship between the structured test elements and the original requirement sentences to ensure the semantic correspondence of subsequent data flows.
4. The intelligent conversion method for natural language requirements based on a large language model to Selenium scripts according to claim 1, characterized in that, The construction of an enhanced context representation based on the structured test elements, the target DOM, and domain knowledge includes: By integrating the structured test elements, target DOM snapshots, and a lightweight domain knowledge graph, and aligning them step by step according to the lexical layer, element attribute layer, and semantic role layer, an enhanced context representation containing element semantic annotations and positional semantics is generated. The enhanced context representation ensures that each test step has a clear semantic mapping with at least one DOM element.
5. The intelligent conversion method for natural language requirements based on a large language model to Selenium scripts according to claim 1, characterized in that, The step of mapping the enhanced context representation to a parameterizable script template and generating a robust localization strategy, resulting in the script template and localization strategy, includes: Parameterizable script templates are generated based on enhanced context representations, and a set of candidate locations is generated for each target element. The candidate location set is sorted by fingerprint scores based on attributes, relative topology, visible text, and neighborhood features. The fingerprint includes the element attribute set, visible text hash, and relative DOM neighborhood signature to improve runtime location robustness and serve as the basis for subsequent self-healing matching.
6. The intelligent conversion method for natural language requirements based on a large language model to Selenium scripts according to claim 1, characterized in that, The process of generating and executing an initial Selenium script based on the script template and positioning strategy to obtain an executable Selenium script and execution feedback includes: When executing the executable Selenium script, collect element matching scores, action success rates, exception stacks, and differences from the page DOM. When a match fails, the following strategies are triggered in order of priority: candidate fallback, element migration based on DOM differences, and relocation based on fuzzy text matching. The execution feedback is used to update the positioning priority of the script template and the target mapping of the structured test elements, thereby forming a closed-loop adaptive correction process.
7. The intelligent conversion method for natural language requirements based on a large language model to Selenium scripts according to claim 1, characterized in that, The optimized Selenium script set is obtained by adaptively correcting and deduplicating the structured test elements and script templates based on the execution feedback, including: The generated scripts are subjected to coverage-aware clustering analysis based on requirement traceability and execution path similarity to identify use cases with overlapping functions or insufficient coverage; use cases marked as redundant are merged or deleted according to priority, and supplementary branches are automatically generated for requirements with insufficient coverage. Finally, the optimized Selenium script set that meets the coverage threshold and minimizes redundancy is output.
8. The intelligent conversion method for natural language requirements based on a large language model to Selenium scripts according to claim 1, characterized in that, The method further includes: The manually verified execution feedback, correction records, and new examples are used as training samples to periodically update the prompting project and lightweight knowledge graph. These updates are used to improve the accuracy of subsequent normalization, element extraction, and template generation, thereby achieving continuous learning and performance evolution.
9. An intelligent conversion system for natural language requirements based on a large language model to Selenium scripts, characterized in that, include: The requirement text normalization module is used to receive requirement text, perform normalization processing, and obtain normalized requirement text. The test element structuring module is used to extract test elements from the standardized requirement text and map them to the interface to obtain structured test elements. An enhanced context building module is used to construct an enhanced context representation based on the structured test elements, the target DOM, and domain knowledge; The script template and localization strategy generation module is used to map the enhanced context representation into a parameterizable script template and generate a robust localization strategy, thereby obtaining the script template and localization strategy. The initial script generation and execution module is used to generate and execute an initial Selenium script based on the script template and the positioning strategy, so as to obtain an executable Selenium script and execution feedback. The script adaptive optimization module is used to adaptively correct and remove redundancy from the structured test elements and the script template based on the execution feedback, so as to obtain an optimized Selenium script set.