Detailed Description
The technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
Fig. 1 is an alternative flowchart of a test script generation method according to an embodiment of the present invention, which will be described with reference to the steps shown in fig. 1.
S101, when receiving an operation recording instruction, entering a recording page of the website to be tested, and starting recording the recording page.
The operation recording method of the webpage end provided by the embodiment of the invention is suitable for recording the operation on the webpage to be tested for the scene of automatic test and is also suitable for other scenes needing to record the webpage operation.
In the embodiment of the invention, the terminal is provided with automatic recording software, and when a recording button in the automatic recording software is clicked or a command statement for starting recording is operated in a system command line of the terminal, the terminal receives an operation recording instruction.
In the embodiment of the invention, when a recording instruction is received, the test script generating device can automatically open the browser through the recording script, enter the recording page of the website to be tested, start the monitoring event bound with the recording page, and start the recording process of the recording page.
In the embodiment of the invention, the website to be tested is a test object website which needs to be automatically tested, in the recording stage of the test script, the page opened by the test script generating device through the recording script is a recording page of the website to be tested, and the test script generating device starts monitoring the recording page to obtain page operation carried out on the recording page.
In some embodiments of the present invention, the test script generating device may open the chrome kernel browser by operating the recording instruction in the node.js execution environment, enter the recording page of the website to be tested, and start recording the recording page.
In the embodiment of the present invention, the test script generating device enters the recording page of the website to be tested, and starting recording on the recording page may include S1011-S1012, as follows:
s1011, acquiring the recording script, wherein a monitoring function is configured on the recording page, and the monitoring function is used for monitoring the preset type of operation event on the recording page.
And S1012, when receiving the operation recording instruction, calling the recording script to open the recording page to start monitoring, and starting recording the recording page.
In the embodiment of the invention, the test script generating device configures a monitoring event on the recording page, and is used for monitoring the operation on the page to be recorded so as to acquire the operation event configured in the monitoring event.
In the embodiment of the present invention, as shown in fig. 2, the monitoring event is an operation event that needs to be monitored and is configured on a web page to be tested by the test script generating device, and may include a click event on the web page to be tested, a keyboard input event, a selection event, a dialog box pop-up event, and the like; for each monitored operation event, the test script generating device can correspondingly acquire the information of the webpage element corresponding to the operation event after monitoring that the operation event occurs on the browser page.
In some embodiments of the present invention, the web page element information may include an innertext field, an id field, and a name field, where the innertext field represents text information that may be displayed on the web page element; the id field represents a unique identifier of the webpage element in the page; the name field represents the internal name of the web page element.
In the embodiment of the invention, a test script generating device can bind a monitoring event with the starting of a browser in a recording script, exemplarily, in a node.js execution environment, the test script generating device uses a record.js as the recording script, wherein the record.js is a JavaScript script, a specific address of a website to be tested and the monitoring event are configured in the record.js, when an operation recording instruction is received, the test script generating device calls the record.js script, automatically opens a chrome browser through the record.js script and enters a recording page according to the website to be tested, and starts monitoring on the recording page according to the monitoring event configured on the recording page.
It should be noted that, in the embodiment of the present invention, the test script generating device may also start recording the recording page by using other methods besides monitoring, for example, the recording page is recorded by obtaining an event notification actively sent by an operation on a web page, and the specific selection is performed according to an actual situation, which is not limited in the embodiment of the present invention.
In the embodiment of the invention, the test script generating device uses the recording script, and after the monitoring event is configured on the recording page, the test script generating device can also call the service realization script in the recording script, so that the recording page responds to the operation information according to the service realization script.
In the embodiment of the invention, the main implementation logic of the webpage program of the website to be tested is packaged in the service implementation script, illustratively, how to jump to a corresponding page address after clicking a certain button, how to prompt after successfully storing the input characters, and similar service logic codes and the like, and the test script generation device can make the recording page perform corresponding response to the operation information according to the monitored service logic of the operation information in the recording script, update the display state of the recording page according to the response result, and continue recording on the recording page with the updated display state.
In some embodiments of the present invention, the test script generating device may use a JavaScript script common.js as a service implementation script, and the test script generating device mainly encapsulates, in a record script record.js, basic configurations related to a record script such as a website to be tested and a monitoring event, and calls the common.js in the record script record.js; js mainly packages main business logic of a webpage program of the website to be tested. Thus, the test script generating device can complete the configuration of the test script recording only by configuring or modifying the recording script record.js, and can realize the normal response of the to-be-tested website to the operation information in the recording process by calling common.js; and meanwhile, the service logic packaged in common can be called by other modules or scripts, so that the usability and reusability of the test script recording are improved.
It can be understood that, by configuring the recording script, the test script generating device can automatically open the recording page of the website to be tested by calling the recording script and start to record the script.
S102, monitoring operation information on the recorded page, wherein the operation information comprises operation events and webpage elements corresponding to the operation events.
In the embodiment of the invention, after the test script generating device starts monitoring the recording page, the test script generating device monitors the operation information on the recording page, wherein the operation information comprises the operation event and the webpage element corresponding to the operation event.
In the embodiment of the invention, the operation information on the recording page monitored by the test script generating device comprises the operation event. The operation event is an event occurring on the recording page monitored by the test script generating device, and may be, for example, a click event, an input event, a pull-down event, a pop-up event, and the like.
In the embodiment of the present invention, the browser page includes at least one web page element, and the at least one web page element may include a control button, a text box, a hyperlink, a pop-up box, a pull-down menu, a dialog box, and the like on the web page.
In the embodiment of the present invention, the operation information also includes a web page element corresponding to the operation event, and for example, the web page element corresponding to the operation event may be a text box input by the input event, a web page button clicked by the click event, a pull-down menu pulled down by the pull-down event, a dialog box popped up by the pop-up event, and the embodiment of the present invention is not limited.
And S103, when the webpage element contains the text information, extracting the text information as an event object.
In the embodiment of the invention, after the test script generating device monitors the operation information, because the operation information comprises the webpage element corresponding to the operation event, when the webpage element comprises the text information, the test script generating device extracts the text information as the event object.
In the embodiment of the present invention, the text information is text content displayed on a browser page by a web page element, and the text information may be, for example, a name of a button displayed on the button, a name of a dialog box displayed on the dialog box, a name of a pull-down menu, a name of each pull-down option in the pull-down menu, and the like.
In the embodiment of the invention, in the chrome browser, the text information is an innertext field in a webpage element.
It can be understood that in the embodiment of the present invention, the test script is generated by using the text information displayed on the page for positioning and operating the elements, when the software to be tested changes, the changed web page elements can be directly found through the page, and the automatic test can be performed only by correspondingly modifying the intuitive text information in the test script, so that the script maintenance process is simplified, the script does not need to be recorded again, and the maintainability of the generated test script is improved.
And S104, generating a script statement according to the operation event and the event object, and realizing a conversion process of converting the operation information into the script statement.
In the embodiment of the invention, after the test script generating device acquires the event object, the script statement is generated according to the operation event and the event object, and the conversion process of converting the operation information into the script statement is realized.
In the embodiment of the invention, the test script generating device converts the event generated on the recording page into the form of script statements for recording according to the operation event and the event object, converts the operation information into the script statements and completes the recording of the webpage operation.
In the embodiment of the present invention, based on fig. 1, the test script generating device in S104 generates a script statement according to the operation event and the event object, and a conversion process for converting the operation information into the script statement is implemented as shown in fig. 3, and includes S1041-S1042 as follows:
and S1041, generating an execution logic statement for executing the operation event on the event object according to the operation event and the event object.
In the embodiment of the invention, the test script generating device generates the execution logic statement for executing the operation event on the event object according to the relationship between the operation event and the event object.
In some embodiments, the operation event is a click event, the event object is a button a, and the test script generating device may generate an execution logic statement of "click button a" correspondingly.
S1042, adding a judgment logic statement before executing the logic statement to form a script statement, and realizing the conversion of the operation information into the script statement; and the judgment logic statement is generated based on the event object and is used for representing whether the event object exists or not.
In the embodiment of the invention, the test script generating device adds the judgment logic statement before executing the logic statement, wherein the judgment logic statement is generated based on the event object and is used for representing whether the event object exists or not.
In the embodiment of the invention, the test script generating device combines the judgment logic statement and the execution logic statement into the script statement corresponding to the operation information.
In some embodiments, when the operation event is a click event and the operation object is a button a, the test script generating apparatus takes "when the button a exists" as a judgment logic statement in the script statement; "click button a" is taken as an execution logic statement in the script statement, thereby generating a script statement "click button a when button a exists".
In the embodiment of the present invention, for a preset operation event occurring on a page, the test script generating device generates a script statement according to the operation event and the event object, and a conversion process for converting operation information into the script statement may further include S1043, as follows:
s1043, when the operation event is a preset operation event, generating an assertion script statement according to the preset operation event and the event object, and realizing the conversion of the operation information into the script statement; the assertion type script statement is used for verifying whether a preset event occurs or not and displaying the same event object when being called.
In the embodiment of the present invention, the test script generating device may further define some preset operation events, generate an assertion script statement according to the preset operation events and the event objects, and use the assertion script statement as a verification point in the test script, so as to verify the preset events and the event objects when the assertion script statement is executed.
In the embodiment of the invention, the assertion script statement is used for verifying whether a preset event occurs or not and displaying the same event object when being called.
In some embodiments of the present invention, the test script generating device may define a dialog box pop-up event as a preset operation event, and correspondingly, the text information B on the pop-up dialog box is an event object, and when the test script generating device monitors the dialog box pop-up event, an Assert statement is generated according to the dialog box pop-up event and the pop-up dialog box, and the Assert statement is used as the assertion-like script statement 1. When the assertion-like script statement 1 is executed, the test script generating apparatus automatically verifies whether there is a pop-up event on the current page, and pops up a dialog box displaying the same text information B.
It should be noted that, in the embodiment of the present invention, each time the test script generation device monitors the operation information of one recording page, a script statement is correspondingly generated, and the test script generation device continuously monitors the recording page and continuously converts the monitored operation information into the script statement.
And S105, continuing the conversion process until an operation recording ending instruction is received, obtaining at least one script statement corresponding to at least one operation message, and forming a test script by the at least one script statement.
In the embodiment of the invention, the test script generating device converts each monitored operation information into the corresponding script statement in the same way, and the test script generating device obtains at least one script statement corresponding to at least one operation information until an operation recording ending instruction is received.
In the embodiment of the invention, the test script generating device forms the test script according to at least one script statement to complete the generation process of the test script of the website to be tested.
S106, executing the test script on the test page of the website to be tested, and realizing the automatic test of the test page.
In the embodiment of the invention, after the test script generating device obtains the test script, the test script generating device can automatically open the browser and enter the test page of the website to be tested by calling the test script, and the test script generating device executes the script statement in the test script on the test page of the website to be tested, so that the automatic test of the test page is realized.
It can be understood that, in the embodiment of the present invention, the test script generating device generates the test script by using the text information displayed on the page for positioning and operating the elements, when the software to be tested changes, the changed web page elements can be directly found through the page, and the automatic test can be performed only by correspondingly modifying the intuitive text information in the test script, so that the script maintenance process is simplified, and the script does not need to be recorded again, thereby improving the maintainability of the generated test script.
In the embodiment of the present invention, after S102, S107 may be further included, as follows:
and S107, when the webpage element does not contain text information, extracting the element identification or the element name in the webpage element as an event object.
In the embodiment of the invention, when the webpage element does not contain text information, the test script generating device extracts the element identifier or the element name in the webpage element as the event object.
In the embodiment of the invention, when the webpage element in the operation information contains the text information innertext, the test script generating device preferentially extracts the text information innertext as an event object; when the web page element does not contain the text information innertext, the test script generating device may further extract an element identifier id or an element name in the web page element as an event object.
In the embodiment of the present invention, based on fig. 3, the test script generating device in S106 calls the test script on the test page of the to-be-tested website, as shown in fig. 4, including S1061-S1066, as follows:
and S1061, receiving a script test instruction.
In the embodiment of the invention, the test script generating device needs to firstly receive the script test instruction and start the automatic script test on the website to be tested according to the script test instruction.
S1062, entering a test page of the website to be tested according to the script test instruction, and starting monitoring on the test page.
In the embodiment of the invention, after the test script generating device receives the script test instruction, the test script generating device calls the test script to automatically open the browser according to the script test instruction, enters the test page of the website to be tested and starts monitoring the test page.
In the embodiment of the invention, the test page of the website to be tested is the webpage to be actually tested, and in practical application, for the same website to be tested, the record page opened during script recording and the test page opened during actual test may be different.
In the embodiment of the present invention, the test script generating device may bind the monitoring event to the test page according to the same principle in S101, and start monitoring on the test page.
S1063, executing the current script statement in the test script on the test page to obtain an execution result of the current script statement; the current script statement is a script statement being executed in at least one script statement.
In the embodiment of the invention, the test script generating device enters the test page of the website to be tested, and after the monitoring of the test page is started, the test script generating device executes the current script statement of at least one script statement in the test script on the test page to obtain the execution result of the current script statement.
In the embodiment of the present invention, the current script statement is a script statement executed by the at least one script statement.
In the embodiment of the invention, the execution result of the current script statement represents whether the test script generation device can successfully execute the corresponding operation in the current script statement on the test page.
In the embodiment of the invention, the test script generating device executes the current script statement in the test script on the test page to obtain the execution result of the current script statement, and the test script generating device can also call the service realization script in the test script to enable the test page to respond to the current script statement according to the service realization script.
In the embodiment of the present invention, the service implementation script called in the test script is the same as the service implementation script called by the recording script, and is not described herein again.
And S1064, monitoring a page response result of the current script statement when the execution result is successful, wherein the page response result is a result of the current script statement executed on the test page.
In the embodiment of the invention, after the test script generating device successfully executes the current script statement, the page response result of the test script generating device is monitored.
In the embodiment of the invention, the page response result is the result of the current script statement executed on the test page, namely the page state and the webpage elements which are correspondingly updated by the test page after the current script statement is executed.
In some embodiments, the current script statement is "click button a when button a exists", the test page responds to the operation of clicking button a after the test page executes the current script statement, and displays page content C, and the test script generating device takes the page content C as a page response result of the current script statement.
And S1065, determining a test result of the current script statement according to the page response result and an expected result, wherein the expected result is a result of the current script statement executed on the recording page.
In the embodiment of the invention, after the test script generating device monitors and acquires the page response result, the test result of the current script statement is determined according to the page response result and the expected result.
In the embodiment of the invention, the expected result is a response result corresponding to the recording page after the current script statement is executed on the recording page in the recording stage; the expected result characterizes the correct page state that the test page should assume after execution of the current script statement.
In the embodiment of the present invention, the test script generating device determines, according to the page response result and the expected result, that the test result of the current script statement may be: when the page response result is consistent with the expected result, determining a test result with successful characterization; and when the page response result is inconsistent with the expected result, determining a test result representing failure.
In the embodiment of the invention, when the page response result is consistent with the expected result, the execution result of the current script statement on the test page is consistent with the execution result on the recording page, the expected result of correct execution is achieved, and the test script generating device determines that the test result of the current script statement is successful.
In the embodiment of the invention, correspondingly, when the page response result is inconsistent with the expected result, the test script generating device determines that the test result of the current script statement is failure.
In some embodiments, the current script statement is "click button a when button a exists", and the expected result is that the page displays content C after the button a is clicked; the test script generating device executes the current script statement and monitors the page response result to display the content D for the page, and the test script generating device can determine that the test result of the current script statement is failure.
S1066, continuing to execute the next script statement of the current script statement until the execution of at least one script statement is completed, thereby obtaining the test result of at least one script statement and completing the automatic test of the test page.
In the embodiment of the invention, each time the test script generating device executes a script statement in a test script to obtain a test result of one script statement, then the next script statement in at least one script statement is continuously executed, the test script generating device executes the next script statement and obtains a test result of the next script statement in the same way as in S1063-S1065, and until the execution of at least one script statement is completed, the test script generating device obtains the test result of each script statement in at least one script statement as the test result of at least one script statement to complete the automatic test of the test page.
It can be understood that, in the embodiment of the present invention, the test script generating device may automatically open the test page of the website to be tested and execute the test script on the test page, and start performing an automated test, and when the test script is executed on the test page, each script statement is executed only when the last script statement is successfully executed, so that it is avoided that an error occurs in the automatic execution of the script statement, and the stability of the test script is improved.
In this embodiment of the present invention, the step S1063 of executing the current script statement in the test script on the test page by the test script generating device to obtain the execution result of the current script statement may include step S201-S202, as follows:
s201, executing the judgment logic statement in the current script statement on the test page, and determining whether the event object in the current script statement exists.
In the embodiment of the invention, when the test script generating device executes the current script statement, the test script generating device firstly reads and executes the judgment logic statement in the current script statement so as to judge whether the event object in the current script statement exists or not.
S202, when the event object exists, executing the execution logic statement in the current script statement, and determining the execution result of successful characterization.
In the embodiment of the invention, when the event object exists, the webpage element corresponding to the operation time can be found, and the current script statement can be normally executed, so that the test script generating device determines that the execution result is successful, executes the execution logic statement in the current script statement, and completes the execution process of the current script statement.
In some embodiments of the present invention, after S201, S203 is further included, as follows:
s203, when the event object does not exist, determining the execution result of the failed representation, ending the execution of the test script and giving an alarm.
In the embodiment of the invention, after the test script generating device executes the judgment logic statement in the current script statement, when the event object does not exist, the test script generating device indicates that the corresponding webpage element in the currently executed script statement does not exist on the current test page, and the continuous execution can cause serious problems, so that the test script generating device determines that the execution result is failure, interrupts the execution of the test script and gives an alarm.
In the embodiment of the present invention, the alarm mode may be a popup alarm on the test script execution interface, or a popup alarm accompanied by a prompt tone, or other alarm modes, and the embodiment of the present invention is not limited.
In some embodiments, when the test script generating device executes the judgment logic statement in the current script statement and finds that the event object does not exist, the test script generating device pops up an error reporting window on the test script execution interface and displays specific error content in an error log sub-interface on the test script execution interface.
It can be understood that, in the embodiment of the present invention, when an event object of a current script statement exists, the test script generating device executes the current script statement and sequentially executes a next script statement; when the event object of the current script statement does not exist, the test script generating device interrupts the execution of the test script and gives an alarm, so that the serious error that the corresponding webpage element cannot be found during the execution of the test script is avoided, and the stability of the test script is improved.
In some embodiments of the present invention, when the execution result in S1063 is successful, the monitoring of the page response result of the current script statement by the test script generating apparatus in S1064 may include S301-S303, as follows:
s301, when the current script statement is an assertion type script statement, monitoring whether an assertion type test event in the current script statement occurs in a current test page, wherein the current test page is a corresponding webpage page when the current script statement is executed.
In the embodiment of the invention, when the test script generating device executes the assertion script statement, the test script generating device firstly monitors whether an assertion test event in the current script statement occurs in the current test page.
In the embodiment of the invention, the assertion type test event is the corresponding preset operation event type in the current assertion type script statement, the test script generating device reads the assertion type test event in the current script statement, and whether the assertion type test event occurs on the current test page is judged according to the monitored operation information on the current test page.
In the embodiment of the invention, the current test page is a corresponding webpage when the current script statement is executed, namely the corresponding test page state after the last script statement is executed.
In some embodiments, script statement 1 is "click save button when save button exists," declares class script statement 2as Assert (pop-up dialog, "save successful"); when the test script generating device executes the assertion type script statement 2, the test script generating device takes the 'pop-up dialog box' as an assertion type test event, and monitors and captures whether the dialog box pops up or not on the current test page.
S302, when an assertion type test event occurs in the current test page, acquiring an actual webpage element corresponding to the assertion type test event on the current test page.
In the embodiment of the invention, when the test script generating device captures the preset operation event in the current page, the test script generating device acquires the actual webpage element corresponding to the preset operation event on the current test page.
In the embodiment of the invention, the actual webpage element represents the webpage element corresponding to the preset operation event on the current test page.
S303, extracting an actual event object from an actual webpage element according to the current event object in the current script statement; the actual event object has the same attribute as the event object extracted from the webpage element; the actual event object is a page response result.
In the embodiment of the present invention, the test script generating device extracts actual event objects with the same attribute from actual web page elements of the current test page according to attributes of the event objects extracted from web page elements of the recorded page in the current script statement, for example, when an event object in the assertion-like script statement is text information, the test script generating device preferentially extracts the text information from the actual web page elements as the actual event object, and when an event object in the assertion-like script statement is id, the test script generating device correspondingly acquires id of the actual web page elements as the actual event object.
In some embodiments, when the test script generating device executes to assertion-like script statement 2Assert (pop-up dialog box, "save successful"), a dialog box pop is monitored and captured on the current test page, and the test script generating device extracts the text information on the dialog box, illustratively, the text information "save successful", as the actual event object.
In the embodiment of the invention, the test script generation device takes the actual event object as the page response result to be compared with the expected result to obtain the test result of the assertion script statement.
It can be understood that, when the current script statement is the assertion-class script statement, according to the method described in S1065, when the page response result, that is, the actual event object, is consistent with the expected result, that is, the event object in the current script statement, it indicates that the pop-up box same as the current script statement pops up on the current test page, and the test script generating device confirms that the test result of the current script statement of the assertion class is a pass. In some embodiments, the current script statement is an assertion class script statement 2: assert (pop-up dialog box, "save successful"), and displaying text information of successful save on the pop-up dialog box as an expected result; when the test script generating device executes the assertion script statement 2, a dialog box pop-up is monitored and captured on the current test page, the text information of the pop-up dialog box is successfully stored, the test script generating device takes the text information successfully stored as a page response result, and the test result of the current script statement is determined to be successful according to comparison with an expected result.
In the embodiment of the present invention, after S301, S304 is further included, as follows:
s304, when the assertion type test event does not occur in the current test page, determining the test result of the characterization failure.
In the embodiment of the invention, when the test script generating device executes the assertion type script statement, if the assertion type test event is not captured in the current test page, the test script generating device indicates that the assertion type test event does not occur on the current test page as expected in the current script statement, so that the test script generating device can directly confirm that the test result of the current script statement is failure.
In some embodiments, the current script statement is an assertion class script statement 2: assert (pop-up dialog, "save successful"); when the test script generating device executes the current script statement, the dialog box pop-up is monitored on the current test page but not captured, and the test script generating device can determine that the test result of the current script statement is failure.
It can be understood that, in the embodiment of the present invention, the test script generating device may directly obtain the test result according to whether the assertion type test event occurs by executing the assertion type script statement, thereby perfecting the process of the test script generating device performing automatic verification according to the assertion type verification point added in the test script.
An embodiment of the present invention provides a test script generating device, fig. 5 is a schematic diagram of a test script generating device provided in an embodiment of the present invention, and as shown in fig. 5, the test script generating device 4 includes: a starting unit 41, a monitoring unit 42, an extracting unit 43, a generating unit 44 and an executing unit 45; the starting unit 41 is configured to, when receiving an operation recording instruction, enter a recording page of a website to be tested, and start recording the recording page;
the monitoring unit 42 is configured to monitor operation information on the recording page, where the operation information includes an operation event and a web page element corresponding to the operation event;
the extracting unit 43 is configured to, when text information is included in the web page element, extract the text information as an event object;
the generating unit 44 is configured to generate a script statement according to the operation event and the event object, and implement a conversion process of converting the operation information into the script statement;
the generating unit 44 is further configured to continue the above conversion process until an operation recording end instruction is received, obtain at least one script statement corresponding to at least one piece of operation information, where the at least one script statement forms a test script;
the execution unit 45 is configured to execute the test script on the test page of the website to be tested, so as to implement an automatic test on the test page.
Optionally, the generating unit 44 includes a first generating subunit and a second generating subunit; wherein,
the first generation subunit is configured to generate, according to the operation event and the event object, an execution logic statement for executing the operation event on the event object;
the second generation subunit is configured to add a judgment logic statement before the execution logic statement to form the script statement, so as to convert the operation information into the script statement; the judgment logic statement is generated based on the event object and is used for representing whether the event object exists or not.
Optionally, the generating unit 44 further includes a third generating subunit; wherein,
the third generating subunit is configured to, when the operation event is a preset operation event, generate an assertion-like script statement according to the preset operation event and the event object, and implement conversion of the operation information into a script statement; the assertion script statement is used for verifying whether the preset event occurs or not and displaying the same event object when being called.
Optionally, the monitoring unit 42 includes a first obtaining subunit and a calling subunit; wherein,
the first obtaining subunit is configured to obtain a recording script, and a monitoring function is configured on the recording page and is configured to monitor an operation event of a preset type on the recording page;
and the calling subunit is used for calling the recording script to open the recording page to start monitoring and start recording the recording page when the operation recording instruction is received.
Optionally, the extracting unit 43 is further configured to extract an element identifier or an element name in the web page element as an event object when the web page element does not include the text information.
Optionally, the first invoking unit 45 includes a receiving subunit, a monitoring subunit, an executing subunit, and a first determining subunit; wherein,
the receiving subunit is used for receiving a script test instruction;
the monitoring subunit is configured to enter the test page of the to-be-tested website according to the script test instruction, and start monitoring on the test page;
the execution subunit is configured to execute the current script statement in the test script on the test page to obtain an execution result of the current script statement; the current script statement is an executing script statement in the at least one script statement;
the monitoring subunit is further configured to monitor a page response result of the current script statement when the execution result is successful, where the page response result is a result of the current script statement being executed on the test page;
the first determining subunit is configured to determine a test result of the current script statement according to the page response result and an expected result, where the expected result is a result of the current script statement executed on the recording page;
the execution subunit is further configured to continue to execute a next script statement of the current script statement until the execution of the at least one script statement is completed, so as to obtain a test result of the at least one script statement, and complete an automated test on the test page.
Optionally, the execution subunit includes a first execution subunit and a second execution subunit; wherein,
the first execution subunit is configured to execute the judgment logic statement in the current script statement on the test page, and determine whether an event object in the current script statement exists;
and the second execution subunit is configured to execute the execution logic statement in the current script statement when the event object exists, and determine the execution result with successful characterization.
Optionally, the execution bullet further comprises a third execution subunit; wherein,
and the third execution subunit is configured to, when the event object does not exist, determine the execution result indicating a failure, end the execution of the test script, and perform an alarm.
Optionally, the monitoring subunit includes a first monitoring subunit and a second obtaining subunit; wherein,
the first monitoring subunit is configured to monitor whether an assertion type test event in the current script statement occurs in a current test page when the current script statement is the assertion type script statement, where the current test page is a corresponding web page when the current script statement is executed;
the second obtaining subunit is configured to, when the assertion type test event occurs in the current test page, obtain an actual web page element corresponding to the assertion type test event on the current test page; extracting an actual event object from the actual webpage element according to the current event object in the current script statement; the actual event object has the same attribute as the event object extracted from the webpage element; and the actual event object is the page response result.
Optionally, the first determining subunit comprises a second determining subunit; wherein,
the second determining subunit is configured to determine the test result that is successfully characterized when the page response result is consistent with the expected result.
Optionally, the first determining subunit comprises a third determining subunit; wherein,
the third determining subunit is configured to determine the test result indicating failure when the page response result is inconsistent with the expected result.
Optionally, the test script generating apparatus further includes a determining unit; wherein,
the determining unit is configured to determine the test result with a failed characterization when the assertion type test event does not occur in the current test page.
Optionally, the test script generating apparatus further includes a calling unit; wherein,
the calling unit is used for calling a service implementation script in the recording script so that the recording page responds to the operation information according to the service implementation script.
Optionally, the test script generating apparatus further includes a second invoking unit; wherein,
and the second calling unit is used for calling a service realization script in the test script so that the test page responds to the current script statement according to the service realization script.
It can be understood that, in the embodiment of the present invention, the test script generating device can automatically open the website recording page to be tested to start script recording, and generate the test script by using the text information displayed on the page for positioning and operating elements. Furthermore, when the test script is used for automatic testing, each script statement can be executed only when the last script statement is successfully executed, so that the serious error that the corresponding webpage element cannot be found during the execution of the script statement is avoided, and the stability of the test script is improved.
An embodiment of the present invention provides a test script generating device 5, and fig. 6 is a schematic structural diagram of a test script generating device provided in an embodiment of the present invention, and as shown in fig. 6, the test script generating device 5 includes: a processor 125, a memory 126 and a communication bus 127, the memory 126 being in communication with the processor 125 via the communication bus 127, the memory 126 storing instructions executable by the processor 125, the instructions, when executed, causing the processor 125 to perform any one of the test script generation methods according to the previous embodiments.
Embodiments of the present invention provide a computer-readable storage medium storing executable instructions for causing a processor 125 to execute any one of the test script generation methods according to the foregoing embodiments when the executable instructions are executed. As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention.