Catalog
One 、 What is? Selenium?
Two 、 Automated testing framework
3、 ... and 、 Design and implementation of automation framework
Four 、 Modules that need to be improved
5、 ... and 、 summary
Software testing learning resource sharing
Selenium Is a browser based automated testing tool , It provides a cross platform 、 Cross browser end-to-end web Automation solutions .Selenium It mainly includes three parts :Selenium IDE、Selenium WebDriver and Selenium Grid.
Selenium IDE:Firefox An extension of , It can record and play back , And record the operation in multiple languages ( for example java、python etc. ) In the form of test case .
Selenium WebDriver: Provide Web Automation needs API, Mainly used as browser control 、 Page element selection and debugging . Different browsers need different WebDriver.
Selenium Grid: Provides different browsers running on different machines selenium The ability to test .
This article will introduce how to use Python combination Selenium WebDriver Library building web Automated testing framework .
A typical automated testing framework generally includes the use case management module 、 Automatic executive controller 、 Report generation module and log modular , These modules complement each other .
Next, it introduces the logic unit of each module :
1、 Use case management module
Use case management module includes new 、 modify 、 Delete and other operation units , These units will also involve the use case writing pattern , Test database management 、 Reusable library, etc .
2、 Automation controller
A controller is an organizational module that automates the execution of use cases , It's mainly about how to execute our test cases .
3、 Report generation module
It is mainly responsible for generating reports after executing use cases , General with HTML The format is mostly , Information is mainly about the execution of use cases . In addition, you can also configure the send mail function .
4、log modular
It is mainly used to record the execution of use cases , To facilitate efficient investigation of use case failure information and tracking of use case execution .
1、 Demand analysis
First of all, our test object is a web platform , The framework designed based on this platform should include test case management 、 Test the execution controller 、 Test report and test log generation .
2、 Design and implementation
Page management
Hypothesis test web Object is a typical single page application , So we use page mode . Page pattern is the link between page and test case , It abstracts each page into a separate class , Provide positioning and operation of page elements for test cases .
BaseClass As a parent class only contains driver Member variables , Used to identify Selenium Medium WebDriver, To locate page elements in subclasses .LoginClass and PageClass As subclasses , It can provide positioning and operation methods of page elements . Like the login page .
From the page , The elements that need to be manipulated are : Login username 、 password 、 Next time automatic login and login button . The specific implementation code is as follows :
Page parent class BaseClass.py
LoginClass Inherited from BaseClass, And the elements of login positioning and operation implementation . In the code username and password, And added the operation of setting user name and password .
Public library module
The common library module serves to create test cases , Mainly including constants 、 Public function 、 journal 、 Reports, etc. .
Common.py
The test case information class is used to identify the test case , And include execution use cases 、 Execution result information , It mainly includes the following fields .
The log is mainly used to record the execution steps of test cases and the error information generated , Different information has different levels of logging , such as Information、Warning、Critical and Debug. Because each test case produces fewer log entries , So only the highest level of log printing is used in the test framework , namely Debug Level , This level will also print out all other log level information . In the concrete implementation, I quoted Python In the standard library logging Class library , For more convenient control of log output .
Test case warehouse
Use case warehouse is mainly used to organize automatic test cases . Each test case is abstracted into a separate class , And they all inherit from unittest.TestCase class . Python Medium unittest The library provides rich testing framework support , Including test cases setUp and tearDown Method , In the process of implementing use cases, you can rewrite . Relying on page management and public library module to achieve page methods and public functions , Each test case script will be written clearly and concisely .
From this test case , We can see
3、 Use case execution module
The execution module is mainly used to control the batch execution of test case scripts , Form a test set . The execution of the use case refers to Python In the standard library subprocess To execute nosetests Of shell command , To execute the use cases in the given test case set . The test case set is a simple plain text file , In the process of implementation, the .txt file testcases.txt.
Not before use case “#“ The marked test case script will be executed , But there is ”#“ Those marked will be ignored , This can easily control the execution of the test set , Of course, you can create different files to execute different test sets .
For the existing implementation of the test framework , Already satisfied web Automation requirements for objects , But there are still some things that can be improved , such as :
be based on Selenium Realized web The automated testing framework is not only lightweight but also flexible , Automated test cases can be developed quickly , Combined with the framework design and some good practice , I hope for you in the future web The design and implementation of the automation framework helps .
Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it
These materials , For those who want to advance 【 automated testing 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful …