Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
Example 1
Fig. 1 is a flowchart of a method for automatically generating a script according to an embodiment of the present invention, where the method may be performed by a script automatic generating device, and the device may be implemented in software and/or hardware.
As shown in fig. 1, the method of this embodiment includes:
s110, calling a pre-written web script template, editing the web script template to obtain a web script template to be analyzed, and calling a script generation device when detecting a target control on the triggering web script template so as to import the web script template to be analyzed into the script generation device.
Wherein, web script templates are pre-written. As shown in fig. 2, the pre-written web script includes script steps, step names, browser types, URL paths, element positioning manners, element positioning values, actions, input contents, execution success expected results, execution failure expected results, and the like. The user who needs to obtain the target web script information can pre-call the web script template, edit the corresponding content in the template, and obtain the target web script information after processing the edited content. Each space of the edited content in the web script template may be used as a control. The target control may understand a control that triggers execution of the next operation, and optionally a "confirm" control. The script generating means may be understood as means for processing the content edited in the web script template. And editing the content in the web script template to obtain the script template as the web script template to be analyzed.
Specifically, when the target web script information needs to be obtained, a pre-written web script template can be called, corresponding content is edited in the web script template, and after the content editing is completed, a target control on the web script template can be triggered, namely, a 'confirmation' control on the web script template is triggered. Upon receiving a request corresponding to the "confirm" control, the script generation apparatus may be invoked to import the web script template to be parsed into the script generation apparatus.
Optionally, determining content corresponding to each control based on header information in the web script template to obtain a web script template to be analyzed, and calling the script generating device when detecting triggering a target control in the web script template to be analyzed; and acquiring the web script template to be analyzed based on a target import instruction, and importing the web script template to be analyzed into the script generation device.
The web script template to be analyzed is a template obtained after the content editing in the web script template is completed. The import instruction may be a pre-written application or a command that the user may trigger importing the web script template to be parsed into the script generating device.
Specifically, when the target web script information needs to be generated, the content needing to be edited can be determined according to the header information of the web script template, and after the content is edited, the determination control can be clicked or the content is edited, and the web script template written with the content is used as the web script template to be analyzed. After the web script template to be analyzed is obtained, the web script template to be analyzed can be imported to the script generating device based on the target import instruction.
S120, analyzing the web script template to be analyzed based on the script analyzing module to obtain target web script information, and importing the target web script information into a target file.
The script analysis module may be a module set in the script generating device and used for analyzing and processing the edited content in the web script template; the web script template may be a program code written in advance to analyze the content in the web script template. The target web script information is script information obtained by analyzing and processing web script contents. The object file is used to store object web script information.
Specifically, the script generating device comprises a script analyzing module, the script analyzing module can analyze and process the web script to be analyzed to obtain target web script information, and the target web script information is imported into a target file. The content in the target file may be as shown in fig. 3, and the obtained web script file may be as shown in fig. 3.
In this embodiment, the analyzing the web script template to be analyzed based on the script analyzing module to obtain the target web script information includes: the script analysis module reads the web script template to be analyzed according to a preset rule, and acquires the content in the web script template to be analyzed to obtain target web script information; a library file corresponding to the target web script information is determined and imported into the target web script information.
The preset rule may be to read the content in the web script template to be parsed line by line.
Specifically, the parsing module in the script generating device can process the content in the web script template to be parsed row by row to obtain the target web script information. To determine a library file corresponding to the target web script information because some common library is required during script execution, and import the library file into the target web script information.
After obtaining the target web script information, the target web script information also needs to be stored in the target file, and therefore, before importing the target web script information into the target file, a detection module in the script generating apparatus also needs to be called to determine whether the target file exists. Optionally, deleting the content in the file when the detection module detects that the file corresponding to the target web script information exists in the script generation directory, and taking the file with the emptied content as the target file; or, creating a target file corresponding to the target web script to store the target web script information in the target file based on the detection module not detecting that the file corresponding to the target web script information exists in the script generation directory.
Specifically, when the detection template detects that the script generation directory includes a file corresponding to the target web script information, namely an original file, the stored content in the original file can be deleted, namely all the content stored in the original file is deleted, and the original file with the emptied content is used as the target file, so that the target web script information is stored in the target file; it is also possible to delete the original file and reestablish the target file corresponding to the target web script information. Of course, if the detection module does not detect that the file corresponding to the target web script information exists in the script generation directory, the target file corresponding to the target web script information may be directly created to store the target web script information into the target file.
In order to determine whether an error exists in time in the process of generating the target web script information, a detection check program is also required to detect whether an error exists. Optionally, when the script analysis module analyzes the web script template to be analyzed, the verification program code is invoked to verify the analyzed web script information, and the web script information passing the verification is taken as target web script information.
When verification fails, error information may be displayed on the display interface, so that the user adjusts the content written in the web script according to the error information.
Specifically, if when the verification program code verifies that the web script information has dislocation when the target web script information is generated, that is, when the verification fails, a prompt of error information can be popped up on the display interface, and the user can re-edit the content in the web script template according to the error information until the target web script information is generated.
According to the technical scheme, the web script template to be analyzed is obtained by calling the pre-written web script template and editing the web script template, and when the target control triggering the web script template is detected, the script generation device is called to guide the web script template to be analyzed into the script generation device; the method comprises the steps of analyzing a web script template to be analyzed based on a script analysis module to obtain target web script information, importing the target web script information into a target file, solving the technical problems that most testers in the prior art are not familiar with programming languages and selenium, a certain difficulty exists in writing web scripts, and the web scripts are inconsistent due to inconsistent encoding styles of different programmers, so that the lower output efficiency of the web scripts is affected, automatic writing of the web scripts is realized, the script writing efficiency is improved, the labor cost is reduced, the format of the web scripts can be unified, and the technical effects of large-batch unified management are facilitated.
Example two
As a preferred embodiment of the foregoing embodiments, fig. 4 is another flow chart of a script automatic generation method according to a second embodiment of the present invention. As shown in fig. 4, the method includes:
s401, starting.
It is understood that the target web script information needs to be acquired.
S402, a template editing device.
The template editing device can be understood as a pre-written web script template. The Web script template may include: use case step, script name, browser type, URL path, element location mode, element location value, action, input content, execution success expected result, execution failure expected result. The user may edit the corresponding content in the corresponding box or may select the content to be written to each control when the user triggers each control.
Specifically, the user can edit the required content in the web script template according to the actual requirement to obtain the web script template to be analyzed.
S403, calling a script generator.
Wherein the script generator is script generating means. A script generator may be understood as a device that processes data compiled in a web script template.
Specifically, after the web script template to be parsed is obtained, the script generating device may be invoked.
S404, importing the web script template to be analyzed into a script generator.
The imported template is a web script template to be analyzed.
Specifically, after the script generation device is called, the web script template to be parsed may be imported into the script generator.
S405, selecting a language to be generated by the web script template to be parsed.
The user can set the type of the computer language according to the actual requirement, and the computer language is optional, namely, C language, java language and the like.
Specifically, after the user triggers the language selection control, multiple languages can be popped up on the display interface for selection by the user, and the user can select the language type according to actual requirements.
S406, a script analysis module in the script generator analyzes the web script template to be analyzed.
Specifically, after determining the language type to be converted, an analysis module in the script generator can be called to analyze the web script template to be analyzed. I.e. the content in the web script template to be parsed is obtained.
S407, judging whether the same script file name exists, if so, executing S408; if not, S409 is performed.
The script file refers to whether a file of a web script template to be parsed exists or not. If so, deleting the original web script template, namely deleting the stored original file, and executing S408; if the web script information is not stored, a new script file is established and is used as a target file to store the analyzed web script information.
S408, deleting the original script file.
That is, when the automation script files with the same name exist under the catalog, the original script file can be deleted, and a new script file can be re-created as a target file to store the parsed web script file to be parsed.
S409, generating a new target file under the script directory.
And creating a new script file under the catalog as a target file, and storing corresponding target web script information after the web script template to be analyzed is analyzed.
S410, writing the library file into the target web script information.
The library functions refer to some public libraries in the script execution process, and methods in the public libraries are needed in some scripts. Therefore, after the web script template to be parsed is parsed, a library file corresponding to the parsed content can be determined and imported into the web script to be parsed. The target web script information is the web script template to be analyzed after the analysis.
Specifically, the content in the web script template to be analyzed is analyzed, a library file corresponding to the target web script information is determined, and the library file is imported to the target web script information.
S411, writing the test function into the target file.
Wherein the test function may be understood as target web script information. The target web script information corresponds to content edited in the web script template to be parsed.
Specifically, web script contents may be sequentially written into the target file to obtain a web script file, i.e., a web script required by the user.
It should be noted that, writing the test function into the target file, that is, writing the target web script information into the target file may be: for clarity of understanding of specific logic, it may be understood in conjunction with fig. 2. Reading the template content row by row starting from the second row, a < 0 >. A < 9 > representing the value of each column of the row, respectively; if a [0] is not empty, a [0] is written into the script file, if a [2] is not empty, a [2] is written into the script file (a [2] is selected by a browser), and if a [3] is not empty, a [3] is written into the script file (a [3] is URL input); and determining whether to perform exception handling on the related operation of the element according to whether the expected result is filled in. If the expected result is filled, the operation of the element is processed abnormally, if the execution is successful, a [8] is returned, if the execution fails, a [9] is returned, the main function is exited, and False is returned. If the expected result is not filled in, the operation of the element is not subjected to abnormal detection processing, and the related operation of the element is directly written into the test main function. It should also be noted that the positioning of elements to perform a related action is considered a set of consecutive input features. A [4], a [5], a [6], a [7] (a [4] is element positioning mode, a [5] is element positioning value, a [6] is action, a [7] is input content) is added into an action list. The element positioning mode and the values in the action table are corresponding to specific scripts in a dictionary mode, for example, when a [4] is name, the corresponding script is 'find_element_by_name'. At this time, we can output the operation script of an element according to a certain format only according to the value corresponding to the action list. And repeatedly executing the operation, and executing the last line in the completed template to obtain a complete main test function script, namely a file corresponding to the content of the web script template to be analyzed.
S412, writing the test entry script into the target file.
Wherein a test entry script may be understood as a test command line. Test functions, i.e., target web script information, cannot run directly and must have a call to run. A test entry is a piece of code that can call a test function.
Specifically, a test entry script corresponding to the target web script information is determined, and the test entry script is written into the target file.
It should be noted that, the library file, the test main function and the test entry script together form a test script, and the script needs to be normally operated, which is indispensable. The library file determines whether some methods in the test master function can be normally executed, and the test master function is a main body part tested by us, namely the content in the web script template obtained after the web script template to be analyzed is analyzed. If the test content needs to be executed, an entry needs to be defined, so that the test script entry can call the test main function.
S413, judging whether the generation of the target web script information is successful; if not, then S414 is executed; if yes, S415 is performed.
In this embodiment, in order to improve the efficiency of acquiring the target web script information, an automatic verification module, that is, a verification program is also provided. The automatic checking module is used for judging whether the script is successfully generated. If not, the error reason can be popped up on the display interface, so that the user can edit new content in the web script template again according to the error prompt, that is, S414 is executed; if so, the verification is successful, the web script file is obtained, and the operation is ended.
S414, re-editing the web script template according to the error prompt information.
That is, the web script file is not automatically generated, and script error information may be popped up on the display interface so that the user may re-edit the content in the web script template according to the error information prompt.
When the editing of the web script template is completed, the above steps may be repeatedly performed to generate a web script file.
S415, ending.
And ending the program operation.
In this embodiment, a block diagram corresponding to the web script automation generation method may be referred to fig. 5. Writing content into a user web script template to obtain a web script template to be analyzed, and importing the web script template to be analyzed into a script generator so that the script generator can acquire original data in the web script template to be analyzed. The analysis module in the script generator can analyze the web script template to be analyzed, and the analyzed data contains contents such as script names, browser types and the like, so that target web script information is obtained. The target web script information includes a library file and a test script entry corresponding to script contents. If errors are reported in the process of generating the target web script information, the generation of the target web script information fails, the web script template needs to be edited again, and if errors are not reported, the generation of the script information is successful.
According to the technical scheme, the web script template to be analyzed is obtained by calling the pre-written web script template and editing the web script template, and when the target control triggering the web script template is detected, the script generation device is called to guide the web script template to be analyzed into the script generation device; the method comprises the steps of analyzing a web script template to be analyzed based on a script analysis module to obtain target web script information, importing the target web script information into a target file, solving the technical problems that most testers in the prior art are not familiar with programming languages and selenium, a certain difficulty exists in writing web scripts, and the web scripts are inconsistent due to inconsistent encoding styles of different programmers, so that the lower output efficiency of the web scripts is affected, automatic writing of the web scripts is realized, the script writing efficiency is improved, the labor cost is reduced, the format of the web scripts can be unified, and the technical effects of large-batch unified management are facilitated.
Example III
Fig. 6 is a schematic diagram of an automatic script generating device according to a third embodiment of the present invention, where the device includes: the script generating means invokes the module 610 and the Web script information generating module 620.
The script generation device calling module 610 is configured to call a pre-written web script template, edit the web script template to obtain a web script template to be parsed, and call a script generation device when detecting a target control triggering the web script template, so as to import the web script template to be parsed into the script generation device; and the Web script information generating module 620 is configured to perform an parsing process on the Web script template to be parsed based on the script parsing module, obtain target Web script information, and import the target Web script information into a target file.
According to the technical scheme, when the target control on the script template is detected to be triggered by calling the pre-written web script template, a script generating device is called to guide the web script template into the script generating device; the web script template is analyzed based on the script analysis module to obtain target web script information, and the target web script information is imported into a target folder, so that the problems that most testers in the prior art are not familiar with programming languages and selenium, a certain difficulty exists in writing web scripts, and the web scripts are inconsistent due to inconsistent encoding styles of different programmers are solved, the technical problem of lower web script output efficiency is affected, automatic writing of web scripts is realized, script writing efficiency is improved, labor cost is reduced, and the technical effects of convenience in large-scale unified management are achieved due to unified web script formats written.
On the basis of the technical scheme, the script generating device calling module is further used for:
determining contents corresponding to each control on the basis of header information in the web script template to obtain a web script template to be analyzed, and calling the script generating device when detecting triggering of a target control in the web script template to be analyzed;
and acquiring the web script template to be analyzed based on a target import instruction, and importing the web script template to be analyzed into the script generation device.
On the basis of the above technical solutions, the script generating device calling module is further configured to, before the importing the target web script information into the target folder, further be configured to:
deleting the content in the folder when the detection module detects that the folder corresponding to the target web script information exists in the script generation directory, and taking the folder with the emptied content as the target folder; or alternatively, the first and second heat exchangers may be,
creating a target folder corresponding to the target web script to store the target web script information in the target folder based on the detection module not detecting that the folder corresponding to the target web script information exists in the script generation directory.
On the basis of the above technical solutions, the web script information generating module is further configured to:
the script analysis module reads the web script template to be analyzed according to a preset rule, and acquires the content in the web script template to be analyzed to obtain the target web script information;
determining a library file corresponding to the target web script information, and importing the library file into the target web script information.
On the basis of the technical schemes, the device further comprises: the test entry script writing module is used for:
determining a test entry script corresponding to the target web script information, and writing the test entry script into the target file to test the target web script information stored in the target file.
On the basis of the above technical solutions, the web script information generating module is further configured to:
and when the analysis script module analyzes the web script template, calling a verification program code to verify the analyzed web script information, and taking the web script information passing the verification as the target web script information.
On the basis of the technical schemes, the device further comprises: a verification module for:
and when the verification fails, prompting error information so that a user can adjust the written content in the web script template according to the error information.
The script automatic generation device provided by the embodiment of the invention can execute the script automatic generation method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
It should be noted that each unit and module included in the above apparatus are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the embodiments of the present invention.
Example IV
Fig. 7 is a schematic structural diagram of a server according to a fourth embodiment of the present invention. Fig. 7 shows a block diagram of an exemplary server 70 suitable for use in implementing embodiments of the present invention. The server 70 shown in fig. 7 is only an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
As shown in FIG. 7, the server 70 is embodied in the form of a general purpose computing device. Components of server 70 may include, but are not limited to: one or more processors or processing units 701, a system memory 702, and a bus 703 that connects the various system components (including the system memory 702 and the processing units 701).
Bus 703 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Server 70 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by server 70 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 702 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 704 and/or cache memory 705. Server 70 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 706 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 7, commonly referred to as a "hard drive"). Although not shown in fig. 7, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 703 through one or more data medium interfaces. Memory 702 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of embodiments of the invention.
A program/utility 708 having a set (at least one) of program modules 707 may be stored in, for example, memory 702, such program modules 707 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 707 generally perform the functions and/or methods of the embodiments described herein.
The server 70 may also be in communication with one or more external devices 709 (e.g., keyboard, pointing device, display 710, etc.), one or more devices that enable a user to interact with the server 70, and/or any devices (e.g., network card, modem, etc.) that enable the server 70 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 711. Also, server 70 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, through a network adapter 712. As shown, network adapter 712 communicates with other modules of server 70 via bus 703. It should be appreciated that although not shown in fig. 7, other hardware and/or software modules may be used in connection with server 70, including, but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processing unit 701 executes various functional applications and data processing by running a program stored in the system memory 72, for example, implements the script automatic generation method provided by the embodiment of the present invention.
Example five
A fifth embodiment of the present invention also provides a storage medium containing computer-executable instructions for performing a script automatic generation method when executed by a computer processor.
The method comprises the following steps:
calling a pre-written web script template, editing the web script template to obtain a web script template to be analyzed, and calling a script generating device when detecting a target control triggering the web script template so as to import the web script template to be analyzed into the script generating device;
and analyzing the web script template to be analyzed based on a script analysis module to obtain target web script information, and importing the target web script information into a target file.
The computer storage media of embodiments of the invention may take the form of any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for embodiments of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.