CN116010253A - Script generation method, script generation device, and computer storage medium - Google Patents

Script generation method, script generation device, and computer storage medium Download PDF

Info

Publication number
CN116010253A
CN116010253A CN202211635039.1A CN202211635039A CN116010253A CN 116010253 A CN116010253 A CN 116010253A CN 202211635039 A CN202211635039 A CN 202211635039A CN 116010253 A CN116010253 A CN 116010253A
Authority
CN
China
Prior art keywords
script
browser
generating
page
user
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211635039.1A
Other languages
Chinese (zh)
Inventor
蒋付明
胡明
曹建
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Bank Co Ltd
Original Assignee
Ping An Bank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Bank Co Ltd filed Critical Ping An Bank Co Ltd
Priority to CN202211635039.1A priority Critical patent/CN116010253A/en
Publication of CN116010253A publication Critical patent/CN116010253A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Stored Programmes (AREA)

Abstract

The application discloses a script generation method, a script generation device and a computer storage medium, wherein the script generation method comprises the following steps: responding to the script generation instruction, and starting recording an operation interface by utilizing an automatic test tool; responding to the user operation instruction, and displaying a process of operating the browser based on the user operation instruction on an operation interface; and generating a corresponding script according to the process of operating the browser in the operation interface. Through the mode, the method and the device can record the operation of the user by utilizing the automatic testing tool, so that the script corresponding to the operation of the user is directly generated, the script generation efficiency is improved, the script generation mode is simple, the use threshold of the user is reduced, and the use experience of the user is improved.

Description

Script generation method, script generation device, and computer storage medium
Technical Field
The present invention relates to the field of script generation, and in particular, to a script generation method, a script generation apparatus, and a computer storage medium.
Background
With the continuous development of internet technology, more and more channels are available for people to acquire information. People are more willing to acquire the latest information on digital media such as microblogs, weChat public numbers, etc. than traditional media such as televisions, magazines, outdoor advertisements, etc. These emerging digital media primarily employ web pages to provide an interactive platform for users to interact with their corresponding websites. These web pages often require testing of their functionality before they can be put into practical use.
In an application scenario, when a tester needs to test a web page by using a script, the tester needs to write the script manually by himself, so that the efficiency of script generation is low. And when the script is generated, a tester is required to locate the positions of the elements involved in the page when the script is used, so that the script writing process is time-consuming, and more unnecessary manpower and time are wasted.
Disclosure of Invention
The technical problem that this application mainly solves is how to improve the efficiency of writing the script, and to this end, this application provides a script generation method, script generation device and computer storage medium.
In order to solve the technical problems, one technical scheme adopted by the application is as follows: provided is a script generation method, the method including: responding to the script generation instruction, and starting recording an operation interface by utilizing an automatic test tool; responding to the user operation instruction, and displaying a process of operating the browser based on the user operation instruction on an operation interface; and generating a corresponding script according to the process of operating the browser in the operation interface.
Wherein the script generation instructions include a language used by the script, a script name, a browser name, and/or a script execution address.
Wherein, after generating the corresponding script according to the process of operating the browser in the operation interface, the method further comprises: and generating a case corresponding to the operation process, wherein the case is used for calling the script to test the page in the browser.
The script generation method further comprises the following steps: acquiring page change information corresponding to the case, updating an execution code about page operation in the script based on the page change information, and acquiring an updated script; and updating the script associated with the case according to the updated script.
Wherein the automated test tool is playwrite.
The method comprises the steps of generating a corresponding script according to the process of operating the browser in the operation interface, wherein the method comprises the following steps: analyzing the browser operation process by using an automatic test tool; positioning elements in a page in the browser by utilizing the analysis result; a script is generated that operates on the element.
The method for locating the elements in the page in the browser by utilizing the analysis result comprises the following steps: obtaining positioning information of the element by utilizing the analysis result; elements in the page are located based on the location information.
The script generation method further comprises the following steps: testing pages in the browser by utilizing the script; the script also comprises an assertion result corresponding to the script, and the assertion result is used for judging whether the test result meets the requirement of a user.
In order to solve the technical problems, another technical scheme adopted by the application is as follows: there is provided a script generating apparatus comprising a processor and a memory, the memory being coupled to the processor, the memory storing program data, the processor being for executing the program data to implement a script generating method as described above.
In order to solve the technical problems, another technical scheme adopted by the application is as follows: there is provided a computer readable storage medium storing program data for implementing the script generation method described above when executed.
The beneficial effects of this application are: different from the situation of the prior art, the script generation method provided by the invention is applied to a script generation device, and the script generation device responds to a script generation instruction and starts recording an operation interface by utilizing an automatic test tool; responding to the user operation instruction, and displaying a process of operating the browser based on the user operation instruction on an operation interface; and generating a corresponding script according to the process of operating the browser in the operation interface. By means of the method, compared with a conventional script generation method, the automatic test tool is used in the script generation device to record the operation of the tester on the page in the browser, so that the operation process is directly translated into the script, the script generation efficiency can be improved, and the operation threshold of the tester is reduced. The testers do not need to write codes in the scripts by themselves, and only need to operate the functions which need to be realized by the scripts by themselves by using the script generating device once, so that the whole operation process can be recorded and the corresponding scripts and test cases can be generated by using an automatic test tool. The method for generating the script by script recording also greatly reduces the time required by generating the script, and saves the time and labor cost. Compared with the conventional script generation method, the script generation method provided by the application does not need to write the script and the used test cases manually, reduces the possibility of error of the script, and is more convenient for maintenance of the script.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Wherein:
FIG. 1 is a flowchart of a first embodiment of a script generation method provided in the present application;
FIG. 2 is a schematic flow chart of a script generating device implementing a script generating method;
FIG. 3 is a flowchart of a second embodiment of a script generation method provided herein;
FIG. 4 is a flowchart of a third embodiment of a script generating method provided in the present application;
FIG. 5 is a schematic diagram of the first embodiment of the script generating apparatus provided in the present application;
FIG. 6 is a schematic diagram of a second embodiment of a script generating apparatus provided herein;
fig. 7 is a schematic structural diagram of an embodiment of a computer readable storage medium provided in the present application.
Detailed Description
The following description of the technical solutions in the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
The script generation method provided by the application is mainly applied to automatic testing of web pages. The web page is an interface for displaying information on the internet, and is a basic unit constituting a website. It can connect the multimedia information such as words, graphics, sound and animation, etc. together, and it is generally composed of station sign, navigation bar, advertisement bar, information area, etc. People can find their own desired material, read novels, watch videos, etc. through web pages.
Since web pages have various functions and require user interaction with the page, UI automation test is required for the functions that can be realized by the whole web page, and the UI automation test is a process of operating the page through a browser by simulating human behavior through codes or tools to check whether the page realizes the desired functions.
Referring to fig. 1 and fig. 2, fig. 1 is a flowchart of a first embodiment of a script generating method provided in the present application, and fig. 2 is a flowchart of a script generating device implementing the script generating method provided in the present application.
Step 11: and responding to the script generation instruction, and starting recording the operation interface by utilizing an automatic testing tool.
Specifically, the script generation instructions include a language used by the script, a script name, a browser name, and/or a script execution address. For example, the user may input script generation instructions on a display screen of the script generation apparatus: "python-m playwright codegen- -target python-o 'test. Py' -b chrome https:// www.baidu.com). The language used for representing the generated script is python, the script name is test, the browser used is google browser, and the execution address of the script is www.baidu.com. The user can select to generate scripts of other languages, such as JavaScript, according to the test requirement of the user. The kind of the browser may also be selected according to the user's requirement, which is not limited herein.
The script generation device does not need to install a browser driver corresponding to the browser and the browser version, only needs to write a browser used in a script generation instruction, and operates the script by calling the built-in browser. Compared with the conventional script generation device, the script generation device does not need to build a corresponding script use environment, is more convenient to use and has higher starting speed.
In an embodiment of the present application, the script generating device may also be used for page testing on the mobile terminal by simulating the mobile phone device, that is, the page used in the script generating instruction may also be an html5 page.
Specifically, after receiving a script generation instruction sent by a user, the script generation device responds to the script generation instruction to open a webpage designated by the user on a display interface of the script generation device. For example, when the browser selected for use in the script generation instruction input by the user is Firefox and the webpage is https:// www.baidu.com, the script generation device opens the hundred-degree home page in the fire fox browser for the user to perform the next operation.
Specifically, the automated testing tool is playwrite, and can drive the browser to perform various automated operations, and is installed in the script generating device for use by a user. playwrite can support all currently mainstream browsers including google browser, firefox browser, microsoft browser, etc., and can provide a well-established automated controlled API interface for these browsers.
playwrite supports two writing modes, one is asynchronous mode and the other is synchronous mode, and different modes can be selected and used according to actual needs. The synchronous mode is that codes in the program are sequentially executed, and a later task needs to wait for the execution of the previous task to be finished before the execution of the previous task is finished. Asynchronous mode is that the next task will not be started until the task ends, for time-consuming operation, asynchronous mode will execute the next task immediately after starting the task, and for time-consuming operation, the subsequent logic will be defined by callback function. And after the time-consuming task is finished, automatically executing the processing in the callback function.
Step 12: and responding to the user operation instruction, and displaying a process of operating the browser based on the user operation instruction on an operation interface.
Specifically, after the display interface of the script generating device opens the webpage designated by the user, the user can operate on the opened webpage, i.e. the operation interface, and any operation performed on the webpage by the user on the operation interface is recorded by the script generating device. The user can perform any operation on the operation interface, such as clicking a search box of the hundred degrees home page, inputting another website in the address bar, and the like. At this time, the script generating apparatus highlights the specific module being operated by the user, and displays the corresponding positioning element in the vicinity of the specific module being operated.
Step 13: and generating a corresponding script according to the process of operating the browser in the operation interface.
Specifically, the script generating device generates a code corresponding to the user operation, that is, a corresponding script, based on the recorded operation of the operation interface by the user. The generated script may be run directly by the script generating means for reproducing the operation just performed by the user. The script generating device records the mode that the user operates and generates the script based on the recorded process, so that the user, namely a tester, does not need to write the script by himself, and the script generating efficiency is improved. The script is directly generated after the operation process of the user is analyzed, so that script errors caused by the problems of manual errors, negligence and the like can be avoided, and the possibility of script errors is reduced.
Specifically, the script generated by the script generating means may be directly located to a specific element in the browser page. The steps of the script generating device for generating the script capable of positioning the element are shown in fig. 3, and fig. 3 is a schematic flow chart of a second embodiment of the script generating method provided in the present application, where the script capable of directly positioning the page element can be generated by the method shown in fig. 3.
Step 31: and analyzing the browser operation process by using an automatic test tool.
Specifically, the script generating device may analyze the process of operating the browser by the user by using the automated test tool, and acquire positioning information, such as id, button name, etc., of the page element involved in each operation step.
Step 32: and positioning the elements in the page in the browser by utilizing the analysis result.
Specifically, the script generating device locates the elements of the page in the browser according to the locating information. The page elements involved in the script do not need to be manually repositioned by a user, so that the script generation efficiency is improved.
For example, when the user clicks the "search" button in the operation process, the script generating device may obtain the name corresponding to the "search" button through analysis, and locate the "search" button in the page through the name, so that the script generated by the script generating device may implement clicking on the "search" button.
Step 33: a script is generated that operates on the element.
Specifically, after the script generating means generates the script, the page in the browser may also be tested by using the script. The script also comprises an assertion result corresponding to the script, and the assertion result is used for judging whether the test result meets the requirement of a user. The purpose of the assertion is to verify that the code meets the expectations of the encoding personnel, and when the program executes to the location of the assertion, the corresponding assertion should be true. If the assertion is not true, the program will cease execution and provide an error message to ensure that the program's defects are found as much as possible during the test phase. For example, when the user clicks the "search" button after inputting the information to be searched in the input box, the result is asserted as the browser to search for the information to be searched by the user. If the browser does not search the information which the user wants to search when the script is executed, the description is that the assertion is false, and the error in the code of the script is proved, so that the script can be modified by a tester in time.
Optionally, after the script generating device generates the script corresponding to the operation, a test case for testing may also be directly generated according to the present operation. Test cases refer to descriptions of test tasks performed on a particular software product, embodying test schemes, methods, techniques and strategies. The contents of the test cases include test targets, test environments, input data, test steps, expected results, test scripts, etc. As in the previous example, when the user clicks on the search box of the hundred degrees home page and enters "banana" therein, the search button is clicked. The script generating device generates a corresponding test case, the test content of the test case is whether the corresponding content can be correctly searched by inputting a banana in a search box of a hundred-degree home page, and the expected result is that the corresponding content can be correctly searched. The test cases may be used to invoke scripts to test pages in the browser.
Specifically, the script generating device stores the generated script and the corresponding test case in a layered manner, so that maintenance of the script and the test case related in the whole test can be facilitated.
In an embodiment of the present application, when a page related to a script that has been recorded is changed, as shown in fig. 4, fig. 4 is a schematic flow chart of a third embodiment of a script generating method provided in the present application, where the embodiment may only change contents in the script by a method shown in fig. 4, and not modify a test case corresponding to the script, so as to reduce maintenance costs for the script and the test case.
Step 41: acquiring page change information corresponding to the case, updating an execution code about page operation in the script based on the page change information, and acquiring the updated script.
Specifically, when the script generating device detects that the page corresponding to the test case is changed, the page is re-recorded based on the page change information, so as to update the execution code about the page operation in the script, and obtain the updated script. For example, when the script is a button for clicking a start button, and the name of the button corresponding to the button is changed from the start to the start of the game, the script generating device needs to re-record the operation of clicking the button by the user, and re-generate the corresponding script according to the recording result, so that the script can normally run. Because the script and the test case are stored in a layered manner, the script generating device does not need to modify the test case, thereby reducing the modification cost and saving the maintenance time.
Step 42: and updating the script associated with the case according to the updated script.
Specifically, the script generating device does not need to update the corresponding test cases, only needs to update the script, and the cases realize execution of the script and test by calling the updated script. The script generation device remarkably reduces maintenance cost through layered management of the test cases and the scripts.
Different from the situation of the prior art, the script generation method provided by the invention is applied to a script generation device, and the script generation device responds to a script generation instruction and starts recording an operation interface by utilizing an automatic test tool; responding to the user operation instruction, and displaying a process of operating the browser based on the user operation instruction on an operation interface; and generating a corresponding script according to the process of operating the browser in the operation interface. By means of the method, compared with a conventional script generation method, the automatic test tool is used in the script generation device to record the operation of the tester on the page in the browser, so that the operation process is directly translated into the script, the script generation efficiency can be improved, and the operation threshold of the tester is reduced. The testers do not need to write codes in the scripts by themselves, and only need to operate the functions which need to be realized by the scripts by themselves by using the script generating device once, so that the whole operation process can be recorded and the corresponding scripts and test cases can be generated by using an automatic test tool. The method for generating the script by script recording also greatly reduces the time required by generating the script, and saves the time and labor cost. Compared with the conventional script generation method, the script generation method provided by the application does not need to write the script and the used test cases manually, reduces the possibility of error of the script, and is more convenient for maintenance of the script.
The method of the foregoing embodiment may be implemented by a script generating apparatus, and is described below with reference to fig. 5, where fig. 5 is a schematic structural diagram of a first embodiment of the script generating apparatus provided in the present application.
As shown in fig. 5, the script generating apparatus 50 of the embodiment of the present application includes a recording module 51, a display module 52, and a generating module 53.
The recording module 51 is configured to start recording the operation interface with an automated testing tool in response to the script generation instruction.
And a display module 52, configured to respond to the user operation instruction, and display, on the operation interface, a process of operating the browser based on the user operation instruction.
The generating module 53 is configured to generate a corresponding script according to a process of operating the browser in the operation interface.
The method of the above embodiment may be implemented by a script generating apparatus, and referring to fig. 6, fig. 6 is a schematic structural diagram of a second embodiment of the script generating apparatus provided in the present application, where the script generating apparatus 60 includes a memory 61 and a processor 62, the memory 61 is used for storing program data, and the processor 62 is used for executing the program data to implement the following method:
responding to the script generation instruction, and starting recording an operation interface by utilizing an automatic test tool; responding to the user operation instruction, and displaying a process of operating the browser based on the user operation instruction on an operation interface; and generating a corresponding script according to the process of operating the browser in the operation interface.
Referring to fig. 7, fig. 7 is a schematic structural diagram of an embodiment of a computer readable storage medium 70 provided in the present application, where the computer readable storage medium 70 stores program data 71, and the program data 71, when executed by a processor, is configured to implement the following method:
responding to the script generation instruction, and starting recording an operation interface by utilizing an automatic test tool; responding to the user operation instruction, and displaying a process of operating the browser based on the user operation instruction on an operation interface; and generating a corresponding script according to the process of operating the browser in the operation interface.
Embodiments of the present application are implemented in the form of software functional units and sold or used as a stand-alone product, which may be stored on a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution, in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing description is only of embodiments of the present application, and is not intended to limit the scope of the patent application, and all equivalent structures or equivalent processes using the descriptions and the contents of the present application or other related technical fields are included in the scope of the patent application.

