pytest+selenium+allure Marco simple de automatización de Webui
introducir
Marco de automatización fácil.
Arquitectura de software
pytest5.4.2
selenio3.141.0
encanto_python_commons2.8.29
PyYAML5.4.1
pitón == 3.6.0
Instalación de dependencia
使用 pip install -r requisitos.txt
Agregue un método para actualizar y descargar automáticamente Chromedriver
La estructura es la siguiente:
Check_driver Consulta la versión del controlador instalado
descripción del código
import requests
import re
import os
from Update_driver.Download import Download_dev
class Check_Driver(Download_dev):
def query_driver_version(self,url):
'''查询最新的Chromedriver版本'''
rep = requests.get(url).text
time_list = [] # 用来存放版本时间
time_version_dict = {
} # 用来存放版本与时间对应关系
result = re.compile(r'\d.*?/</a>.*?Z').findall(rep) # 匹配文件夹(版本号)和时间
for i in result:
time = i[-24:-1] # 提取时间
version = re.compile(r'.*?/').findall(i)[0] # 提取版本号
time_version_dict[time] = version # 构建时间和版本号的对应关系,形成字典
time_list.append(time) # 形成时间列表
latest_version = time_version_dict[max(time_list)][:-1] # 用最大(新)时间去字典中获取最新的版本号
return latest_version
def query_system_driver_version(self):
'''查询系统内的Chromedriver版本'''
system_version = os.popen('chromedriver --version').read()
return system_version.split(' ')[1]
def get_path(self):
'''查询系统内Chromedriver的存放路径,由于mac不能使用指定bash,只能写死路径,有好的解决方案请赐教'''
system_path = '/usr/local/bin/'
# system_path = os.popen('where chromedriver').read() # windows 可以使用这个方法
return system_path
@staticmethod
def Run_download_driver():
url = 'http://npm.taobao.org/mirrors/chromedriver/'
dev = Check_Driver()
latest_version = dev.query_driver_version(url)
print('最新的chromedriver版本为:', latest_version)
version = dev.query_system_driver_version()
print('当前系统内的Chromedriver版本为:', version)
if version == latest_version:
print('当前系统内的Chromedriver已经是最新的')
else:
print('当前系统内的Chromedriver不是最新的,需要进行更新')
download_url = url + latest_version + '/chromedriver_mac64.zip' # 拼接下载链接,更换下载对应系统的driver名称即可
dev.download_driver(download_url)
path = dev.get_path()
print('替换路径为:', path)
dev.unzip_driver(path)
print('更新后的Chromedriver版本为:', dev.query_system_driver_version())
Descargar Descargar imagen de Chromedriver
import requests
import zipfile
class Download_dev():
def download_driver(self, download_url):
'''下载文件'''
file = requests.get(download_url)
with open("chromedriver.zip", 'wb') as zip_file: # 保存文件到脚本所在目录
zip_file.write(file.content)
print('下载成功')
def unzip_driver(self,path):
'''解压Chromedriver压缩包到指定目录'''
f = zipfile.ZipFile("chromedriver.zip", 'r')
for file in f.namelist():
f.extract(file, path)
ejecutar agrega llamadas, no comentable
from test_run import run_test
from Update_driver import Check_driver
#入口文件
class startest(run_test.RunTest,Check_driver.Check_Driver):
import time
test_data = time
# class sterdown(Check_driver.Check_Driver):
if __name__ == '__main__':
startest.Run_download_driver()#检测chromedriver版本,不需要注释即可
startest.run_alltest()