Python+Selenium (1) - automated testing framework

1. What is an automated testing framework

      Simply put, an automated testing framework is composed of some standards, protocols, and rules that provide an environment for scripting to run. Automated testing frameworks can provide many conveniences for users to efficiently complete some things, such as developing scripts with a clear structure, executing scripts in multiple ways and platforms, and good reports to track script execution results.

Frameworks offer some of the following advantages:

1) Code reuse

2) Maximum coverage

3) Very low maintenance

4) Very little manual intervention

5) Simple report output

2. Common test framework classification

Many Selenium automation test developers are transferred from QTP, so the frameworks they designed in the early days can be roughly divided into the following categories:

1) Module-based testing framework

2) Test framework based on library structure

3) Data-driven testing framework, much like QTP

4) Keyword-driven testing framework, also from QTP

5) Mixed test boxes, 3 4 and comprehensive

6) Behavior-driven development and testing framework

 We will not introduce these frameworks one by one here. Literally, you can imagine some of the backgrounds and components of these frameworks. This article only has a basic understanding of the frameworks.

3. Framework basic components

Let's consider the following framework components:

1) Requires configuration file management

2) Separation of business logic code and test script

3) Report and log file output

4) Encapsulation of custom libraries

5) Manage and execute scripts

6) Introduction of third-party plug-ins

7) Continuous Integration

explain:

      We need a configuration file to control some, environment information, switches, and configuration files can be txt/xml/yaml/properties/ini. Generally, .properties are used more in JAVA. This article is a Python series. I may choose the ini file.

       The business logic code is separated from the test script, unlike when we first started learning Selenium, the code and script are demonstrated in a class file. We didn't use code refactoring and reuse at all. After the code and use case files are separated, it is clearer, and multiple people develop scripts to facilitate debugging.

       Report and log file output, how many cases you have executed, and the results of the cases, all need to be displayed by reports. Generally, third-party plug-ins are used to achieve this function. Many report formats are html, which is simple and clear. The log output is also very important. If an error occurs, the script execution fails, and the log can quickly locate the problem location.

      用户自定义库,这个很好理解,我们很多功能需要重复调用,这样我们就写成一个公用方法,放到工具包下,每次方便调用,例如浏览器引擎类和basepage.py的封装。

      管理和执行脚本的方式,例如Python中单元测试框架unittest使用率非常高。

      第三方插件,有时候,我们一些功能,需要借助第三方插件,能够更好实现,例如AutoIT,来实现文件上传和下载。还有利用第三方报告插件生成基于html格式的测试报告。

      持续集成,git,svn,ant,maven,jenkins,我们会把这整合到jenkins,达到持续集成,一键执行测试脚本。

根据以上的特点介绍,我大致用以下图来描述一下,一个简单的自动化测试框架,可能包含哪些组成部分。

       框架的简单介绍就到这里,有些人把框架想得太复杂了,框架无非就是一些软件的集合,达到特定的目的。这里我们上图画出来的框架,就是一个简单的自动化测试框架,别笑,这确实是一个简单但又包含必要的组件的自动化测试框架设计实例,如果你学会了这个设计思路和思想,那么,你已经达到了自动化测试第二个阶段的水平:能够简单设计自动化测试框架和维护框架的能力。

如需更多了解和交流,请加QQ群:49044146

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326106874&siteId=291194637