CN108182143A - A kind of page object automated testing method - Google Patents

A kind of page object automated testing method Download PDF

Info

Publication number
CN108182143A
CN108182143A CN201711220633.3A CN201711220633A CN108182143A CN 108182143 A CN108182143 A CN 108182143A CN 201711220633 A CN201711220633 A CN 201711220633A CN 108182143 A CN108182143 A CN 108182143A
Authority
CN
China
Prior art keywords
page
test
class
elements
testing method
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201711220633.3A
Other languages
Chinese (zh)
Inventor
陶磊
徐唤春
裴大鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Commercial Software Co Ltd
Original Assignee
Commercial Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Commercial Software Co Ltd filed Critical Commercial Software Co Ltd
Priority to CN201711220633.3A priority Critical patent/CN108182143A/en
Publication of CN108182143A publication Critical patent/CN108182143A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a kind of page object automated testing methods, belong to page technical field of measurement and test, including being a Class by each Pages Design;Page elements are obtained by invoking page class in Selenium test pages;Read test instructs from page elements;The page code file of the page to be tested is called, the Class of search operation creates page object example;The page operation correlation Class that test is called to specify;Invoking page element searches corresponding page elements in page operation correlation Class;Page operation is performed to the page elements found, obtains test result.Each Pages Design is a Class by the present invention, is obtained page elements by invoking page class in Selenium test pages, is avoided the situation for as page elements id or change in location, needing to change test page code.

Description

