Test case execution method and device, storage medium and electronic device
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- QINGDAO HAIER TECH
- Filing Date
- 2022-05-27
- Publication Date
- 2026-07-24
AI Technical Summary
[0004]本申请实施例提供了一种测试用例的执行方法和装置、存储介质及电子装置,以至少解决相关技术中存在的自动化测试效率较低的问题
[0017]根据本申请实施例的又一个实施例,还提供了一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为通过所述计算机程序执行上述任一项方法实施例中的步骤。
Smart Images

Figure CN115033475B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of smart home technology, and more specifically, to a method and apparatus for executing test cases, a storage medium, and an electronic device. Background Technology
[0002] In web / app automated testing, testers typically use pre-packaged keywords from web automation platforms. These platforms usually encapsulate commonly used keywords for element manipulation or assertion verification, such as `click`, `input`, `switchFrame`, and `select`. However, some web projects require additional keywords or require further development and encapsulation of commonly used keywords. This special case introduces uncertainty. If integrated into the project through packaging and compilation, it can affect the stability of the automation platform and lead to frequent deployments, resulting in low efficiency in automated testing.
[0003] There is currently no effective solution to the problem of low efficiency in automated testing in related technologies. Summary of the Invention
[0004] This application provides a method and apparatus for executing test cases, a storage medium, and an electronic device to at least solve the problem of low efficiency in automated testing in related technologies.
[0005] According to one embodiment of this application, a method for executing test cases is provided, comprising: receiving a target test case issued by a target platform, wherein the target test case includes test steps; sequentially executing one or more sub-steps included in the test steps until each step included in the test steps is executed, wherein for any target sub-step included in the test steps, the following predetermined operation is performed: if it is determined that the target sub-step includes a target keyword, sending a query instruction to the target platform to query the target code of the target keyword, wherein the target keyword is used to indicate a newly added keyword; receiving the target code returned by the target platform; executing the target sub-step based on the target code; and executing the target sub-step if it is determined that the target sub-step does not include the target keyword.
[0006] In an exemplary embodiment, executing the target sub-step based on the target code includes: generating a target usage method for the target keyword corresponding to the target code through a Java reflection mechanism; and invoking the target usage method to execute the target operation included in the target sub-step.
[0007] In one exemplary embodiment, invoking the target usage method to perform the target operation included in the target sub-step includes: invoking the target usage method to perform element operations and / or assertion verifications included in the target sub-step.
[0008] In one exemplary embodiment, before performing a predetermined operation, the method further includes: parsing a first keyword included in the target sub-step; comparing the first keyword with a local keyword library to obtain a comparison result; if the comparison result indicates that the local keyword library does not include the first keyword, determining that the first keyword is the target keyword, and determining that the target sub-step includes the target keyword; if the comparison result indicates that the local keyword library includes the first keyword, determining that the first keyword is a non-target keyword, and determining that the target sub-step does not include the target keyword.
[0009] In one exemplary embodiment, the method further includes: after executing the target sub-step, obtaining the actual test result of the target sub-step.
[0010] In one exemplary embodiment, after obtaining the actual test results, the method further includes: comparing the actual test results with the expected test results to obtain a target test result, wherein the test step includes the expected test results; and returning the target test results to the target platform to instruct the target platform to generate a test report.
[0011] According to another embodiment of the present application, a method for executing test cases is provided, comprising: upon receiving a target execution instruction, issuing a target test case to a target execution machine, wherein the target test case includes test steps to instruct the target execution machine to execute one or more sub-steps included in the test steps in sequence until each step included in the test steps is executed; receiving a query instruction sent by the target execution machine, wherein the query instruction is sent by the target execution machine upon determining that a target sub-step includes a target keyword, and the target sub-step is any step included in the test steps; returning the target code of the target keyword to the target execution machine based on the query instruction, and instructing the target execution machine to execute the target sub-step based on the target code.
[0012] In one exemplary embodiment, the method further includes: receiving target test results sent by the target executor, wherein the target test results are obtained by the target executor after executing the target test cases; and generating a test report based on the target test results.
[0013] In one exemplary embodiment, before issuing target test cases to the target executor, the method further includes: receiving the target test cases written by the target object, wherein the target test cases include the target keywords; and storing the target test cases in a target database, wherein the target database includes target code for the pre-written and stored target keywords.
[0014] According to another embodiment of the present application, a test case execution apparatus is also provided, comprising: a first receiving module, configured to receive a target test case issued by a target platform, wherein the target test case includes test steps; and an execution module, configured to execute one or more sub-steps included in the test steps in sequence until each step included in the test steps is executed, wherein for any target sub-step included in the test steps, the following predetermined operations are performed: if it is determined that the target sub-step includes a target keyword, a query instruction is sent to the target platform to query the target code of the target keyword, wherein the target keyword is used to indicate a newly added keyword; the target code returned by the target platform is received; the target sub-step is executed based on the target code; and the target sub-step is executed if it is determined that the target sub-step does not include the target keyword.
[0015] According to another embodiment of the present application, a test case execution device is also provided, comprising: a issuing module, configured to issue a target test case to a target execution machine upon receiving a target execution instruction, wherein the target test case includes test steps to instruct the target execution machine to execute one or more sub-steps included in the test steps in sequence until each step included in the test steps is executed; a second receiving module, configured to receive a query instruction sent by the target execution machine, wherein the query instruction is sent by the target execution machine upon determining that a target sub-step includes a target keyword, and the target sub-step is any step included in the test steps; and a processing module, configured to return the target code of the target keyword to the target execution machine based on the query instruction, and instruct the target execution machine to execute the target sub-step based on the target code.
[0016] According to yet another embodiment of the present application, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein the program, when executed, performs the steps in any of the above method embodiments.
[0017] According to yet another embodiment of the present application, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to perform the steps of any of the above method embodiments through the computer program.
[0018] Through this invention, by receiving target test cases issued by the target platform, each sub-step included in the test steps is executed sequentially according to the test steps included in the target test cases until all steps in the test steps are executed. For any target sub-step included in the test steps, the following predetermined operation is performed: when it is determined that the target sub-step includes a newly added target keyword, a query instruction is sent to the target platform to query the target code of the target keyword, and then the target code returned by the target platform is received. Then, the target sub-step is executed based on the target code. When it is determined that the target sub-step does not include a newly added target keyword, the target sub-step is executed directly. Each step of the test case is executed sequentially. This invention allows for the pre-defined keywords on the target platform, such as the target keywords mentioned above. Code for these custom keywords is written, and during the execution of the target test cases, if a custom keyword is encountered, the corresponding target code can be obtained by querying the target platform. Then, the target sub-steps are executed based on the target code, and so on, until all sub-steps in the test steps are completed to finish the target test case execution. This avoids the problem in related technologies where adding keywords or test items to test cases requires upgrading and updating the execution machine for the target test cases. It also avoids the problem in related technologies where integrating the test case into the project through packaging and compilation can easily affect the stability of the automation platform and lead to frequent deployments, resulting in low automation testing efficiency. This invention solves the problem of low automation testing efficiency in related technologies and achieves the effect of improving automation testing efficiency. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a schematic diagram of the hardware environment for an interaction method of a smart home device according to an embodiment of this application;
[0022] Figure 2This is a flowchart of a test case execution method according to an embodiment of this application;
[0023] Figure 3 This is a flowchart of another test case execution method according to an embodiment of this application;
[0024] Figure 4 This is a flowchart of an automated test according to a specific embodiment of this application;
[0025] Figure 5 This is a structural block diagram of a test case execution device according to an embodiment of this application;
[0026] Figure 6 This is a structural block diagram of an execution device for another test case according to an embodiment of this application. Detailed Implementation
[0027] 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 with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0028] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0029] According to one aspect of the embodiments of this application, an interaction method for smart home devices is provided. This interaction method for smart home devices is widely applicable to whole-house intelligent digital control application scenarios such as smart homes, smart home ecosystems, and intelligence house ecosystems. Optionally, in this embodiment, the above-mentioned interaction method for smart home devices can be applied to, for example... Figure 1 The hardware environment shown consists of terminal device 102 and server 104. For example... Figure 1As shown, server 104 is connected to terminal device 102 via a network and can be used to provide services (such as application services) to the terminal or clients installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server to provide data processing services for server 104.
[0030] The aforementioned network may include, but is not limited to, at least one of the following: wired network, wireless network. The aforementioned wired network may include, but is not limited to, at least one of the following: wide area network, metropolitan area network, local area network. The aforementioned wireless network may include, but is not limited to, at least one of the following: Wi-Fi (Wireless Fidelity), Bluetooth. The terminal device 102 may not be limited to PC, mobile phone, tablet computer, smart air conditioner, smart range hood, smart refrigerator, smart oven, smart stove, smart washing machine, smart water heater, smart washing equipment, smart dishwasher, smart projector, smart TV, smart clothes rack, smart curtains, smart audio-visual equipment, smart socket, smart speaker, smart speaker box, smart fresh air equipment, smart kitchen and bathroom equipment, smart bathroom equipment, smart robot vacuum cleaner, smart window cleaning robot, smart mopping robot, smart air purifier, smart steam oven, smart microwave oven, smart water heater, smart air purifier, smart water dispenser, smart door lock, etc.
[0031] This embodiment provides a method for executing test cases. Figure 2 This is a flowchart of a test case execution method according to an embodiment of this application, such as... Figure 2 As shown, the process includes the following steps:
[0032] Step S202: Receive target test cases issued by the target platform, wherein the target test cases contain test steps;
[0033] Step S204: Execute one or more sub-steps included in the test step sequentially until each step in the test step is completed. For any target sub-step included in the test step, perform the following predetermined operations: if the target sub-step includes a target keyword, send a query instruction to the target platform to query the target code of the target keyword, wherein the target keyword indicates a newly added keyword; receive the target code returned by the target platform; execute the target sub-step based on the target code; if the target sub-step does not include the target keyword, execute the target sub-step.
[0034] Through the above steps, by receiving the target test cases issued by the target platform, each sub-step included in the test cases is executed sequentially according to the test steps included in the target test cases, until all steps in the test cases are executed. For any target sub-step included in the test cases, the following predetermined operation is performed: when it is determined that the target sub-step includes a newly added target keyword, a query instruction is sent to the target platform to query the target code of the target keyword, and then the target code returned by the target platform is received. Then, the target sub-step is executed based on the target code. When it is determined that the target sub-step does not include a newly added target keyword, the target sub-step is executed directly, and each step of the test cases is executed in sequence. This invention allows for the pre-definition of custom keywords on the target platform, such as the target keywords mentioned above. Code for these custom keywords is written, and during the execution of the target test cases, if a custom keyword is encountered, the corresponding target code can be obtained by querying the target platform. Then, the target sub-steps are executed based on the target code, and so on, until all sub-steps included in the test steps are executed to complete the execution of the target test cases. This embodiment eliminates the need to recompile and rebuild the automated test project, avoiding the problem in related technologies where adding keywords or test projects to test cases requires upgrading and updating the execution machine for executing the target test cases. It also avoids the problem in related technologies where integrating the test case into the project through packaging and compilation can easily affect the stability of the automated platform and lead to frequent deployments, resulting in low automated testing efficiency. This invention solves the problem of low automated testing efficiency in related technologies, achieving the effect of improving automated testing efficiency.
[0035] The entity executing the above steps can be an execution machine, such as a program execution machine, a server, a backend system, a processor with human-computer interaction capabilities configured on a storage device, or a processing device or processing unit with similar processing capabilities, but is not limited to these. The following explanation uses an execution machine performing the above operations as an example (this is merely an illustrative example; in actual operation, other devices or modules can also perform the above operations):
[0036] In the above embodiment, the execution machine receives target test cases issued by the target platform. Each target test case contains test steps, such as one or more steps. In practical applications, the target test cases can be prepared in advance by developers on the target platform (e.g., a web / app automated testing platform), or prepared by developers and then imported into the target platform. The execution machine then executes one or more sub-steps included in the test steps sequentially until each step is completed. For example, if a test step includes three (or other numbers) sub-steps, the execution machine will execute them sequentially from step 1 to step 3 until all three steps are completed. Specifically, for any sub-step included in the test steps... Each target sub-step, for example, step 2, performs the following predetermined operations: When the execution machine determines that the target sub-step includes the target keyword, it sends a query instruction to the target platform to query the target code of the target keyword. Here, the target keyword is a newly added keyword, or a custom keyword, that is, a keyword that is not commonly used in automated testing. For example, in web testing, the target keyword is right-click, double-click, clicking a drop-down list, or other special clicks. Then, it receives the target code of the target keyword returned by the target platform and executes the target sub-step based on the target code. When it is determined that the target sub-step does not include the target keyword, the execution machine directly executes the target sub-step. In practical applications, the execution machine has a local keyword library. When executing any target sub-step, it can parse the target sub-step to obtain the first keyword contained in the target sub-step. Then, it compares the first keyword with each keyword included in the local keyword library. If there is a keyword in the local keyword library that is the same as the first keyword, it is determined that the first keyword is not the target keyword, or it can be considered that the first keyword at this time is a commonly used keyword. If there is no keyword in the local keyword library that is the same as the first keyword, it is determined that the first keyword is the target keyword, or it can be considered that the first keyword at this time is an uncommon keyword, or a newly added keyword, or a custom keyword. Each sub-step included in the test step is executed according to the above predetermined operation.In this embodiment, if a custom keyword is encountered during the execution of the target test case, the corresponding target code can be obtained by querying the target platform. Then, the target sub-steps are executed based on the target code to perform element operations and / or assertion verification on the custom keyword. This process continues until all sub-steps in the test steps are executed, thus completing the execution of the target test case. This embodiment eliminates the need to recompile and rebuild the automated test project, avoiding the problem in related technologies where adding keywords or test projects to test cases requires upgrading the execution machine for executing the target test cases. It also avoids the problem in related technologies where integrating the test case into the project through packaging and compilation can easily affect the stability of the automated platform and lead to frequent deployments, resulting in low automated testing efficiency. This invention solves the problem of low automated testing efficiency in related technologies, achieving the effect of improving automated testing efficiency.
[0037] In an optional embodiment, executing the target sub-step based on the target code includes: generating a target usage method for the target keyword corresponding to the target code using Java reflection; and invoking the target usage method to execute the target operation included in the target sub-step. In this embodiment, after the execution machine obtains the target code of the target keyword returned by the platform, it can generate a usage method for the target keyword through Java reflection, thus enabling the execution machine itself to use the target keyword. This achieves the goal of extending automation keywords through Java reflection, allowing the target keyword to be used to execute target operations in the target sub-step, such as element manipulation and / or assertion verification. Through this embodiment, the goal of extending automation keywords is achieved through Java reflection, simplifying the process of extending web automation keywords and improving the efficiency of web automation testing.
[0038] In an optional embodiment, invoking the target usage method to execute the target operations included in the target sub-step includes: invoking the target usage method to execute element operations and / or assertion verifications included in the target sub-step. In this embodiment, after the execution machine generates the target usage method for the target keyword through the JAVA reflection mechanism, it can invoke the target usage method to execute element operations and / or assertion verifications included in the target sub-step. That is, the execution machine has the ability to use the target keyword, and thus can execute the operations in the target sub-step.
[0039] In an optional embodiment, before performing the predetermined operation, the method further includes: parsing a first keyword included in the target sub-step; comparing the first keyword with a local keyword library to obtain a comparison result; if the comparison result indicates that the first keyword is not included in the local keyword library, determining that the first keyword is the target keyword, and determining that the target sub-step includes the target keyword; if the comparison result indicates that the local keyword library includes the first keyword, determining that the first keyword is a non-target keyword, and determining that the target sub-step does not include the target keyword. In this embodiment, when the executor executes each sub-step included in the test steps sequentially, for any target sub-step in the test steps, it first parses the first keyword included in the target sub-step. The first keyword may be a commonly used keyword or a newly added keyword (i.e., the aforementioned target keyword, or custom keyword). Then, it compares the first keyword with the executor's local keyword library. When it is determined that the local keyword library does not include the first keyword, it can be determined that the first keyword is the target keyword, or it can be determined that the target sub-step includes the target keyword. Then, it can send a query command to the target platform to query the target code of the target keyword according to the steps of the aforementioned embodiment. When it is determined that the local keyword library includes the first keyword, it can be determined that the first keyword is a non-target keyword, that is, it is not a target keyword, not a newly added keyword, or it can be considered that the first keyword is a commonly used keyword, or it can be considered that the executor itself already has the ability to use the first keyword. Through this embodiment, the purpose of determining whether the test steps include a newly added keyword is achieved.
[0040] In an optional embodiment, the method further includes: obtaining the actual test result of the target sub-step after execution. In this embodiment, the actual test result of any target sub-step can be obtained after execution.
[0041] In an optional embodiment, after obtaining the actual test results, the method further includes: comparing the actual test results with the expected test results to obtain a target test result, wherein the test step includes the expected test result; and returning the target test result to the target platform to instruct the target platform to generate a test report. In this embodiment, the actual test results of the target sub-step can be compared with the expected test results to obtain the test result of the target sub-step, such as the result of the target sub-step's test success or failure. Optionally, in practical applications, the target test result for the entire test case can be obtained after executing each sub-step in the test step; then, the target test result is returned to the target platform to instruct the target platform to generate a test report. This embodiment achieves the purpose of returning the execution results of the test case to the platform to instruct the platform to generate a test report.
[0042] This embodiment also provides another method for executing test cases. Figure 3 This is a flowchart of another test case execution method according to an embodiment of this application, such as... Figure 3 As shown, the process includes the following steps:
[0043] Step S302: Upon receiving the target execution instruction, a target test case is sent to the target execution machine. The target test case contains test steps to instruct the target execution machine to execute one or more sub-steps included in the test steps in sequence until each step included in the test steps is executed.
[0044] Step S304: Receive a query instruction sent by the target executor, wherein the query instruction is sent by the target executor after determining that the target sub-step includes the target keyword, and the target sub-step is any step included in the test step;
[0045] Step S306: Based on the query instruction, return the target code of the target keyword to the target executor, and instruct the target executor to execute the target sub-step based on the target code.
[0046] Through the above steps, when a target execution instruction is received, a target test case is sent to the target execution machine. The target test case contains test steps to instruct the target execution machine to execute one or more sub-steps included in the test steps in sequence until each step included in the test steps has been executed. A query instruction sent by the target execution machine is received. The query instruction is sent by the target execution machine when it determines that the target sub-step includes a target keyword. The target sub-step is any step included in the test steps. Then, based on the query instruction, the target code of the target keyword is returned to the target execution machine to instruct the target execution machine to execute the above target sub-steps based on the target code. After the target test case is issued to the target execution machine, when the target execution machine executes the test steps contained in the target test case, if it is determined that the target sub-step includes a newly added target keyword, a query command is sent to the target platform. Upon receiving the query command, the target platform returns the target code of the target keyword to the target execution machine. This target code can be pre-written code for the target keyword on the target platform, thus instructing the target execution machine to execute the corresponding target sub-step based on the target code. This process continues until the target execution machine has executed all the sub-steps included in the test steps, completing the execution of the target test case. This avoids the problem in related technologies where adding keywords or test items to test cases requires upgrading and updating the execution machine executing the target test case. It also avoids the problem in related technologies where integrating the test case into the project through packaging and compilation can easily affect the stability of the automation platform and lead to frequent deployments, resulting in low automation testing efficiency. This invention solves the problem of low automation testing efficiency in related technologies, achieving the effect of improving automation testing efficiency.
[0047] The entity executing the above steps can be a platform, such as an automated testing platform, a processor with human-computer interaction capabilities configured on a storage device, or a processing device or unit with similar processing capabilities, but is not limited to these. The following explanation uses an automated testing platform (hereinafter referred to as the platform) performing the above operations as an example (this is merely an illustrative example; in actual operation, other devices or modules can also perform the above operations):
[0048] In the above embodiments, upon receiving a target execution instruction, the platform sends target test cases to the target execution machine. Each target test case contains test steps, instructing the target execution machine to execute one or more sub-steps sequentially until all steps in the test steps have been executed. For example, when the platform receives a user-triggered test instruction, it sends the target test cases to the target execution machine and instructs the machine to execute each step in the order of the test steps included in the target test cases. Alternatively, a timed execution method can be set. In practical applications, target test cases can be prepared in advance by developers on the platform (e.g., a web / app automated testing platform), or written by developers and then imported into the target platform. When the target execution machine executes any target sub-step within the test steps, if it determines that the sub-step includes a newly added target keyword, it sends a query instruction to the platform. The target keyword is a newly added keyword, also known as a custom keyword, i.e., a keyword not commonly used in automated testing. For example, in web testing, the target keyword might be "right-click" or "double-click". The platform receives query instructions from the target executor via a drop-down list or other special clicks. Based on these instructions, it returns the target code for the target keyword to the target executor. The target executor then executes the corresponding target sub-steps based on the target code. This process continues until the target executor has completed all sub-steps included in the test steps, thus completing the execution of the target test case. In practical applications, the executor has a local keyword library. When executing any target sub-step, it parses the sub-step to obtain the first keyword contained within it. Then, it compares the first keyword with each keyword in the local keyword library. If a keyword identical to the first keyword exists in the local keyword library, the first keyword is determined not to be the target keyword, or it can be considered a commonly used keyword. If no keyword identical to the first keyword exists in the local keyword library, the first keyword is determined to be the target keyword, or it can be considered a rarely used keyword, a newly added keyword, or a custom keyword. Each sub-step included in the test steps is executed according to the predetermined operation described above.After receiving a query instruction from the target executor, the platform returns the target code of the target keyword to the target executor based on the query instruction, and instructs the target executor to execute the target sub-steps based on the target code. That is, if a custom keyword is encountered during the execution of the target test case, it can query the target platform for the target keyword (or custom keyword), and the platform will return the target code of the custom keyword to the target executor. Then, the target sub-steps are executed based on the target code to achieve element operations and / or assertion verification of the custom keyword. This process continues until all sub-steps included in the test steps are executed, thus completing the execution of the target test case. This embodiment eliminates the need to recompile and rebuild the automated test project, and also avoids the problem of low automated testing efficiency caused by the need for packaging and compilation in related technologies, which can easily affect the stability of the automated platform and lead to frequent deployments. This invention solves the problem of low automated testing efficiency in related technologies, achieving the effect of improving automated testing efficiency.
[0049] In an optional embodiment, the method further includes: receiving target test results sent by the target executor, wherein the target test results are obtained by the target executor after executing the target test cases; and generating a test report based on the target test results. In this embodiment, the platform can also receive target test results sent by the target executor, that is, after the target executor executes the target test cases, it can return the results of the target test cases to the platform, such as the success or failure result of the target test cases, or the success or failure result of the test steps included in the target test cases. Then, the platform can generate a test report for the target test cases based on the target test results. In practical applications, the target test results or test reports can be fed back to the user terminal, or the user can view the target test results or test reports on the platform terminal. Through this embodiment, the purpose of generating a test report after executing the target test cases is achieved.
[0050] In an optional embodiment, before sending the target test cases to the target execution machine, the method further includes: receiving the target test cases written by the target object, wherein the target test cases include the target keywords; and storing the target test cases in a target database, wherein the target database includes target code for the pre-written and stored target keywords. In this embodiment, the platform can receive target test cases written by the target object. For example, users or developers can pre-write target test cases on the platform, wherein the target test cases may include target keywords, i.e., newly added keywords, or custom keywords. In practical applications, users or developers can pre-write the code for the target keywords on the platform and save the target keywords to the platform's database. Similarly, pre-written target test cases can also be saved to the platform's database. Thus, when a user needs to test automated test cases, the platform can send the automated test cases to the target execution machine. Through this embodiment, the purpose of extending and secondary encapsulating keywords in web testing projects is achieved, the process of extending web automated keywords is simplified, and the efficiency of web automated testing is improved.
[0051] To better understand the execution process of the above test cases, the flow of the execution method of the above test cases will be described below in conjunction with optional embodiments, but this is not intended to limit the technical solution of the embodiments of this application.
[0052] This embodiment provides an automated testing method. Figure 4 This is a flowchart of an automated test according to a specific embodiment of this application, such as... Figure 4 As shown, the details are as follows:
[0053] S402, Log in to the web automation platform (corresponding to the aforementioned target platform), write a code snippet (corresponding to the aforementioned target code), and expand keywords;
[0054] S404, save the custom keyword (corresponding to the aforementioned target keyword) to the database;
[0055] S406, Write web automation test cases (corresponding to the aforementioned target test cases), using custom keywords;
[0056] S408, save the automation use cases to the database (corresponding to the aforementioned target database);
[0057] S410 executes automated use cases;
[0058] S412, Issue automated test case steps (corresponding to the aforementioned test steps) and keyword list to the execution machine;
[0059] S414, query custom keywords;
[0060] S416 returns the definition method of the custom keyword, that is, it returns the code snippet of the custom keyword;
[0061] S418: After the execution machine obtains the code snippet with the custom keyword, it generates the method with the custom keyword through Java's reflection mechanism, and uses the custom keyword to manipulate elements or perform assertions.
[0062] S420, The automated test case execution is complete, and the test case result (corresponding to the aforementioned target test result) is returned.
[0063] In the above embodiments, custom keywords can be defined in the web automation testing platform. During the execution of automated test cases, these keywords can be invoked through Java's reflection mechanism to achieve element manipulation and assertion judgments on the keywords. This application embodiment supports the extension and secondary encapsulation of keywords for some special web projects without requiring recompiling and rebuilding the web project. By extending web automation keywords through Java's reflection mechanism, this application embodiment reduces the number of compilation and deployment operations on the execution machine, simplifies the process of extending web automation keywords, and improves the efficiency of web automation testing.
[0064] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0065] This embodiment also provides a test case execution device. Figure 5 This is a structural block diagram of a test case execution device according to an embodiment of this application, such as... Figure 5 As shown, it includes:
[0066] The first receiving module 502 is used to receive target test cases issued by the target platform, wherein the target test cases include test steps;
[0067] The execution module 504 is configured to execute one or more sub-steps included in the test step sequentially until each step included in the test step has been executed. For any target sub-step included in the test step, the following predetermined operations are performed: if it is determined that the target sub-step includes a target keyword, a query instruction is sent to the target platform to query the target code of the target keyword, wherein the target keyword is used to indicate a newly added keyword; the target code returned by the target platform is received; the target sub-step is executed based on the target code; if it is determined that the target sub-step does not include the target keyword, the target sub-step is executed.
[0068] In an optional embodiment, the execution module 504 is further configured to execute the target sub-step by: generating a target usage method for the target keyword corresponding to the target code through a JAVA reflection mechanism; and calling the target usage method to execute the target operation included in the target sub-step.
[0069] In an optional embodiment, the execution module 504 is further configured to perform the target operations included in the target sub-step by invoking the target usage method to perform element operations and / or assertion verifications included in the target sub-step.
[0070] In an optional embodiment, the above apparatus further includes: a parsing module, configured to parse a first keyword included in the target sub-step before performing a predetermined operation; a comparison module, configured to compare the first keyword with a local keyword library to obtain a comparison result; a first determining module, configured to determine that the first keyword is the target keyword and that the target sub-step includes the target keyword if the comparison result indicates that the local keyword library does not include the first keyword; and a second determining module, configured to determine that the first keyword is a non-target keyword and that the target sub-step does not include the target keyword if the comparison result indicates that the local keyword library includes the first keyword.
[0071] In an optional embodiment, the above apparatus further includes: a first obtaining module, configured to obtain the actual test result of the target sub-step after the target sub-step has been executed.
[0072] In an optional embodiment, the above apparatus further includes: a second obtaining module, configured to compare the actual test results with the expected test results after obtaining the actual test results to obtain a target test result, wherein the test steps include the expected test results; and a returning module, configured to return the target test result to the target platform to instruct the target platform to generate a test report.
[0073] This embodiment also provides another test case execution device. Figure 6 This is a structural block diagram of an execution device for another test case according to an embodiment of this application, such as... Figure 6 As shown, it includes:
[0074] The delivery module 602 is used to deliver target test cases to the target execution machine upon receiving a target execution instruction. The target test cases contain test steps to instruct the target execution machine to execute one or more sub-steps included in the test steps in sequence until each step included in the test steps is executed.
[0075] The second receiving module 604 is used to receive a query instruction sent by the target executor, wherein the query instruction is sent by the target executor when it is determined that the target sub-step includes a target keyword, and the target sub-step is any step included in the test step;
[0076] The processing module 606 is used to return the target code of the target keyword to the target executor based on the query instruction, and instruct the target executor to execute the target sub-step based on the target code.
[0077] In an optional embodiment, the above apparatus further includes: a third receiving module, configured to receive target test results sent by the target executor, wherein the target test results are obtained by the target executor after executing the target test cases; and a generating module, configured to generate a test report based on the target test results.
[0078] In an optional embodiment, the above apparatus further includes: a fourth receiving module, configured to receive the target test cases written by the target object before issuing the target test cases to the target executor, wherein the target test cases include the target keywords; and a storage module, configured to store the target test cases in a target database, wherein the target database includes target code of the target keywords that have been pre-written and stored.
[0079] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.
[0080] Embodiments of this application also provide a computer-readable storage medium comprising a stored program, wherein the program, when executed, performs the steps of any of the method embodiments described above.
[0081] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0082] Embodiments of this application also provide an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0083] In one exemplary embodiment, 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.
[0084] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.
[0085] Obviously, those skilled in the art should understand that the modules or steps of this application described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those presented here, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, this application is not limited to any particular combination of hardware and software.
[0086] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for executing test cases, characterized in that, include: Receive target test cases issued by the target platform, wherein the target test cases contain test steps; The test step includes one or more sub-steps, which are executed sequentially until each step is completed. For any target sub-step included in the test step, the following predetermined operation is performed: If the target sub-step is determined to include a target keyword, a query instruction is sent to the target platform to query the target code of the target keyword, wherein the target keyword includes newly added keywords, custom keywords, and keywords not commonly used in automated testing; the target code returned by the target platform is received; the target sub-step is executed based on the target code, wherein the target code is code about the target keyword that has been pre-written in the target platform; If it is determined that the target sub-step does not include the target keyword, then the target sub-step is executed. Executing the target sub-step based on the target code includes: generating a target usage method for the target keyword corresponding to the target code using the Java reflection mechanism; and invoking the target usage method to execute the target operation included in the target sub-step. Calling the target usage method to execute the target operations included in the target sub-step includes: calling the target usage method to execute the element operations and / or assertion verifications included in the target sub-step.
2. The method according to any one of claims 1, characterized in that, Before performing the predetermined operation, the method further includes: Parse the first keyword included in the target sub-step; The first keyword is compared with the local keyword database to obtain the comparison results; If the comparison result indicates that the first keyword is not included in the local keyword library, the first keyword is determined to be the target keyword, and the target sub-step is determined to include the target keyword; If the comparison result indicates that the first keyword is included in the local keyword library, the first keyword is determined to be a non-target keyword, and the target keyword is determined not to be included in the target sub-step.
3. The method according to any one of claims 1, characterized in that, The method further includes: After executing the target sub-step, the actual test results of the target sub-step are obtained; The actual test results are compared with the expected test results to obtain the target test results, wherein the test steps include the expected test results; The target test results are returned to the target platform to instruct the target platform to generate a test report.
4. A method for executing test cases, characterized in that, include: Upon receiving a target execution instruction, a target test case is issued to the target execution machine. The target test case contains test steps to instruct the target execution machine to execute one or more sub-steps included in the test steps in sequence until each step included in the test steps has been executed. Receive a query instruction sent by the target executor, wherein the query instruction is sent by the target executor when it is determined that the target sub-step includes a target keyword, the target sub-step is any step included in the test steps, and the target keyword includes newly added keywords, custom keywords, and keywords that are not commonly used in automated testing; Based on the query instruction, the target execution machine returns the target code of the target keyword and instructs the target execution machine to execute the target sub-step based on the target code. The target code is pre-written code about the target keyword. The execution of the target sub-step based on the target code by the target execution machine includes: generating a target usage method for the target keyword corresponding to the target code through the JAVA reflection mechanism; calling the target usage method to execute the target operation included in the target sub-step; calling the target usage method to execute the target operation included in the target sub-step includes: calling the target usage method to execute the element operation and / or assertion verification included in the target sub-step.
5. The method according to claim 4, characterized in that, The method further includes: Receive the target test result sent by the target execution machine, wherein the target test result is obtained by the target execution machine after executing the target test case; A test report is generated based on the target test results.
6. The method according to claim 4, characterized in that, Before issuing the target test cases to the target execution machine, the method further includes: Receive the target test case written by the target object, wherein the target test case includes the target keyword; The target test cases are stored in the target database.
7. A test case execution device, characterized in that, include: The first receiving module is used to receive target test cases issued by the target platform, wherein the target test cases include test steps; An execution module is configured to execute one or more sub-steps included in the test step sequentially until each step included in the test step has been executed, wherein, for any target sub-step included in the test step, the following predetermined operation is performed: If the target sub-step is determined to include a target keyword, a query instruction is sent to the target platform to query the target code of the target keyword, wherein the target keyword includes newly added keywords, custom keywords, and keywords not commonly used in automated testing; the target code returned by the target platform is received; and the target sub-step is executed based on the target code. If it is determined that the target sub-step does not include the target keyword, then the target sub-step is executed. The execution module executes the target sub-step based on the target code in the following manner: it generates a target usage method for the target keyword corresponding to the target code using the Java reflection mechanism; and it calls the target usage method to execute the target operation included in the target sub-step. The execution module executes the target operations included in the target sub-step by calling the target usage method in the following manner: calling the target usage method to execute the element operations and / or assertion verifications included in the target sub-step.
8. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method of any one of claims 1 to 3 or 4 to 6 through the computer program.