Claims (10)

1. A browser-based script generation method, the script generation method comprising:
responding to the script generation instruction, and starting recording an operation interface by utilizing an automatic test tool;
responding to a user operation instruction, and displaying a process of operating the browser based on the user operation instruction on the operation interface;
and generating a corresponding script according to the browser operation process in the operation interface.
2. The script generating method as claimed in claim 1, wherein,
the script generation instructions include a language used by the script, a script name, a browser name, and/or a script execution address.
3. The script generating method as claimed in claim 1, wherein,
after the corresponding script is generated according to the process of operating the browser in the operation interface, the method further comprises the following steps:
and generating a case corresponding to the operation process, wherein the case is used for calling the script to test the page in the browser.
4. The script generating method as claimed in claim 3, wherein,
the script generation method further comprises the following steps:
acquiring page change information corresponding to the case, updating an execution code about page operation in the script based on the page change information, and acquiring an updated script;
and updating the script associated with the case according to the updated script.
5. The script generating method as claimed in claim 1, wherein,
the automated test tool is playwrite.
6. The script generating method as claimed in claim 1, wherein,
the generating a corresponding script according to the process of operating the browser in the operation interface comprises the following steps:
analyzing the browser operation process by using the automatic testing tool;
positioning elements in a page in the browser by utilizing the analysis result;
the script is generated that performs the operation on the element.
7. The script generating method as recited in claim 6, wherein,
the positioning the element in the page in the browser by using the analysis result comprises the following steps:
obtaining positioning information of the element by utilizing the analysis result;
elements in the page are located based on the location information.
8. The script generating method as claimed in claim 1, wherein,
the script generation method further comprises the following steps:
testing the pages in the browser by using the script;
the script also comprises an assertion result corresponding to the script, and the assertion result is used for judging whether the test result meets the requirement of a user.
9. A script generating apparatus comprising a memory and a processor coupled to the memory;
wherein the memory is for storing program data and the processor is for executing the program data to implement the script generation method of any of claims 1 to 8.
10. A computer storage medium for storing program data which, when executed by a computer, is adapted to carry out the script generation method of any of claims 1 to 8.
CN202211635039.1A 2022-12-19 2022-12-19 Script generation method, script generation device, and computer storage medium Pending CN116010253A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211635039.1A CN116010253A (en) 2022-12-19 2022-12-19 Script generation method, script generation device, and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211635039.1A CN116010253A (en) 2022-12-19 2022-12-19 Script generation method, script generation device, and computer storage medium

Publications (1)

Publication Number Publication Date
CN116010253A true CN116010253A (en) 2023-04-25

Family

ID=86031172

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211635039.1A Pending CN116010253A (en) 2022-12-19 2022-12-19 Script generation method, script generation device, and computer storage medium

Country Status (1)

Country Link
CN (1) CN116010253A (en)

Similar Documents

Publication Publication Date Title
US8104020B2 (en) Method and system to automate software testing using sniffer side and browser side recording and a toolbar interface
CA2674659C (en) Synchronous to asynchronous web page conversion
CN103810089B (en) Automatically testing gesture-based applications
KR101087312B1 (en) Importation of automatically generated content
KR101076867B1 (en) Automatic image capture for generating content
Little et al. Koala: capture, share, automate, personalize business processes on the web
US9569231B2 (en) Device, system, and method for providing interactive guidance with execution of operations
US7899847B2 (en) System and method for authoring new lightweight web applications using application traces on existing websites
JP4140916B2 (en) Method for analyzing state transition in web page
US20100205529A1 (en) Device, system, and method for creating interactive guidance with execution of operations
US11372661B2 (en) System and method for automatic segmentation of digital guidance content
CN106959919B (en) Software testing method and device based on testing path diagram
CN113448845A (en) UI automation test method and system
CN107451163B (en) Animation display method and device
US11709991B2 (en) Detecting truncation and overlap defects on webpage
CN114897296A (en) RPA flow labeling method, execution process playback method and storage medium
US10275462B2 (en) Automatic translation of string collections
US11461090B2 (en) Element detection
US20230195825A1 (en) Browser extension with automation testing support
CN116010253A (en) Script generation method, script generation device, and computer storage medium
US11550990B2 (en) Machine first approach for identifying accessibility, non-compliances, remediation techniques and fixing at run-time
Cisco Creating a Web-enabled Client Application
US11704232B2 (en) System and method for automatic testing of digital guidance content
US20170083297A1 (en) Online discussing system with compiling program function and method thereof
Sugiarti et al. Usability Evaluation on Website Using the Cognitive Walkthrough Method

Legal Events

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