A kind of page object automated testing method
Technical field
The present invention relates to a kind of page object automated testing methods, belong to page technical field of measurement and test.
Background technology
At present, when being tested using webdriver, it may appear that one to the element of some page positioned when The methods of time, program is in the ranks flooded with id, name, xpath, the readability that can cause test program in this way is poor, after being not easy to The maintenance and modification of phase.
Although can be easy to understand program by adding the method for annotation, can not tackle the problem at its root, mesh It is preceding using it is more be to avoid every time directly invoking these methods by carrying out secondary encapsulation to these methods, the side of passing through Although the encapsulation of method can realize multiplexing, by encapsulation can not realize page elements logical process and test data it is only It is vertical.
New test is constantly added, and seldom goes to reconstruct, utilize original test, the execution confrontation unit of Selenium Speed is slow for test, and as test gradually increases, run time can progressively increase to be difficult to the degree carried.
Invention content
The main object of the present invention is to provide for a kind of page object automated testing method, by each Pages Design For a Class, can page elements be obtained by invoking page class in Selenium test pages, avoid and work as the page Element id or during change in location, needs to change the situation of test page code.
The purpose of the present invention can reach by using following technical solution:
A kind of page object automated testing method, includes the following steps:
S1:It is a Class by each Pages Design;
S2:Page elements are obtained by invoking page class in Selenium test pages;
S3:Read test instructs from page elements;
S4:It is instructed according to test, calls the page code file of the page to be tested, behaviour is searched using page elements are not performed The Class of work creates page object example;
S5:The page operation correlation Class for test page object instance that test is called to specify;
S6:Invoking page element searches corresponding page elements in page operation correlation Class;
S7:Page operation is performed to the page elements found, obtains test result.
Further, in the S1, each Class in the page comprising the element tested is needed, including button, input Frame and title.
Further, in the S2, page elements are obtained by invoking page class in Selenium test pages, are wrapped It includes:
The separation of data, object, script three;
The web automated test frames based on selenium are built, when the demand for having web to apply changes, only Change corresponding object, data and script.
Further, in the S3, read test is instructed and is included from page elements:
Receive the operational order inputted in Selenium test pages;
Obtain page object corresponding with operational order in the former page;
Extract the page elements of page object;
It reads and instruction is tested in memory page element.
Further, in the S4, using the page object for the Class establishments for not performing page elements search operation Example includes setting information and resource information;
The resource information includes the path descriptor of each page elements in page object example.
Further, in the S5, the page operation phase for test page object instance tested and specified is called Class is closed to include:
It is used to test according to what the calling test of the path descriptor of page elements each in page object example was specified The page operation correlation Class of page object example.
Further, in the S6, invoking page element searches corresponding page member in page operation correlation Class Element, including:
Invoking page element according to the corresponding paths of page operation correlation Class to retouch in page operation correlation Class It states symbol and searches corresponding page elements.
Further, in the S6, invoking page element searches corresponding page member in page operation correlation Class Element if not finding page elements, continues to search for page elements, until finding the page after waiting for default lookup time interval Element until searches the total duration of page elements more than or equal to default total duration.
Further, if not finding page elements until when the total duration for searching page elements is more than or equal to default total It is long, then error message is returned to by page operation correlation Class.
Further, in the S7, page operation is performed to the page elements that find, is obtained after test result again to page Surface element carries out second test, including:
Test result data is input in the input domain of Web page;
Capture the warning dialog box object of Web page;
Analyze the error information in the warning dialog box object;
Error information and the expected results in test cases data are compared, if comparison result unanimously if illustrate to survey It pinged, and illustrated that second test does not pass through if comparison result is inconsistent.
The advantageous effects of the present invention:Page object automated testing method according to the invention, it is provided by the invention Each Pages Design is a Class, wherein including the member for needing to test in the page by page object automated testing method Element, such as button, input frame and title can obtain page member in Selenium test pages by invoking page class Element avoids the situation for as page elements id or change in location, needing to change test page code, when page elements id changes When, it is only necessary to change the attribute of the page in test sheets Class.
Specific embodiment
To make those skilled in the art more clear and clear and definite technical scheme of the present invention, with reference to embodiment to this hair It is bright to be described in further detail, but the implementation of the present invention is not limited to this.
A kind of page object automated testing method provided in this embodiment, includes the following steps:
S1:It is a Class by each Pages Design;
S2:Page elements are obtained by invoking page class in Selenium test pages;
S3:Read test instructs from page elements;
S4:It is instructed according to test, calls the page code file of the page to be tested, behaviour is searched using page elements are not performed The Class of work creates page object example;
S5:The page operation correlation Class for test page object instance that test is called to specify;
S6:Invoking page element searches corresponding page elements in page operation correlation Class;
S7:Page operation is performed to the page elements found, obtains test result.
In some embodiments, in the S1, each Class in the page comprising the element tested is needed, including pressing Button, input frame and title.
In some embodiments, in the S2, the page is obtained by invoking page class in Selenium test pages Element, including:
The separation of data, object, script three;
The web automated test frames based on selenium are built, when the demand for having web to apply changes, only Change corresponding object, data and script.
In some embodiments, in the S3, read test is instructed and is included from page elements:
Receive the operational order inputted in Selenium test pages;
Obtain page object corresponding with operational order in the former page;
Extract the page elements of page object;
It reads and instruction is tested in memory page element.
In some embodiments, in the S4, using the page for the Class establishments for not performing page elements search operation Face object instance includes setting information and resource information;
The resource information includes the path descriptor of each page elements in page object example.
In some embodiments, in the S5, the page for test page object instance tested and specified is called Operation correlation Class includes:
It is used to test according to what the calling test of the path descriptor of page elements each in page object example was specified The page operation correlation Class of page object example.
In some embodiments, in the S6, invoking page element searches corresponding page in page operation correlation Class Surface element, including:
Invoking page element according to the corresponding paths of page operation correlation Class to retouch in page operation correlation Class It states symbol and searches corresponding page elements.
In some embodiments, in the S6, invoking page element searches corresponding page in page operation correlation Class Surface element if not finding page elements, continues to search for page elements, until finding after waiting for default lookup time interval Page elements until search the total duration of page elements more than or equal to default total duration.
In some embodiments, if not finding page elements until searching the total duration of page elements more than or equal to default Total duration then returns to error message by page operation correlation Class.
In some embodiments, in the S7, page operation is performed to the page elements found, after obtaining test result Second test is carried out to page elements again, including:
Test result data is input in the input domain of Web page;
Capture the warning dialog box object of Web page;
Analyze the error information in the warning dialog box object;
Error information and the expected results in test cases data are compared, if comparison result unanimously if illustrate to survey It pinged, and illustrated that second test does not pass through if comparison result is inconsistent.
In conclusion in the present embodiment, according to the page object automated testing method of the present embodiment, the present embodiment carries Each Pages Design is a Class, wherein comprising needing to test in the page by the page object automated testing method of confession Element, such as button, input frame and title can obtain the page in Selenium test pages by invoking page class Element avoids the situation for as page elements id or change in location, needing to change test page code, when page elements id becomes During change, it is only necessary to change the attribute of the page in test sheets Class.
The above, further embodiment only of the present invention, but protection scope of the present invention is not limited thereto, and it is any Those familiar with the art is in range disclosed in this invention, and according to the technique and scheme of the present invention and its design adds With equivalent substitution or change, protection scope of the present invention is belonged to.

