原标题:自制快速冒烟测试小工具--基于python多线程(2)
新书
速递
文 |愈知愈无知
快速冒烟测试小工具-(1)分析及准备
三、代码实现-封装
1. 创建包和文件夹目录
Config:存放配置文件
Driver:存放不同浏览器驱动
TestResults:存放测试结果
Tests:存放程序脚本
Util:存放封装方法
2. 将所需用到目录及文件路径单独整理
ProjVar.py
1importos
2proj_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3conf_path = os.path.join(proj_path,"config")
4dbuser_ini_path = os.path.join(proj_path,"config","DbUser.ini")
5objectmap_ini_path = os.path.join(proj_path,"config","UiObjectMap.ini")
6driver_path = os.path.join(proj_path,"Driver")
7logger_path = os.path.join(proj_path,"config","Logger.conf")
8result_path = os.path.join(proj_path,"Testresults")
9test_path = os.path.join(proj_path,"Tests")
3. 从ini配置文件读取数据方法
ReadConfig.py
1# encoding=utf-8
2importconfigparser
3importos
4importplatform
5fromConfig.ProjVar import*
6
7defread_ini_file(ini_file_path, section_name, option_name):
8#创建一个读取配置文件的实例
9cf = configparser.ConfigParser
10#将配置文件内容加载到内存
11cf.read(ini_file_path)
12try:
13#根据section和option获取配置文件中的数据
14value = cf.get(section_name, option_name)
15except:
16print( "the specific seciton or the specific option doesn't e