Method, device and system for testing code scanning function
By obtaining and transmitting QR code pictures and controlling scanning of the code scanning equipment, the problems of low efficiency and high cost of scanning code testing in the existing technology are solved, and the effect of simplifying the testing process and improving the testing efficiency is achieved.
Patent Information
- Application Number
- CN202510040227.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-05-09
AI Technical Summary
In the prior art, the scanning device automatically scans the code, determines that the scanning code is successful or failed, and multiple terminals scan the code and log in at the same time is inconvenient, and requires manual or robotic operation, resulting in low testing efficiency and high cost.
By obtaining the QR code pictures on the device being tested, transmitting them to the image library of the code scanning device, and controlling the QR code scanning device to load and scan the QR code pictures, and testing the scanning function of the business program based on the scanning results.
Simplifies the scanning code during the test process, reduces the cost and maintenance costs of automated testing, and improves the testing efficiency and reliability.
Smart Images

Figure CN119962549A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of testing technology, and in particular to a method, device and system for testing a code scanning function. Background Art
[0002] In related technologies, a two-dimensional code is also called a two-dimensional barcode, and the most common two-dimensional code is QR Code, QR stands for Quick Response, which is a coding method. A black and white graphic that records data symbol information distributed in a plane (two-dimensional direction) according to a certain geometric pattern.
[0003] Various application software have introduced application scenarios such as scanning code to log in and scanning code to pay, which not only improves the user experience and convenience, but also greatly enhances the security and efficiency of transactions. However, it is not convenient to realize automatic scanning of code by scanning equipment, determine whether the scanning is successful or failed, and scan code to log in at multiple terminals at the same time. It needs to be operated manually or by a robot. Manual scanning cannot meet the automation requirements, and the robot requires a certain cost and cumbersome operation. The accuracy of the scan cannot be guaranteed, resulting in low test efficiency.
[0004] With respect to the above-mentioned problems existing in the related technologies, no efficient and accurate solutions have been found yet. Summary of the invention
[0005] The present invention provides a method, device and system for testing a code scanning function to solve the technical problems in related technologies.
[0006] According to one embodiment of the present invention, a method for testing a code scanning function is provided, which is applied to a test end and includes: obtaining a QR code image to be scanned by a business program on a device under test, wherein the test end is connected between the device under test and the code scanning device, wherein the business program runs on the device under test and the code scanning device at the same time; transmitting the QR code image to a picture library of the code scanning device; controlling the code scanning device to load and scan the QR code image; and testing the code scanning function of the business program according to the scanning result of the code scanning device.
[0007] Optionally, obtaining the QR code image to be scanned by the business program on the device under test includes: loading an automation script, controlling the device under test to display the QR code to be scanned by the business program through the automation script; controlling the device under test to take a screenshot through the automation script to obtain the QR code image; and transmitting the QR code image to the local test end.
[0008] Optionally, transmitting the QR code image to the code scanning device includes: pushing the QR code image to the memory of the code scanning device; controlling the operating system of the code scanning device to send a broadcast message so that the operating system passes the QR code image to the image library of the code scanning device, wherein the broadcast message is used to transmit information between different applications on the same device.
[0009] Optionally, controlling the scanning device to load and scan the QR code image includes: controlling the scanning device to locate the scanning control of the business program; triggering the scanning control, and selecting the image library in the scanning path popped up by the scanning control; controlling the scanning control to select the QR code image from the image library, so that the business program loads and scans the QR code image.
[0010] Optionally, testing the scanning function of the business program according to the scanning result of the scanning device includes: monitoring the display interface of the device under test; determining whether a first prompt message is displayed on the display interface, wherein the first prompt message is used to indicate that the scanning is successful; if the first prompt message is displayed on the display interface, generating a first test result, wherein the first test result is used to indicate that the scanning function of the business program is normal.
[0011] Optionally, after generating the first test result, the method also includes: within a first preset time after generating the first test result, controlling the scanning device to locate the scanning confirmation control of the business program; triggering the scanning confirmation control to monitor the display interface of the device under test; determining whether a second prompt message is displayed on the display interface, wherein the second prompt message is used to indicate that the service is successfully executed; if the second prompt message is displayed on the display interface, generating a second test result, wherein the second test result is used to indicate that the QR code scanning service of the business program is functioning normally.
[0012] Optionally, after generating the first test result, the method also includes: within a second preset time after generating the first test result, controlling the scanning device to locate the scan cancel control of the business program; triggering the scan cancel control, monitoring the display interface of the device under test; determining whether a second prompt message is displayed on the display interface, wherein the second prompt message is used to indicate that the service is successfully executed; if the second prompt message is displayed on the display interface, generating a third test result; if the second prompt message is not displayed on the display interface, generating a fourth test result, wherein the third test result is used to indicate that the cancellation function of the QR code scanning service of the business program is abnormal, and the fourth test result is used to indicate that the cancellation function of the QR code scanning service of the business program is normal.
[0013] Optionally, after generating the first test result, the method also includes: after a preset timeout period after the first test result is generated, controlling the scanning device to locate the scanning confirmation control of the business program; triggering the scanning confirmation control to monitor the display interface of the device under test; determining whether a third prompt message is displayed on the display interface, wherein the third prompt message is used to indicate that the QR code is expired; if the third prompt message is displayed on the display interface, generating a fifth test result, wherein the fifth test result is used to indicate that the timeout function of the QR code scanning service of the business program is normal; if the third prompt message is not displayed on the display interface, generating a sixth test result, wherein the sixth test result is used to indicate that the timeout function of the QR code scanning service of the business program is abnormal.
[0014] According to another embodiment of the present invention, a testing device for a code scanning function is provided, which is applied to a test end and includes: an acquisition module, used to acquire a two-dimensional code image to be scanned by a business program on a tested device, wherein the test end is connected between the tested device and the code scanning device, wherein the business program runs on the tested device and the code scanning device at the same time; a transmission module, used to transmit the two-dimensional code image to a picture library of the code scanning device; a control module, used to control the code scanning device to load and scan the two-dimensional code image; and a test module, used to test the code scanning function of the business program according to the scanning result of the code scanning device.
[0015] Optionally, the acquisition module includes: a control unit, used to load an automation script, and control the device under test to display a QR code to be scanned by the business program through the automation script; a screenshot unit, used to control the device under test to take a screenshot through the automation script to obtain a QR code image; and a transmission unit, used to transmit the QR code image to the local test end.
[0016] Optionally, the transmission module includes: a push unit, used to push the QR code image to the memory of the code scanning device; a control unit, used to control the operating system of the code scanning device to send a broadcast message so that the operating system transfers the QR code image to the image library of the code scanning device, wherein the broadcast message is used to transmit information between different applications of the same device.
[0017] Optionally, the control module includes: a control unit, used to control the scanning device to locate the scanning control of the business program; a selection unit, used to trigger the scanning control and select the image library in the scanning path popped up by the scanning control; and a scanning unit, used to control the scanning control to select the QR code image from the image library, so that the business program loads and scans the QR code image.
[0018] Optionally, the test module includes: a first monitoring unit, used to monitor the display interface of the device under test; a first judgment unit, used to judge whether a first prompt information is displayed on the display interface, wherein the first prompt information is used to indicate that the code scanning is successful; a first generation unit, used to generate a first test result if the first prompt information is displayed on the display interface, wherein the first test result is used to indicate that the scanning function of the business program is normal.
[0019] Optionally, the test module also includes: a first control unit, used to control the scanning device to locate the scanning confirmation control of the business program within a first preset time after the first test result is generated; a second monitoring unit, used to trigger the scanning confirmation control and monitor the display interface of the device under test; a second judgment unit, used to judge whether a second prompt information is displayed on the display interface, wherein the second prompt information is used to indicate that the service is successfully executed; a second generation unit, used to generate a second test result if the second prompt information is displayed on the display interface, wherein the second test result is used to indicate that the QR code scanning service of the business program is functioning normally.
[0020] Optionally, the test module also includes: a second control unit, used to control the scanning device to locate the scan cancel control of the business program within a second preset time after generating the first test result; a third monitoring unit, used to trigger the scan cancel control and monitor the display interface of the device under test; a third judgment unit, used to judge whether a second prompt information is displayed on the display interface, wherein the second prompt information is used to indicate that the service is successfully executed; a third generation unit, used to generate a third test result if the second prompt information is displayed on the display interface; and to generate a fourth test result if the second prompt information is not displayed on the display interface, wherein the third test result is used to indicate that the cancellation function of the QR code scanning service of the business program is abnormal, and the fourth test result is used to indicate that the cancellation function of the QR code scanning service of the business program is normal.
[0021] Optionally, the test module also includes: a third control unit, used to control the scanning device to locate the scanning confirmation control of the business program after a preset timeout period after the first test result is generated; a fourth monitoring unit, used to trigger the scanning confirmation control and monitor the display interface of the device under test; a fourth judgment unit, used to judge whether a third prompt message is displayed on the display interface, wherein the third prompt message is used to indicate that the QR code is expired; a fourth generation unit, used to generate a fifth test result if the third prompt message is displayed on the display interface, wherein the fifth test result is used to indicate that the timeout function of the QR code scanning service of the business program is normal; if the third prompt message is not displayed on the display interface, a sixth test result is generated, wherein the sixth test result is used to indicate that the timeout function of the QR code scanning service of the business program is abnormal.
[0022] According to another aspect of an embodiment of the present application, a storage medium is further provided, which includes a stored program, and the above steps are executed when the program is run.
[0023] According to another aspect of an embodiment of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein: the memory is used to store computer programs; and the processor is used to execute the steps in the above method by running the program stored in the memory.
[0024] The embodiment of the present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the steps in the above method.
[0025] Beneficial effects of the present invention:
[0026] 1. The code scanning method provided by the present invention simplifies the code scanning action during the test process, and does not require an external device to control the code scanning device to perform physical code scanning, thereby reducing the cost and maintenance cost of automated testing;
[0027] 2. Scanning the QR code by directly taking a screenshot ensures the accuracy of the QR code and improves test efficiency and reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0029] Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present invention;
[0030] Figure 2is a flow chart of a method for testing a code scanning function according to an embodiment of the present invention;
[0031] Figure 3 is a device connection topology diagram in an embodiment of the present invention;
[0032] Figure 4 is a network structure diagram of an embodiment of the present invention;
[0033] Figure 5 It is a complete implementation flow chart of an embodiment of the present invention;
[0034] Figure 6 It is a structural block diagram of a testing device for a code scanning function according to an embodiment of the present invention. DETAILED DESCRIPTION
[0035] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0036] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0037] Example 1
[0038] The method embodiment provided in the first embodiment of the present application can be executed in a host device, a computer, a test terminal or a similar processing device. Taking running on a computer as an example, Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present invention. Figure 1 As shown, the server may include one or more ( Figure 1Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Optionally, the server may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0039] The memory 104 can be used to store server programs, for example, software programs and modules of application software, such as a server program corresponding to a remote control method of a computer in an embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the server program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0040] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0041] In this embodiment, a method for testing a code scanning function is provided. Figure 2 is a flow chart of a method for testing a code scanning function according to an embodiment of the present invention, which is applied to a test terminal, such as Figure 2 As shown, the process includes the following steps:
[0042] Step S202, obtaining a QR code image to be scanned by the business program on the device under test, wherein the test end is connected between the device under test and the code scanning device, wherein the business program runs on the device under test and the code scanning device at the same time;
[0043] The business program of this embodiment may be an operating system, functional software (such as music software, navigation software, payment software, video software, etc.).
[0044] The test end is connected to the device under test and the code scanning device via wired or wireless connections, and obtains control permissions of the device under test and the code scanning device in advance. This embodiment is described by taking the test end as a PC, the device under test as a vehicle-mounted central control terminal, and the code scanning device as a mobile phone as an example.
[0045] Figure 3 This is the device connection topology diagram in the embodiment of the present invention. The test end is the PC end, and the device under test is the vehicle-mounted central control end. The PC end is connected to the vehicle-mounted central control end and the code scanning device through a USB data cable, and the ADB (Android Debug Bridge) software tool is used to control the operation behavior of the mobile phone and the vehicle-mounted central control end. Install Appium, ADB tools, the business program APP to be tested, and the screen projection software on the PC, connect the device under test and the code scanning device to the PC through a USB data cable, and enable the USB debugging mode. You can use the screen projection software on the PC to project the screen of the device under test and the code scanning device to the PC.
[0046] Step S204, transmitting the QR code image to the image library of the code scanning device;
[0047] Step S206, controlling the code scanning device to load and scan the QR code image;
[0048] Step S208, testing the scanning function of the business program according to the scanning result of the scanning device.
[0049] Through the above steps, a QR code image to be scanned by the business program on the device under test is obtained, wherein the test end is connected between the device under test and the code scanning device, wherein the business program runs on the device under test and the code scanning device at the same time; the QR code image is transmitted to the image library of the code scanning device; the code scanning device is controlled to load and scan the QR code image; the code scanning function of the business program is tested according to the scanning result of the code scanning device, and the QR code image of the device under test is obtained by automated means and transmitted to the code scanning device, and the code scanning function of the business program is automatically tested based on the scanning result of the code scanning device, which solves the technical problem of low efficiency in testing the QR code scanning function in the related technology and improves the test efficiency and test reliability.
[0050] In one implementation of this embodiment, obtaining a QR code image to be scanned by a business program on a device under test includes: loading an automation script, controlling the device under test to display a QR code to be scanned by a business program through the automation script; controlling the device under test to take a screenshot through the automation script to obtain a QR code image; and transmitting the QR code image to the local test end.
[0051] By loading and running the automation script, the device under test is controlled to open the QR code that needs to be scanned, and control instructions are sent to the device under test through the host computer to control the device under test to take a screenshot and save the QR code screenshot to the local folder of the test end.
[0052] Optionally, transmitting the QR code image to the code scanning device includes: pushing the QR code image to the memory of the code scanning device; controlling the operating system of the code scanning device to send a broadcast message so that the operating system passes the QR code image to the image library of the code scanning device, wherein the broadcast message is used to transmit information between different applications on the same device.
[0053] Optionally, the image library of the code scanning device can be cleared in advance, and then the QR code image can be transferred to the image library of the code scanning device. When the code scanning device opens the image library during subsequent scanning, it can directly select and choose the QR code image to avoid wrong selection.
[0054] Take a screenshot of the QR code and save it to the PC, then push the screenshot to the scanning device through the ADB command, notify the broadcast mechanism of the Android system, and save the image to the gallery of the scanning device (such as a mobile phone). The test end sends a broadcast command to the scanning device, and after receiving the broadcast command, the scanning device generates and sends a broadcast message.
[0055] Optionally, controlling the scanning device to load and scan the QR code image includes: controlling the scanning device to locate the scanning control of the business program; triggering the scanning control, and selecting the image library in the scanning path popped up by the scanning control; controlling the scanning control to select the QR code image from the image library, so that the business program loads and scans the QR code image.
[0056] Optionally, the scanning control is a button with "Scan", "Scan Code" or similar functions on the business program. The scanning control is located and triggered (simulating the user's click operation) through an automated script. The scanning control detects the QR code and scans the code. The scanning path can be an image captured by the camera in real time or a QR code image in the local image library. The scanning device is controlled to open the scanning APP corresponding to the QR code, and the local image is called for scanning by loading the album photos.
[0057] You can use Appium's UI automation testing framework to click the "Scan QR code" element in the mobile app, and then click the "Scan" button. At this time, the "Can be selected from the gallery" pops up. Select "Select from gallery" and then select a screenshot of the QR code.
[0058] During the test process, the test end runs the test cases. In different test scenarios, the host computer asserts the scanning results of the device under test, gives the test results, and completes the fully automatic test of the APP scanning function.
[0059] In a test scenario of the present embodiment, testing the scanning function of the business program according to the scanning result of the scanning device includes: monitoring the display interface of the device under test; determining whether a first prompt message is displayed on the display interface, wherein the first prompt message is used to indicate that the scanning is successful; if the first prompt message is displayed on the display interface, generating a first test result, wherein the first test result is used to indicate that the scanning function of the business program is normal.
[0060] During the process of scanning the QR code with a mobile phone, the test script asserts whether the first prompt message "Scanning successfully" appears on the QR code on the screen of the device under test. If so, the output test result is that the scanning is successful, confirming that the scanning function of the business program is normal. If not, the mobile phone clicks the "Scan" button again and repeats the steps.
[0061] In a test scenario of the present embodiment, after generating a first test result, it also includes: within a first preset time after generating the first test result, controlling the scanning device to locate the scanning confirmation control of the business program; triggering the scanning confirmation control to monitor the display interface of the device under test; determining whether a second prompt information is displayed on the display interface, wherein the second prompt information is used to indicate that the service is successfully executed; if the second prompt information is displayed on the display interface, generating a second test result, wherein the second test result is used to indicate that the function of the QR code scanning service of the business program is normal.
[0062] Optionally, the QR code scanning service of the business program can implement various interactive services through QR code scanning operations, such as login service, file transfer service, transfer service, registration service, verification service, friend adding service, etc.
[0063] Taking the QR code scanning login service as an example, the words "Scan code successful" appear on the QR code on the screen of the device under test. The mobile phone clicks the "Confirm" button within 3 minutes. At this time, the test script asserts whether the words "Login successful" appear on the QR code on the screen of the device under test. If so, the output test result is that the password-free login is successful and the QR code scanning login function is normal; if the second prompt message of "Login successful" does not appear, a test result indicating that the QR code scanning login function is abnormal is generated.
[0064] In a test scenario of the present embodiment, after generating a first test result, the method also includes: within a second preset time after generating the first test result, controlling the scanning device to locate the scan cancel control of the business program; triggering the scan cancel control, monitoring the display interface of the device under test; determining whether a second prompt message is displayed on the display interface, wherein the second prompt message is used to indicate that the service is successfully executed; if the second prompt message is displayed on the display interface, generating a third test result; if the second prompt message is not displayed on the display interface, generating a fourth test result, wherein the third test result is used to indicate that the cancellation function of the QR code scanning service of the business program is abnormal, and the fourth test result is used to indicate that the cancellation function of the QR code scanning service of the business program is normal.
[0065] Let's take the scanning service as the scanning login service as an example. The QR code on the screen of the device under test shows the words "Scanning successful". The mobile phone clicks the "Cancel" button within 3 minutes. At this time, the test script asserts whether the QR code on the screen of the device under test still shows the words "Login successful". If so, the output test result is scanning login cancellation exception, that is, the cancellation function of the QR code scanning service is abnormal; if not, the output test result is scanning login cancellation failure, the cancellation function of the QR code scanning service is normal, and the test passes.
[0066] In a test scenario of the present embodiment, after generating the first test result, it also includes: after a preset timeout period after generating the first test result, controlling the scanning device to locate the scanning confirmation control of the business program; triggering the scanning confirmation control to monitor the display interface of the device under test; determining whether a third prompt message is displayed on the display interface, wherein the third prompt message is used to indicate that the QR code is expired; if the third prompt message is displayed on the display interface, generating a fifth test result, wherein the fifth test result is used to indicate that the timeout function of the QR code scanning service of the business program is normal; if the third prompt message is not displayed on the display interface, generating a sixth test result, wherein the sixth test result is used to indicate that the timeout function of the QR code scanning service of the business program is abnormal.
[0067] In one example, when generating the sixth test result, it is also determined whether the second prompt information is displayed on the display interface. If the third prompt information is not displayed on the display interface and the second prompt information is displayed, the sixth test result is generated. Displaying the second prompt information indicates that the QR code screenshot can continue to be used even after the timeout, which is a timeout function abnormality.
[0068] In this embodiment, the preset timeout period corresponds to the validity period of the QR code image. For example, if the preset timeout period is 3 minutes, it means that the QR code image is valid within 3 minutes after the initial generation or refresh. If it exceeds 3 minutes, the service corresponding to the QR code image will become invalid and the QR code needs to be refreshed to ensure the security and timeliness of the QR code.
[0069] Still taking the scanning service as the scanning login service as an example, the QR code on the screen of the device under test shows the words "Scanning successful". After 3 minutes, the mobile phone clicks "Confirm". At this time, the test script asserts whether the QR code on the screen of the device under test shows the words "QR code expired". If so, the timeout function of the QR code scanning service is normal, and the QR code can be refreshed to restart the process. If not, scan the code again. If the login is successful after refreshing for 3 minutes, the test result is output that the scanning login timeout failed, and the timeout function of the QR code scanning service is abnormal.
[0070] Figure 4 : This is a network structure diagram of an embodiment of the present invention, including: device layer, middleware layer, and application layer. The device layer includes various hardware devices, such as test terminals, code scanning devices, communication lines, etc., and completes the physical connection between PC, device under test, and code scanning device through USB data cables. The middleware layer includes various tool software running on the device layer, including ADB, WebDriver, automator2, and AppiumAPI. ADB is a tool in the android sdk, which can be used to directly operate and manage real android devices. WebDriver, automator2, and AppiumAPI provide a standard interface for automated testing and browser control, simulating real user operations to interact with APP or browsers. The application layer includes various software. PC acts as the Appium Server server to execute test scripts, and the device under test and the code scanning device act as the Appium Clenit client to execute the actions specified in the test script. The screen projection software mainly projects the screen of the device under test and the code scanning device to the PC to facilitate the positioning of UI elements.
[0071] This solution provides an automated testing method for APP scan code login scenarios. It uses the ADB tool to achieve communication connections between the device under test, PC, and mobile terminal scan code device, and completes the operation of sending the screenshot file of the login QR code of the device under test to the mobile device. Through Appium's UI automated testing framework, it can accurately locate the UI elements of the APP such as "Scan code login", "Scan", "Confirm", "Cancel", "QR code", etc., and obtain the text information of the UI elements, and complete the APP's click, slide, interaction, and monitoring of the QR code status. Figure 5 It is a complete implementation flow chart of an embodiment of the present invention, including:
[0072] Step (1) Install Appium, ADB tools, the APP to be tested, and the screen projection software on the PC, connect the device to be tested and the code scanning device to the PC via a USB data cable, and enable USB debugging mode.
[0073] Step (2) Use the screen projection software on the PC to project the screen of the device under test and the QR code scanning device onto the PC.
[0074] Step (3) Execute the test script on the PC. Steps (3) to (7) are all implemented by code without manual intervention. Check the connection status of the scanning device and the device under test. After the connection is normal, the two devices respectively start the APP to be tested.
[0075] Step (4) After waiting for 3 seconds, the device under test takes a screenshot of the QR code and saves it to the PC. It then executes the ADB command to push the screenshot to the scanning device and notifies the broadcast mechanism of the Android system to save the image to the gallery of the scanning device's mobile phone.
[0076] Step (5) Using Appium's UI automation testing framework, click the "Scan code to log in" element in the mobile app, and then click the "Scan" button. A "Can be selected from gallery" pops up. Select "Can be selected from gallery" and then select a screenshot of the QR code.
[0077] Step (6) Situation 1: During the QR code scanning process, the test script asserts whether the words "Scan successful" appear on the QR code on the screen of the device under test. If yes, the test result "Scan successful" is output. If not, the mobile phone clicks the "Scan" button again and repeats the steps.
[0078] Case 2: The QR code on the screen of the device under test shows the words "Scan code successful". The phone clicks the "Confirm" button within 5 minutes. At this time, the test script asserts whether the QR code on the screen of the device under test shows the words "Login successful". If yes, the test result is output: password-free login is successful.
[0079] Case 3: The words "Scan code successful" appear on the QR code on the screen of the device under test. The mobile phone clicks the "Cancel" button within 3 minutes. At this time, the test script asserts whether the words "Login successful" appear on the QR code on the screen of the device under test. If yes, the test result is output: Scan code login cancellation exception; No, the test result is output: Scan code login cancellation success.
[0080] Case 4: The QR code on the screen of the device under test shows the words "Scan successful". After 5 minutes, the mobile phone clicks "Confirm". At this time, the test script asserts whether the QR code on the screen of the device under test shows the words "QR code expired". If so, refresh the QR code and restart the process. If not, scan the code again. If the login is not successful after 5 minutes, the test result "Scan login timeout failure" is output.
[0081] After all the test cases in the test script in step (7) are executed, the results of all the test situations that occurred in step (6) are summarized and output.
[0082] The solution of this embodiment is adopted, and the scanning method based on the automated script makes it easier to automate the action of scanning the APP during the test. Scanning the code by directly taking a screenshot ensures the accuracy of the QR code, improving the test efficiency and reliability. No external device is required to control the scanning device to perform physical scanning, which reduces the cost and maintenance cost of automated testing. It can be applied to a variety of scanning test scenarios such as product or service information query, application login or verification, event registration or application, and various payment services.
[0083] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0084] Example 2
[0085] In this embodiment, a test device for a code scanning function is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and will not be repeated here. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0086] Figure 6 is a structural block diagram of a test device for a code scanning function according to an embodiment of the present invention, which is applied to a test terminal, such as Figure 6 As shown, the device comprises:
[0087] The acquisition module 60 is used to acquire a QR code image to be scanned by the business program on the device under test, wherein the test end is connected between the device under test and the code scanning device, and wherein the business program runs on the device under test and the code scanning device at the same time;
[0088] A transmission module 62, used for transmitting the two-dimensional code image to the image library of the code scanning device;
[0089] A control module 64, used to control the code scanning device to load and scan the QR code image;
[0090] The testing module 66 is used to test the scanning function of the business program according to the scanning result of the scanning device.
[0091] Optionally, the acquisition module includes: a control unit, used to load an automation script, and control the device under test to display a QR code to be scanned by the business program through the automation script; a screenshot unit, used to control the device under test to take a screenshot through the automation script to obtain a QR code image; and a transmission unit, used to transmit the QR code image to the local test end.
[0092] Optionally, the transmission module includes: a push unit, used to push the QR code image to the memory of the code scanning device; a control unit, used to control the operating system of the code scanning device to send a broadcast message so that the operating system transfers the QR code image to the image library of the code scanning device, wherein the broadcast message is used to transmit information between different applications of the same device.
[0093] Optionally, the control module includes: a control unit, used to control the scanning device to locate the scanning control of the business program; a selection unit, used to trigger the scanning control and select the image library in the scanning path popped up by the scanning control; and a scanning unit, used to control the scanning control to select the QR code image from the image library, so that the business program loads and scans the QR code image.
[0094] Optionally, the test module includes: a first monitoring unit, used to monitor the display interface of the device under test; a first judgment unit, used to judge whether a first prompt information is displayed on the display interface, wherein the first prompt information is used to indicate that the code scanning is successful; a first generation unit, used to generate a first test result if the first prompt information is displayed on the display interface, wherein the first test result is used to indicate that the scanning function of the business program is normal.
[0095] Optionally, the test module also includes: a first control unit, used to control the scanning device to locate the scanning confirmation control of the business program within a first preset time after the first test result is generated; a second monitoring unit, used to trigger the scanning confirmation control and monitor the display interface of the device under test; a second judgment unit, used to judge whether a second prompt information is displayed on the display interface, wherein the second prompt information is used to indicate that the service is successfully executed; a second generation unit, used to generate a second test result if the second prompt information is displayed on the display interface, wherein the second test result is used to indicate that the QR code scanning service of the business program is functioning normally.
[0096] Optionally, the test module also includes: a second control unit, used to control the scanning device to locate the scan cancel control of the business program within a second preset time after generating the first test result; a third monitoring unit, used to trigger the scan cancel control and monitor the display interface of the device under test; a third judgment unit, used to judge whether a second prompt information is displayed on the display interface, wherein the second prompt information is used to indicate that the service is successfully executed; a third generation unit, used to generate a third test result if the second prompt information is displayed on the display interface; and to generate a fourth test result if the second prompt information is not displayed on the display interface, wherein the third test result is used to indicate that the cancellation function of the QR code scanning service of the business program is abnormal, and the fourth test result is used to indicate that the cancellation function of the QR code scanning service of the business program is normal.
[0097] Optionally, the test module also includes: a third control unit, used to control the scanning device to locate the scanning confirmation control of the business program after a preset timeout period after the first test result is generated; a fourth monitoring unit, used to trigger the scanning confirmation control and monitor the display interface of the device under test; a fourth judgment unit, used to judge whether a third prompt message is displayed on the display interface, wherein the third prompt message is used to indicate that the QR code is expired; a fourth generation unit, used to generate a fifth test result if the third prompt message is displayed on the display interface, wherein the fifth test result is used to indicate that the timeout function of the QR code scanning service of the business program is normal; if the third prompt message is not displayed on the display interface, a sixth test result is generated, wherein the sixth test result is used to indicate that the timeout function of the QR code scanning service of the business program is abnormal.
[0098] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0099] Example 3
[0100] An embodiment of the present invention further provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0101] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0102] S1, obtaining a QR code image to be scanned by a business program on a device under test, wherein the test end is connected between the device under test and a code scanning device, and wherein the business program runs on both the device under test and the code scanning device;
[0103] S2, transmitting the QR code image to the image library of the code scanning device;
[0104] S3, controlling the code scanning device to load and scan the QR code image;
[0105] S4, testing the scanning function of the business program according to the scanning result of the scanning device.
[0106] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
[0107] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0108] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0109] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0110] S1, obtaining a QR code image to be scanned by a business program on a device under test, wherein the test end is connected between the device under test and a code scanning device, and wherein the business program runs on both the device under test and the code scanning device;
[0111] S2, transmitting the QR code image to the image library of the code scanning device;
[0112] S3, controlling the code scanning device to load and scan the QR code image;
[0113] S4, testing the scanning function of the business program according to the scanning result of the scanning device.
[0114] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0115] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0116] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0117] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0118] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for testing a code scanning function, characterized in that: Application on the test side includes: Obtaining a QR code image to be scanned by a business program on a device under test, wherein the test end is connected between the device under test and a code scanning device, and wherein the business program runs on both the device under test and the code scanning device at the same time; Transmitting the QR code image to the image library of the code scanning device; Control the code scanning device to load and scan the QR code image; The scanning function of the business program is tested according to the scanning result of the scanning device.
2. The method according to claim 1, characterized in that Obtaining the QR code image to be scanned by the business program on the device under test includes: Loading an automation script, and controlling the device under test to display a QR code to be scanned by a business program through the automation script; Controlling the device under test to take a screenshot through the automation script to obtain a QR code image; The two-dimensional code image is transmitted to the local test end.
3. The method according to claim 1, characterized in that Transmitting the two-dimensional code image to the code scanning device includes: Pushing the QR code image to the memory of the code scanning device; The operating system of the code scanning device is controlled to send a broadcast message so that the operating system transfers the two-dimensional code image to the image library of the code scanning device, wherein the broadcast message is used to transfer information between different applications of the same device.
4. The method according to claim 1, characterized in that: Controlling the code scanning device to load and scan the QR code image includes: Control the code scanning device to locate the scanning control of the business program; Trigger the scanning control, and select the picture library in the scanning path popped up by the scanning control; The scanning control is controlled to select the two-dimensional code image from the image library, so that the business program loads and scans the two-dimensional code image.
5. The method according to claim 1, characterized in that Testing the scanning function of the business program according to the scanning result of the scanning device includes: Monitoring the display interface of the device under test; Determine whether first prompt information is displayed on the display interface, wherein the first prompt information is used to indicate that the code scanning is successful; If the first prompt information is displayed on the display interface, a first test result is generated, wherein the first test result is used to indicate that the scanning function of the business program is normal.
6. The method according to claim 5, characterized in that After generating the first test result, the method further includes: Within a first preset time after the first test result is generated, controlling the code scanning device to locate the scan confirmation control of the business program; Triggering the scan confirmation control to monitor the display interface of the device under test; Determining whether second prompt information is displayed on the display interface, wherein the second prompt information is used to indicate that the service is successfully executed; If the second prompt information is displayed on the display interface, a second test result is generated, wherein the second test result is used to indicate that the function of the QR code scanning service of the business program is normal.
7. The method according to claim 5, characterized in that After generating the first test result, the method further includes: Within a second preset time after the first test result is generated, controlling the code scanning device to locate a scan cancel control of the business program; Triggering the scan cancel control to monitor the display interface of the device under test; Determining whether second prompt information is displayed on the display interface, wherein the second prompt information is used to indicate that the service is successfully executed; If the second prompt information is displayed on the display interface, a third test result is generated; if the second prompt information is not displayed on the display interface, a fourth test result is generated, wherein the third test result is used to characterize that the cancellation function of the QR code scanning service of the business program is abnormal, and the fourth test result is used to characterize that the cancellation function of the QR code scanning service of the business program is normal.
8. The method according to claim 5, characterized in that After generating the first test result, the method further includes: After a preset timeout period after the first test result is generated, controlling the code scanning device to locate the scan confirmation control of the business program; Triggering the scan confirmation control to monitor the display interface of the device under test; Determining whether third prompt information is displayed on the display interface, wherein the third prompt information is used to indicate that the QR code is expired; If the third prompt information is displayed on the display interface, a fifth test result is generated, wherein the fifth test result is used to characterize that the timeout function of the QR code scanning service of the business program is normal; if the third prompt information is not displayed on the display interface, a sixth test result is generated, wherein the sixth test result is used to characterize that the timeout function of the QR code scanning service of the business program is abnormal.
9. A device for testing a code scanning function, characterized in that: Application on the test side includes: An acquisition module, used for acquiring a QR code image to be scanned by a business program on a device under test, wherein the test end is connected between the device under test and a code scanning device, wherein the business program runs on both the device under test and the code scanning device at the same time; A transmission module, used for transmitting the QR code image to the image library of the code scanning device; A control module, used to control the code scanning device to load and scan the QR code image; The testing module is used to test the scanning function of the business program according to the scanning result of the scanning device.
10. A code scanning function testing system, characterized in that: include: A test end, a device under test and a code scanning device, wherein the test end is connected between the device under test and the code scanning device, and the test end comprises the apparatus as claimed in claim 9.
Citation Information
Cited By
Debugging tool interaction control method, device and equipment of wireless intelligent equipment
CN120640339A