Disclosure of Invention
The embodiment of the application provides an automatic testing method, device, equipment and medium for login of an Html5 game page, and aims to at least solve the problem of compatibility testing in the related technology and solve the problems of low manual testing efficiency and high time cost and labor cost.
In a first aspect, an embodiment of the present application provides an automatic testing method for Html5 game page login, including: loading a driver of a browser needing compatibility test by using a pre-written script; calling a Selenium library through the script to drive each browser and simulate a login request of a user, wherein the login request of the simulated user comprises: automatically opening an Html5 game page with each said browser and simulating interaction of elements of said Html5 game page to generate a login request; executing each test case in a pre-constructed test case set under a pre-constructed test case environment, wherein each test case is positioned to each element in advance; and when all the test cases in the test case set are completely executed, automatically generating a test report.
In some embodiments, in a case that the test case environment includes a pre-condition and a post-condition, executing each test case in the pre-constructed test case set in the pre-constructed test case environment includes: before executing each test case, opening a browser, maximizing the browser and/or clicking a search button of the browser according to the precondition; and after each test case is executed, closing the browser according to the post condition.
In some embodiments, said locating each of said test cases onto each of said elements comprises: creating a test case according to an equivalence class division method or a boundary value analysis method; and positioning the created test case to the corresponding element.
In some embodiments, in a case that the script is a Python script, loading a driver of a browser requiring a compatibility test by using a pre-written script includes: placing a driving address of a browser needing compatibility testing under a directory of the Python script; and loading the driver of each browser by using the Python script.
In a second aspect, an embodiment of the present application provides an automatic testing apparatus for Html5 game page login, including: the device comprises a loading module, a calling module, an executing module and a generating module, wherein the loading module is used for loading the driver of the browser needing to be subjected to the compatibility test by utilizing a pre-written script; the calling module is used for calling the Selenium library through the script to drive each browser and simulate the login request of the user, wherein the login request of the simulated user comprises: automatically opening an Html5 game page with each said browser and simulating interaction of elements of said Html5 game page to generate a login request; the execution module is used for executing each test case in a pre-constructed test case set under a pre-constructed test case environment, wherein each test case is positioned to each element in advance; the generating module is used for automatically generating a test report when all the test cases in the test case set are executed.
In some embodiments, in a case that the test case environment includes a pre-condition and a post-condition, executing each test case in the pre-constructed test case set in the pre-constructed test case environment includes: before executing each test case, opening a browser, maximizing the browser and/or clicking a search button of the browser according to the precondition; and after each test case is executed, closing the browser according to the post condition.
In some embodiments, said locating each of said test cases onto each of said elements comprises: creating a test case according to an equivalence class division method or a boundary value analysis method; and positioning the created test case to the corresponding element.
In some embodiments, in a case that the script is a Python script, loading a driver of a browser requiring a compatibility test by using a pre-written script includes: placing a driving address of a browser needing compatibility testing under a directory of the Python script; and loading the driver of each browser by using the Python script.
In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a storage medium storing a computer program, where the computer program, when executed by the processor, implements the automatic testing method for Html5 game page login according to any one of the above items.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored, the computer program, when executed by a processor, implementing an automated testing method for Html5 game page login as described in any one of the above.
According to the content, the automatic testing method for the login of the Html5 game page comprises the following steps: loading a driver of a browser needing compatibility test by using a pre-written script; calling a Selenium library through a script to drive each browser and simulate a login request of a user, wherein the simulating of the login request of the user comprises the following steps: automatically opening an Html5 game page with each browser and simulating interaction of each element of an Html5 game page to generate a login request; executing each test case in a pre-constructed test case set under a pre-constructed test case environment, wherein each test case is positioned on each element in advance; and when all the test cases in the test case set are executed, automatically generating a test report. The compatibility test problem is effectively solved, the test efficiency is improved, and the time cost and the labor cost are saved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments provided in the present application without any inventive step are within the scope of protection of the present application.
It is obvious that the drawings in the following description are only examples or embodiments of the present application, and that it is also possible for a person skilled in the art to apply the present application to other similar contexts on the basis of these drawings without inventive effort. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
Reference in the specification to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the specification. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of ordinary skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments without conflict.
Unless defined otherwise, technical or scientific terms referred to herein shall have the ordinary meaning as understood by those of ordinary skill in the art to which this application belongs. Reference to "a," "an," "the," and similar words throughout this application are not to be construed as limiting in number, and may refer to the singular or the plural. The present application is directed to the use of the terms "including," "comprising," "having," and any variations thereof, which are intended to cover non-exclusive inclusions; for example, a process, method, system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or elements, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus. Reference to "connected," "coupled," and the like in this application is not intended to be limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The term "plurality" as referred to herein means two or more. "and/or" describes an association relationship of associated objects, meaning that three relationships may exist, for example, "A and/or B" may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. Reference herein to the terms "first," "second," "third," and the like, are merely to distinguish similar objects and do not denote a particular ordering for the objects.
In order to solve the problem of compatibility testing, improve testing efficiency, and save time cost and labor cost, an embodiment of the application provides an automatic testing method for registering a Html5 game page, wherein an automatic testing process of the method is a part of testing work, is established relative to functional testing, and is mainly realized through Web, a software testing tool (namely, Selenium) and a script. Fig. 1 is a flowchart of an automated testing method for Html5 game page login according to an embodiment of the present application, as shown in fig. 1, the method includes:
s100: loading a driver of a browser needing compatibility test by using a pre-written script;
s200: calling a Selenium library through a script to drive each browser and simulate a login request of a user, wherein the login request of the simulated user comprises the following steps: automatically opening an Html5 game page with each browser and simulating interaction of each element of an Html5 game page to generate a login request;
s300: executing each test case in a pre-constructed test case set under a pre-constructed test case environment, wherein each test case is positioned on each element in advance;
s400: and when all the test cases in the test case set are executed, automatically generating a test report.
According to the content, not only is the drive of the browser needing to be subjected to the compatibility test automatically loaded through the script, but also the Selenium test can be directly operated in the browser, just like the operation of a real user, the browser supported by the Selenium test comprises IE (7, 8, 9, 10, 11), Mozilla Firefox, Safari, Google Chrome, Opera and the like, so that the Selenium library is automatically called through the script to simulate the interaction of the user on the Web, the compatibility and the automatic test of the Html5 game page login are realized, the compatibility test problem is effectively solved, the test efficiency is improved, the time cost and the labor cost are saved, and the consistency and the repeatability of the test are ensured. In addition, the expected results can be achieved by modifying the script, making the test easy to maintain.
Optionally, the test case environment may include a preset precondition and a preset postcondition, for example, before each test case is executed, a browser is opened, the browser is maximized, and/or a search button of the browser is clicked according to the precondition; and after each test case is executed, closing the browser according to the post condition.
Optionally, the test case may be created according to an equivalence class classification method or a boundary value analysis method, and then the created test case is located on the corresponding element.
The above equivalence class partitioning method divides all possible input data (valid and invalid) of a program into several equivalence classes. And then, selecting representative data from each part as a test case for reasonable classification, wherein the test case consists of representatives of effective equivalence classes and ineffective equivalence classes, thereby ensuring the integrity and the representativeness of the test case. The method can reduce the design of unnecessary test cases, because the test cases use the same equivalence class data, thereby leading the test object to obtain the same reflecting behavior.
The above boundary value analysis method is complementary to the equivalence class classification method, and in this case, the test case is derived from the boundary of the equivalence class.
In order to more clearly illustrate the automatic testing method for the login of the Html5 game page in the embodiment of the present application, specific examples are given below.
According to the embodiment of the application, an automatic testing framework is constructed, the testing cases can be led in by the automatic testing framework, and the machine can realize artificial and complicated clicking and inputting operations, so that the testing report can be automatically output to allow a testing engineer to check the testing result, wherein a plurality of testing cases can be written by an equivalence class division method and/or a boundary value analysis method.
As an embodiment, a driver (WebDriver) of a browser that needs to be subjected to a compatibility test is installed first, specifically, a script written in Java or Python language can be freely selected, and the driver of each browser is loaded using the written script.
The above-mentioned Selenium encapsulates various browser-driven requests (get, post, etc.) and contents (body), where the Selenium library is called by, for example, Python script to drive the browser, so as to completely simulate the user's operation on the browser, for example, simulate the user's login request: automatically opening the Html5 game page by using different browsers and simulating the interaction (such as clicking, inputting account numbers and passwords, dragging a mouse and the like) of each element of the Html5 game page, thereby generating various login requests.
The automated testing framework is one of the cores of the embodiment of the application and is beneficial to the automated testing of the login of the Html5 game page. Specifically, a test case is created using, for example, an equivalence class partition method and/or a boundary value analysis method, and from the viewpoint of code writing, a TestCase test class is created and inherits TestCase (). Then, the Web element positioning of the game login interface is used for positioning the corresponding elements, namely, each created test case is positioned on each element of the Html5 game page, so that the click and input (account and password) operations and the like of the player are simulated by using codes. For example, main () can construct a test case set, and by calling main (), the test cases in main () are run in sequence, and finally, a test report is automatically generated. Thus, basic login automation testing can be completed.
As a further improvement, the Setup () and TearDown () of the test framework can be used to simulate the pre-condition and the post-condition before and after the execution of each test case according to different login situations. Namely Setup () and TearDown () represent a precondition and a postcondition, respectively. For example, according to the Setup () precondition, buttons such as open a browser, maximize a browser, click a search of a browser, etc. may be used before executing each test case. Similarly, Teardown () means a post condition, for example: after each test case is executed, operations such as closing a browser can be simulated. Therefore, the steps are not required to be written on each test case, and only different input operations of a user need to be written, which is equivalent to building an environment for writing the test cases. And moreover, the code amount can be saved, and the storage cost can be saved.
Further, the test result of account registration can be judged by adding assertion, and whether the result of program execution and the set expected result are consistent or not is specifically judged. TestSuite () can also be used to represent the test case suite, and the test case classes that need to be executed are stored together. And executing the test case through the TestRunner, and then generating a test report, for example, generating a test report in an Html format. Related parameters can be filled in to improve the readability of the test report, and the test report can show which logging is successful and which logging is failed.
As an implementation manner, fig. 2 is a schematic diagram of a relationship between a test tool, a script and a browser according to an embodiment of the present application, as shown in fig. 2:
(1) the method comprises the steps that a driving address of a browser needing compatibility testing is placed under an directory of a Python script, and therefore the driving of each browser is loaded through the Python script;
(2) after the Webdriver is initialized, the browser can be controlled through codes to simulate automation operation, and firstly, the browser is opened;
(3) building a test case environment, namely setting the above-mentioned Setup () and Teardown (), the browser can complete the automatic precondition arrangement operation of Selenium, for example, opening the browser, maximizing the browser, clicking the search button of the browser, etc. before executing the test case;
(4) writing a test case: searching a game page through embedding and switching;
(5) writing a test case: and detecting the elements, and positioning and inputting the elements. Based on the steps (4) - (5), after the Web positioning element is successful, the browser simulates operations such as clicking and inputting of a user;
(6) defining a test case set comprising a plurality of test cases;
(7) and running the test suite and executing the TestCase in batches. Based on the steps (6) - (7), the browser executes all the TestCase operations;
(8) TestRunner is executed to generate a test report in Html format.
The embodiment of the present application further provides an automatic testing device for logging in an Html5 game page, which is used to implement the foregoing embodiment and preferred embodiments, and the description of the device is omitted. The term "module" as used below may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 3 is a block diagram of an automatic testing apparatus for Html5 game page login according to an embodiment of the present application, as shown in fig. 3, the apparatus includes: the system comprises a loading module 1, a calling module 2, an executing module 3 and a generating module 4. The loading module 1 is configured to load a driver of a browser requiring a compatibility test by using a pre-written script.
The calling module 2 is configured to call a Selenium library through a script to drive each browser and simulate a login request of a user, where the login request of the simulated user includes: automatically opening an Html5 game page with each browser and simulating interaction of each element of an Html5 game page to generate a login request;
the execution module 3 is used for executing each test case in the pre-constructed test case set under the pre-constructed test case environment, wherein each test case is positioned on each element in advance;
the generating module 4 is used for automatically generating a test report when all the test cases in the test case set are executed.
Optionally, the test case environment may include a preset precondition and a preset postcondition, for example, before each test case is executed, a browser is opened, the browser is maximized, and/or a search button of the browser is clicked according to the precondition; and after each test case is executed, closing the browser according to the post condition.
Optionally, the test case may be created according to an equivalence class classification method or a boundary value analysis method, and then the created test case is located on the corresponding element.
Optionally, the script is a Python script, and a driver address of a browser requiring a compatibility test may be placed in an entry of the Python script, so that a driver of each browser is loaded by using the Python script.
The above modules may be functional modules or program modules, and may be implemented by software or hardware. For a module implemented by hardware, the modules may be located in the same processor; or the modules can be respectively positioned in different processors in any combination.
Fig. 4 is a block diagram of an electronic device according to an embodiment of the present application, and as shown in fig. 4, the electronic device may include a processor 81 and a memory 82 storing computer program instructions.
Specifically, the processor 81 may include a Central Processing Unit (CPU), or A Specific Integrated Circuit (ASIC), or may be configured to implement one or more Integrated circuits of the embodiments of the present Application.
Memory 82 may include, among other things, mass storage for data or instructions. By way of example, and not limitation, memory 82 may include a Hard Disk Drive (Hard Disk Drive, abbreviated to HDD), a floppy Disk Drive, a Solid State Drive (SSD), flash memory, an optical Disk, a magneto-optical Disk, tape, or a Universal Serial Bus (USB) Drive or a combination of two or more of these. Memory 82 may include removable or non-removable (or fixed) media, where appropriate. The memory 82 may be internal or external to the data processing apparatus, where appropriate. In a particular embodiment, the memory 82 is a Non-Volatile (Non-Volatile) memory. In particular embodiments, Memory 82 includes Read-Only Memory (ROM) and Random Access Memory (RAM). The ROM may be mask-programmed ROM, Programmable ROM (PROM), Erasable PROM (EPROM), Electrically Erasable PROM (EEPROM), Electrically rewritable ROM (earrom), or FLASH Memory (FLASH), or a combination of two or more of these, where appropriate. The RAM may be a Static Random-Access Memory (SRAM) or a Dynamic Random-Access Memory (DRAM), where the DRAM may be a Fast Page Mode Dynamic Random-Access Memory (FPMDRAM), an Extended data output Dynamic Random-Access Memory (EDODRAM), a Synchronous Dynamic Random-Access Memory (SDRAM), and the like.
The memory 82 may be used to store or cache various data files for processing and/or communication use, as well as possible computer program instructions executed by the processor 81.
The processor 81 implements any of the above described embodiments of an automated testing method for Html5 game page entries by reading and executing computer program instructions stored in the memory 82.
In some of these embodiments, the electronic device may also include a communication interface 83 and a bus 80. As shown in fig. 4, the processor 81, the memory 82, and the communication interface 83 are connected via the bus 80 to complete communication therebetween.
The communication interface 83 is used for implementing communication between modules, devices, units and/or equipment in the embodiment of the present application. The communication port 83 may also be implemented with other components such as: the data communication is carried out among external equipment, image/data acquisition equipment, a database, external storage, an image/data processing workstation and the like.
The bus 80 includes hardware, software, or both to couple the components of the electronic device to one another. Bus 80 includes, but is not limited to, at least one of the following: data Bus (Data Bus), Address Bus (Address Bus), Control Bus (Control Bus), Expansion Bus (Expansion Bus), and Local Bus (Local Bus). By way of example, and not limitation, Bus 80 may include an Accelerated Graphics Port (AGP) or other Graphics Bus, an Enhanced Industry Standard Architecture (EISA) Bus, a Front-Side Bus (FSB), a Hyper Transport (HT) Interconnect, an ISA (ISA) Bus, an InfiniBand (InfiniBand) Interconnect, a Low Pin Count (LPC) Bus, a memory Bus, a microchannel Architecture (MCA) Bus, a PCI (Peripheral Component Interconnect) Bus, a PCI-Express (PCI-X) Bus, a Serial Advanced Technology Attachment (SATA) Bus, a Video Electronics Bus (audio Electronics Association), abbreviated VLB) bus or other suitable bus or a combination of two or more of these. Bus 80 may include one or more buses, where appropriate. Although specific buses are described and shown in the embodiments of the application, any suitable buses or interconnects are contemplated by the application.
In addition, in combination with the automatic testing method for the login of the Html5 game page in the above embodiment, the embodiment of the present application may be implemented by providing a computer-readable storage medium. The computer readable storage medium having stored thereon computer program instructions; the computer program instructions, when executed by the processor, implement any one of the above embodiments of an automated testing method for Html5 game page entry.
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.