Disclosure of Invention
The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.
The embodiment of the invention provides a method and a device for realizing test verification, which can reduce the codes in the test verification process and improve the test verification efficiency.
The embodiment of the invention provides a test and verification method, which comprises the following steps:
creating a base page class as a parent class for forms and dialogs;
inheriting the form and the dialog box by taking the created basic page class as a parent class, and packaging to obtain an application programming interface;
testing and checking according to the packaged application programming interface;
and the basic page class is packaged with search elements and clicks.
Optionally, the attributes included in the table include: a table toolbar and a table row;
the table includes: find element by name and click specify name element.
Optionally, the attributes included in the form toolbar include: drop down lists, input boxes, and button attributes;
the table row list type, each table row containing a table column attribute.
Optionally, the dialog box includes attributes including: drop down lists, input boxes, text areas.
Alternatively, elements of the form and dialog box use python descriptors.
On the other hand, the embodiment of the invention also provides equipment for realizing test verification, which comprises a processor, a memory and a communication bus;
the communication bus is used for realizing connection communication between the processor and the memory;
the processor is configured to execute an image display program stored in the memory to implement the steps of:
creating a base page class as a parent class for forms and dialogs;
inheriting the form and the dialog box by taking the created basic page class as a parent class, and packaging to obtain an application programming interface;
testing and checking according to the packaged application programming interface;
and the basic page class is packaged with search elements and clicks.
Optionally, the attributes included in the table include: a table toolbar and a table row;
the table includes: looking up and clicking on the specified name element by name;
optionally, the dialog box includes attributes including: drop down lists, input boxes, text areas.
Alternatively, elements of the form and dialog box use python descriptors.
In yet another aspect, the present invention further provides a computer-readable storage medium, which stores one or more programs, where the one or more programs are executable by one or more processors to implement the steps of the method for test verification described above.
Compared with the related art, the technical scheme of the application comprises the following steps: creating a base page class as a parent class for forms and dialogs; inheriting the form and the dialog box through the created basic page class, and packaging to obtain an application programming interface; testing and checking according to the packaged application programming interface; wherein the base page class is encapsulated with the search element and the click. The embodiment of the invention realizes the packaging of the application programming interface, avoids repeated coding during test and verification and improves the efficiency of test and verification.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
The steps illustrated in the flow charts of the figures may be performed in a computer system such as a set of computer-executable instructions. Also, while a logical order is shown in the flow diagrams, in some cases, the steps shown or described may be performed in an order different than here.
Fig. 1 is a flowchart of a method for implementing test verification according to an embodiment of the present invention, as shown in fig. 1, including:
step 100, creating a basic page (BasePage) class as a parent class of a Table (Table) and a dialog box (Modal);
it should be noted that, the basic page class created by the embodiment of the present invention is mainly used to obtain a driver object of a Selenium (browser automation test framework, a tool for Web application test).
Optionally, the attributes included in the table in the embodiment of the present invention include: a table toolbar (top) and a table row (rows); the table includes: find by name (name _ search) and click on the named name element (name _ click);
it should be noted that, in the embodiment of the present invention, name _ search is a query filter of a table search box, and name _ click is a list click operation of each row.
Optionally, the attributes included in the table toolbar (top) in the embodiment of the present invention include: drop down list (selects), input box (input), and button (btns) attributes;
the table rows (rows) are of the list (list) type, each of which contains a table column (cols) attribute.
It should be noted that the table toolbar (top) of the embodiment of the present invention includes attributes for obtaining the operation elements above the table. The table rows may represent table elements, e.g., rows [0]. cols [1] are the table elements of the first row and the second column.
Optionally, the attributes included in the dialog box in the embodiment of the present invention include: drop down lists (selects), input boxes (input), text areas (textareas).
It should be noted that the dialog box of the embodiment of the present invention includes attributes that are elements operable in the dialog box; the method comprises the following steps (next), submission (submit), submission and check (submit _ check).
Alternatively, elements of forms and dialogs of embodiments of the present invention use python descriptors.
It should be noted that python is an object-oriented interpreted computer programming language, invented by Guido van Rossum, netherlands in 1989, and published by the first open release in 1991. Python is purely free software. The Python syntax is compact and clear, one of the features is to force whitespace (white space) as a statement indentation. Python has rich and powerful libraries. It is often nicked as a glue language and can easily join various modules made in other languages together. One common application scenario is to use Python to quickly generate a prototype of a program (sometimes even the final interface of the program), and then rewrite the specifically required parts of the program with a more appropriate language, such as a graphics rendering module in a 3D game, which has a high performance requirement, and then rewrite the program with C/C + +, and then package the program into an extended class library that Python can call. It should be noted that platform issues may need to be considered when you use the extended class library, and some may not provide for cross-platform implementations.
101, inheriting a Table (Table) and a dialog box (Modal) through the created base page class, and packaging to obtain an application programming interface;
102, testing and checking according to a packaged application programming interface;
wherein the base page class is encapsulated with a find element (find _ element) and a click (click).
It should be noted that, in the embodiment of the present invention, a find element (find _ element) and a click (click) method of a base page class package can enable inherited Table (Table) and dialog box (Modal) instances to implement find and click elements in Table and Modal.
Elements of the form and the dialog box in the embodiment of the invention use the python descriptor, and carry out unified treatment on the setting (set) and obtaining (get) methods, thereby simplifying the operation; for example, table, top, input, and 'test' are used, that is, a table search box inputs a test character, and a complicated calling method is not needed, so that the method is simple and clear.
The present invention is a world wide WEB (WEB) automation testing framework that provides an Application Programming Interface (API) to simplify the code work of testers by the Selenium-based editing of mainstream WEB application forms and dialog boxes. The Selenium is a complete set of Web application test system, which includes recording (Selenium IDE), writing and running (Selenium Remote Control) of tests and parallel processing (Selenium Grid) of tests. The core of the Selenium is written entirely in JavaScript and can therefore run on any JavaScript-enabled browser. The core of the Selenium is driven by an HTML file in a specified format, which enhances the readability of the Test Suite (Test Suite) to some extent. The Selenium Remote Control allows testers to write test code using common languages (naturally including C #, et al. NET languages) and supports a variety of mainstream browsers under different operating systems. The API provided by Selenium mainly uses webdriver, select and webelement modules. The main operation of WEB applications analyzed by the applicant is focused on tables and dialogs, wherein the tables are currently popular as data tables, and the dialogs are currently popular as Modal. The embodiment of the invention provides a simple and easy-to-use testing method for mainstream web application, unnecessary code repeated work is saved, a set of uniform interface calling of each business operation can be provided, and code personnel are not required to write different codes for each operation.
Fig. 2 is a block diagram of a device for implementing test verification according to an embodiment of the present invention, and as shown in fig. 2, the device includes a processor, a memory, and a communication bus;
the communication bus is used for realizing connection communication between the processor and the memory;
the processor is used for executing the image display program stored in the memory to realize the following steps:
creating a basic page (BasePage) class as a parent class of tables (tables) and dialogs (Modal);
it should be noted that, the basic page class created by the embodiment of the present invention is mainly used to obtain a driver object of a Selenium (browser automation test framework, a tool for Web application test).
Inheriting a Table (Table) and a dialog box (Modal) through the created base page class, and packaging to obtain an application programming interface;
testing and checking according to the packaged application programming interface;
wherein the base page class is encapsulated with a find element (find _ element) and a click (click).
It should be noted that, in the embodiment of the present invention, a find element (find _ element) and a click (click) method of a base page class package can enable inherited Table (Table) and dialog box (Modal) instances to implement find and click elements in Table and Modal.
Optionally, the attributes included in the table include: a table toolbar (top) and a table row (rows);
the table includes: find by name (name _ search) and click on the named name element (name _ click);
it should be noted that, in the embodiment of the present invention, name _ search is a query filter of a table search box, and name _ click is a list click operation of each row.
Optionally, the attributes included in the table toolbar (top) in the embodiment of the present invention include: drop down list (selects), input box (input), and button (btns) attributes;
the table rows (rows) are of the list (list) type, each of which contains a table column (cols) attribute.
It should be noted that the table toolbar (top) of the embodiment of the present invention includes attributes for obtaining the operation elements above the table. The table rows may represent table elements, e.g., rows [0]. cols [1] are the table elements of the first row and the second column.
Optionally, the dialog box includes attributes including: drop down lists (selects), input boxes (input), text areas (textareas).
It should be noted that the dialog box of the embodiment of the present invention includes attributes that are elements operable in the dialog box; the method comprises the following steps (next), submission (submit), submission and check (submit _ check).
Alternatively, elements of the form and dialog box use python descriptors.
Elements of the form and the dialog box in the embodiment of the invention use the python descriptor, and carry out unified treatment on the setting (set) and obtaining (get) methods, thereby simplifying the operation; for example, table, top, input, and 'test' are used, that is, a table search box inputs a test character, and a complicated calling method is not needed, so that the method is simple and clear.
In still another aspect, an embodiment of the present invention is a computer-readable storage medium, where one or more programs are stored, and the one or more programs are executable by one or more processors to implement the method for test verification described above.
The method of the embodiment of the present invention is described in detail below by using application examples, which are only used for illustrating the present invention and are not used for limiting the protection scope of the present invention.
Application example
The embodiment of the invention firstly creates a basic page (BasePage) class as a parent class of a Table (Table) and a dialog box (Modal), mainly aims to acquire a driver (driver) object of a Selenium, and encapsulates a search element (find _ element) and a click method, wherein the encapsulated search element and click method can ensure that the inherited Table and Modal are search and click elements in the Table and Modal. Example codes are as follows:
the method mainly comprises two attributes of a Table toolbar (top) and a Table row (rows), a name search (name _ search) method and a name element click (name _ click) method, wherein the top attribute comprises a pull-down list (selections), an input box (input) and a button (btns) attribute and is used for obtaining operation elements above the Table, the rows are of a list (list) type, and each row comprises a Table column (cols) attribute, for example, the rows [0] and the cols [1] are Table elements of a first row and a second column; name _ search is the query filter for the table search box, and name _ click is the list click operation for each row. Example codes are as follows:
in the embodiment of the present invention, Modal is also a subclass of BasePage, and its attributes mainly include selections, inputs, and text areas (textareas), which are elements operable in a dialog box, including next, submit, and submit _ check, respectively, for next step, submission, and submission and verification. Example codes are as follows:
in the embodiment of the invention, the elements of the form and the dialog box use the python descriptor to carry out unified processing on the set and get methods, so that the operation is simplified, for example, table. Example codes are as follows:
the creating logic of a service of the application example can complete testing and checking through the following simple codes, and is uniformly applicable to each service, so that the distinguishing operation on the codes is not required to be performed each time:
def test_01_add(self):
self.table.top.btns['btn-add'].click()
self.modal.inputs['name']='selenium'
self.modal.inputs['code']='selenium'
self.modal.inputs['value']='selenium'
self.modal.inputs['order_num']='1'
assert self.modal.submit_check()
the application example provides a set of simple and easy-to-use testing method for main web application, unnecessary code repeated work is saved, a set of uniform interface calling of each business operation can be provided, and code personnel are not required to write different codes for each operation.
It will be understood by those skilled in the art that all or part of the steps of the above methods may be implemented by a program instructing associated hardware (e.g., a processor) to perform the steps, and the program may be stored in a computer readable storage medium, such as a read only memory, a magnetic or optical disk, and the like. Alternatively, all or part of the steps of the above embodiments may be implemented using one or more integrated circuits. Accordingly, each module/unit in the above embodiments may be implemented in hardware, for example, by an integrated circuit to implement its corresponding function, or in software, for example, by a processor executing a program/instruction stored in a memory to implement its corresponding function. The present invention is not limited to any specific form of combination of hardware and software.
Although the embodiments of the present invention have been described above, the above description is only for the convenience of understanding the present invention, and is not intended to limit the present invention. It will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.