A Web Site Automated Testing Method
By using an automated testing platform, leveraging Selenium drivers and Python scripts, the functional testing of websites is automated, solving the problems of low testing efficiency and unstable quality, and improving both testing efficiency and quality.
Patent Information
- Application Number
- CN202111654996.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2041-12-30
AI Technical Summary
Current technologies for testing website functionality are inefficient and the quality varies from person to person. Manual testing is time-consuming and labor-intensive, and writing scripts is difficult, making full automation impossible.
This project uses screenshots to capture web pages for virtual display, and utilizes Selenium drivers and Python scripts to implement click operations and record the operation process. It develops an automated testing platform that automatically generates and executes test scripts.
It automates the functional testing of websites, significantly improving testing efficiency and quality while reducing testing difficulty and the requirements for programming knowledge.
Smart Images

Figure CN114297076B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automated testing of Web sites, and in particular to an automated testing method for Web sites. Background Art
[0002] In the era of the Internet of Things, everything is connected, and the development and application of smart mobile terminals are becoming more and more popular, but this does not mean the end of the Internet era. On the contrary, the Internet of Things can be seen as an extension of the Internet. Therefore, web sites that exist with the Internet still play an indispensable role, and with the continuous advancement of technology, the functional requirements that they can meet are also getting higher and higher. To create an excellent web site, its functions are becoming more and more complex, the interactions are becoming more and more diverse, the performance indicators are becoming more and more stringent, and the development and testing difficulties are great.
[0003] At present, in the field of web testing, there are professional testing tools for performance / security tests, which can be learned and used. For functional testing, manual testing is generally the main method, and then testing frameworks such as selenium are used to assist. The specific process is to perform testing operations manually after completing the test requirements analysis and test case design of the website function. For some important or key modules, testing frameworks such as selenium are deployed, and test scripts are written according to the test case description, and then the scripts are run to implement the test. The above functional testing methods for web sites cannot guarantee the test efficiency and test quality. Only through manual testing, the test efficiency is low, and the test quality varies from person to person; and using the test framework to write test scripts to assist in testing can replace some manual operations, but it cannot achieve full automation, and writing scripts is time-consuming and laborious. It also requires testers to master deep programming knowledge, which is difficult to implement. Therefore, there is an urgent need for a set of convenient and fast automated testing methods to effectively improve the test efficiency and test quality while reducing the difficulty of testing. Summary of the invention
[0004] The purpose of the present invention is to provide a method for automated testing of a Web site in order to solve the above problems. The technical problem to be solved by the present invention is the problem of low test efficiency and test quality when manual testing is used in the functional testing of Web pages. The present invention uses screenshots to obtain Web pages for virtual display, and uses selenium drivers and python scripts to implement click operations, operation process recording and other technical means to achieve key functions such as remote connection, operation and process recording of Web pages. On this basis, an automated testing platform for functional testing of Web pages is developed and implemented. Testers use the automated testing platform to perform click operations according to the test case description, and can automatically generate and execute test scripts, thereby replacing manual testing, realizing the automation of functional testing of web sites, and greatly improving the test efficiency and test quality.
[0005] The present invention solves three difficult problems of virtual display of web pages, click operation and operation process recording, and script conversion and execution. On this basis, a set of automatic testing platform for Web sites is developed, that is, after realizing functions such as display of web site interface, operation of various elements in web pages, operation process recording, and conversion of records into script execution, operation instructions can be sent to the web page, and the web page responds synchronously. In this process, it is judged whether the function of the web page is correctly implemented.
[0006] The key point that the technical solution of the present invention can achieve is to solve the three problems of the test platform for Web site connection, virtual display, click operation and response, among which the connection and click operation are realized through the selenium framework and driver, and secondary development and packaging, and the virtual display function is realized by taking a screenshot to obtain the real Web page and then transmitting the data. On the basis of realizing the above functions, the test platform framework and script execution function are developed to form an automated test platform for Web sites.
[0007] The present invention achieves the above-mentioned purpose through the following technical solutions:
[0008] A method for automated testing of a website, comprising the following steps:
[0009] Step 1: Build the framework of the automated testing platform, including web page display, operation record, script conversion, and script execution functions;
[0010] Step 2, taking a screenshot of the current web page and presenting it in the web page display frame;
[0011] Step 3: Use the browser driver in the Selenium framework to implement click operations on web pages, and record and save the operation process;
[0012] Step 4: Write a python script to parse the saved operation process into step-by-step operation instructions and save it as an execution script;
[0013] Step 5, run the execution script, send operation instructions to the web page, the web page responds, and observe whether the response is correct.
[0014] A further solution is that in step 1, the process of building an automated testing platform framework is as follows:
[0015] The web page is virtualized by taking screenshots and encapsulated in the display control of the test platform for presentation. The whole process is repeated continuously.
[0016] By clicking on the virtual interface of the web page in the test platform, the click coordinates are obtained, and the coordinates of the pointed element are associated with the control ID of the real web page to realize the operation of the web page and the recording of the operation process. The click operation on the web page is realized through the browser driver in the Selenium framework, and the ID of the clicked element is obtained through the coordinate position, and then the web page responds and the operation process is recorded;
[0017] The operation process is parsed into a test script through Python for execution (the test script formed according to the test case can be regarded as a series of operation processes).
[0018] The click operation on the web page is based on the selenium framework. Similarly, different browser drivers should be selected according to different browsers, otherwise the operation will not respond.
[0019] A further solution is that in step 1, a database function is added to save the test script.
[0020] A further solution is that in step 2, the screenshot image data is not saved but only used, and is directly discarded after use, thereby reducing the processing time of the test platform system.
[0021] A further solution is that in step 3, whether the click operation is successful is related to the browser driver in the Selenium framework. When performing web page testing, the corresponding browser driver should be selected for different browsers.
[0022] A further solution is that in step 3, the key point is the correspondence between the click position coordinates and the element ID, and the browser web page interface and the virtual display in the test platform are kept in equal proportion.
[0023] The beneficial effects of the present invention are:
[0024] The present invention provides a method for automated testing of a website, which solves key technical problems such as display, operation, process recording, and script conversion of web pages, and builds an automated testing platform for the website on this basis. The tester uses the testing platform to click and operate according to the test case description, and can automatically generate and execute the test script, thereby realizing the automation of the functional testing of the website, which can replace manual testing and greatly improve the testing efficiency and quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0026] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0027] To make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described in detail below. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other implementation methods obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.
[0028] In any embodiment, if Figure 1 As shown, a method for automated testing of a website of the present invention (this article takes the Chrome browser as an example for introduction) includes:
[0029] Open the browser and enter the address of the website to be tested;
[0030] Open the test platform and configure the browser driver chromeDriver (based on the selenium framework).
[0031] Through the screenshot function, capture the current interface of the web page and save it as image data, and then call the image data in the test platform display control to present it, driver.get_screenshot_as_file(); you can also use other functions and call the display directly in the data stream mode without saving.
[0032] Click, swipe, and perform other operations based on the test case, and the browser web page will respond in real time, and the previous step will be repeated synchronously.
[0033] The test platform records the previous operation process, obtains the element ID to which the operation coordinates belong, and connects the operation steps through connectors. For example, opening a login interface, entering the account and password, and clicking OK can be recorded with a string, loginFrame(idl)&getClientId(id2)&password(id3)&login(id4). If the web page to be tested does not allow the use of sendkey to enter the password, the virtual keyboard can be called to complete it. A mapping table can be established to correspond the element ID to simple characters for subsequent analysis. The string can also be edited, such as adding a delay time, adding the number of clicks, the number of loops, etc.
[0034] The compiled script uses Python to parse the expressions recorded in the above process and form an executable script. The script is as follows:
[0035] Inputs=driver.find_element_by_id("idl"); Inputs.send_keys(keys.ENTER);
[0036] Inputs=driver.find_element_by_id("id2"); Inputs.send_keys(keys.ENTER);
[0037] Inputs=driver.find_element_by_id("id3"); Inputs.send_keys(keys.ENTER);
[0038] Inputs=driver.find_element_by_id("id4"); Inputs.send_keys(keys.ENTER);
[0039] The principle of the script execution process is to call seleniumDriver to perform operations.
[0040] In summary, the web website automation testing platform constructed by the technical method of the present invention allows testers to automatically generate test scripts for parsing and execution through click operations, which significantly reduces the programming ability requirements for testers. Therefore, it can replace manual testing and some testing frameworks, achieve more in-depth automated testing, and ultimately effectively improve testing efficiency and testing quality.
[0041] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, the present invention will not further explain various possible combinations. In addition, the various different embodiments of the present invention can also be combined arbitrarily, as long as they do not violate the concept of the present invention, they should also be regarded as the contents disclosed by the present invention.
Claims
1. A method for automated testing of a website, characterized in that: The following steps are involved: Step 1: Build an automated testing platform framework, including web page display, operation record, script conversion, and script execution functions; in step 1, the process of building an automated testing platform framework is as follows: The web page is virtualized by taking screenshots and encapsulated in the display control of the test platform for presentation. The whole process is repeated continuously. By clicking on the virtual interface of the web page in the test platform, the click coordinates are obtained, and the coordinates of the pointed element are associated with the control ID of the real web page to realize the operation of the web page and the recording of the operation process. The click operation on the web page is realized through the browser driver in the Selenium framework, and the ID of the clicked element is obtained through the coordinate position, and then the web page responds and the operation process is recorded; Parse the operation process into a test script for execution through Python; Step 2, taking a screenshot of the current web page and presenting it in the web page display frame; Step 3: Use the browser driver in the Selenium framework to implement click operations on web pages, and record and save the operation process; In step 3, whether the click operation is successful is related to the browser driver in the Selenium framework. When performing web page testing, the corresponding browser driver should be selected for different browsers. In step 3, the click position coordinates correspond to the element ID, and the browser web page interface and the virtual display in the test platform are kept in the same proportion. Step 4: Write a Python script to parse the saved operation process into step-by-step operation instructions and save it as an execution script; Step 5, run the execution script, send operation instructions to the web page, the web page responds, and observe whether the response is correct.
2. A Web site automated testing method as claimed in claim 1, characterized in that: In the step 1, the test script is saved by adding a database function.
3. A method for automated testing of a website as claimed in claim 1, characterized in that: In step 2, the screenshot image data is not saved but only used, and is directly discarded after use, thereby reducing the processing time of the test platform system.