Claims (10)

1. a kind of page object automated testing method, which is characterized in that include the following steps:
S1:It is a Class by each Pages Design;
S2:Page elements are obtained by invoking page class in Selenium test pages;
S3:Read test instructs from page elements;
S4:It is instructed according to test, calls the page code file of the page to be tested, using not performing page elements search operation Class creates page object example;
S5:The page operation correlation Class for test page object instance that test is called to specify;
S6:Invoking page element searches corresponding page elements in page operation correlation Class;
S7:Page operation is performed to the page elements found, obtains test result.
2. a kind of page object automated testing method according to claim 1, which is characterized in that each in the S1 A Class in the page comprising the element tested is needed, including button, input frame and title.
3. a kind of page object automated testing method according to claim 1, which is characterized in that in the S2, Page elements are obtained by invoking page class in Selenium test pages, including:
The separation of data, object, script three;
The web automated test frames based on selenium are built, when the demand for having web to apply changes, are only changed Corresponding object, data and script.
4. a kind of page object automated testing method according to claim 1, which is characterized in that in the S3, from page Read test instruction includes in surface element:
Receive the operational order inputted in Selenium test pages;
Obtain page object corresponding with operational order in the former page;
Extract the page elements of page object;
It reads and instruction is tested in memory page element.
5. a kind of page object automated testing method according to claim 1, which is characterized in that in the S4, use The page object example for not performing the Class establishments of page elements search operation includes setting information and resource information;
The resource information includes the path descriptor of each page elements in page object example.
6. a kind of page object automated testing method according to claim 1, which is characterized in that in the S5, call What test was specified includes for the page operation correlation Class of test page object instance:
Test page is used for according to what the calling test of the path descriptor of page elements each in page object example was specified The page operation correlation Class of object instance.
7. a kind of page object automated testing method according to claim 1, which is characterized in that in the S6, in page Invoking page element searches corresponding page elements in the operation correlation Class of face, including:
Invoking page element is with according to the corresponding path descriptors of page operation correlation Class in page operation correlation Class Search corresponding page elements.
8. a kind of page object automated testing method according to claim 1, which is characterized in that in the S6, in page Invoking page element searches corresponding page elements in the operation correlation Class of face, if not finding page elements, waits for default Page elements are continued to search for after searching time interval, until finding page elements or until searching the total duration of page elements More than or equal to default total duration.
9. a kind of page object automated testing method according to claim 8, which is characterized in that if not finding the page Element presets total duration until the total duration for searching page elements is more than or equal to, then is returned by page operation correlation Class wrong False information.
10. a kind of page object automated testing method according to claim 1, which is characterized in that in the S7, to looking into The page elements found perform page operation, and second test is carried out to page elements again after obtaining test result, including:
Test result data is input in the input domain of Web page;
Capture the warning dialog box object of Web page;
Analyze the error information in the warning dialog box object;
Error information and the expected results in test cases data are compared, if comparison result unanimously if illustrate that test is logical It crosses, illustrates that second test does not pass through if comparison result is inconsistent.
CN201711220633.3A 2017-11-29 2017-11-29 A kind of page object automated testing method Pending CN108182143A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711220633.3A CN108182143A (en) 2017-11-29 2017-11-29 A kind of page object automated testing method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711220633.3A CN108182143A (en) 2017-11-29 2017-11-29 A kind of page object automated testing method

Publications (1)

Publication Number Publication Date
CN108182143A true CN108182143A (en) 2018-06-19

Family

ID=62545469

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711220633.3A Pending CN108182143A (en) 2017-11-29 2017-11-29 A kind of page object automated testing method

Country Status (1)

Country Link
CN (1) CN108182143A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109062813A (en) * 2018-10-08 2018-12-21 南京薄幕软件科技有限公司 A kind of literary men's cloud open platform page automated testing method based on index in classification
CN109299983A (en) * 2018-09-30 2019-02-01 北京金山安全软件有限公司 Mobile application advertisement generation method and device, electronic equipment and storage medium
CN109508297A (en) * 2018-11-26 2019-03-22 南京物盟信息技术有限公司 A kind of wisdom agricultural monitoring system of internet of things based on Internet of Things web page automatic test
CN110750441A (en) * 2019-09-06 2020-02-04 平安健康保险股份有限公司 Automatic testing method and device, computer equipment and storage medium
CN112231214A (en) * 2020-10-16 2021-01-15 百度国际科技(深圳)有限公司 Page testing method and device, electronic equipment and medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102521121A (en) * 2011-11-18 2012-06-27 华为技术有限公司 Page testing method and page testing device
US8893087B2 (en) * 2011-08-08 2014-11-18 Ca, Inc. Automating functionality test cases
CN106484609A (en) * 2015-09-01 2017-03-08 博雅网络游戏开发(深圳)有限公司 Page method of testing and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8893087B2 (en) * 2011-08-08 2014-11-18 Ca, Inc. Automating functionality test cases
CN102521121A (en) * 2011-11-18 2012-06-27 华为技术有限公司 Page testing method and page testing device
CN106484609A (en) * 2015-09-01 2017-03-08 博雅网络游戏开发(深圳)有限公司 Page method of testing and device

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109299983A (en) * 2018-09-30 2019-02-01 北京金山安全软件有限公司 Mobile application advertisement generation method and device, electronic equipment and storage medium
CN109062813A (en) * 2018-10-08 2018-12-21 南京薄幕软件科技有限公司 A kind of literary men's cloud open platform page automated testing method based on index in classification
CN109508297A (en) * 2018-11-26 2019-03-22 南京物盟信息技术有限公司 A kind of wisdom agricultural monitoring system of internet of things based on Internet of Things web page automatic test
CN110750441A (en) * 2019-09-06 2020-02-04 平安健康保险股份有限公司 Automatic testing method and device, computer equipment and storage medium
CN112231214A (en) * 2020-10-16 2021-01-15 百度国际科技(深圳)有限公司 Page testing method and device, electronic equipment and medium
CN112231214B (en) * 2020-10-16 2023-09-26 百度国际科技(深圳)有限公司 Page test method, device, electronic equipment and medium

Similar Documents

Publication Publication Date Title
CN108182143A (en) A kind of page object automated testing method
US10372594B2 (en) Method and device for retrieving test case based on code coverage
US9983984B2 (en) Automated modularization of graphical user interface test cases
EP3251298B1 (en) Data extraction
CN106202235A (en) A kind of data processing method and device
CN111078221B (en) Page color theme switching method and device, storage medium and electronic equipment
KR102033416B1 (en) Method for generating data extracted from document and apparatus thereof
CN108804300A (en) Automated testing method and system
CN106484609A (en) Page method of testing and device
CN107038117B (en) Web automatic testing method based on definition-reference between event processing functions
CN111240967B (en) Code generation method and device
CN109359053A (en) Generation method and relevant apparatus, the test macro and storage medium of test report
CN110968314A (en) Page generation method and device
CN102014023B (en) VB Script based automatic testing method of network equipment products
CN107168848B (en) Multithreading analysis and operation visualization method
CN108763054A (en) Test effect methods of exhibiting, electronic device and the storage medium of test cases
CN109491884A (en) Code method for testing performance, device, computer equipment and medium
CN109508297A (en) A kind of wisdom agricultural monitoring system of internet of things based on Internet of Things web page automatic test
CN103593273A (en) Method, device and system for testing circuit board card
CN108270604B (en) Method and system for tracking service data change
Bartoli et al. Recording and replaying navigations on AJAX web sites
CN109062813A (en) A kind of literary men's cloud open platform page automated testing method based on index in classification
CN102929777A (en) Network application testing method and system
CN109857636A (en) A kind of methods and applications positioning App homepage in Android client UI automation process
CN103678134A (en) Method and device for obtaining browser script information with faults to be analyzed browser

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20180619

WD01 Invention patent application deemed withdrawn after publication