zoukankan      html  css  js  c++  java
  • 【python】UI自动化-新版

    1、commom·公共配置,

    【1】包含common1·公共方法、

    from webdriver_manager.chrome import ChromeDriverManager
    from seleniumwire import webdriver
    import xlrd

    class common2:


    def __init__(self):
    #调用webdeiver
    self.driver=webdriver.Chrome(ChromeDriverManager().install())


    def set_header(self, request):
    #添加header
    request.headers['***']='***'


    def URL(self):
    #调用系统地址
    return "https://"

    def login(self):
    #调试窗口大小、设置隐式等待、添加herder
    self.driver.maximize_window()
    self.driver.implicitly_wait(10)
    self.driver.request_interceptor = self.set_header
    self.driver.get(self.URL())
    #调用cookie
    wb=xlrd.open_workbook('cookie.xlsx')
    sheel=wb.sheet_by_name('sheet1')
    for row in range(1,sheel.nrows):
    self.driver.add_cookie({'name':sheel.cell_value(row,0),'value':sheel.cell_value(row,1),'domain':sheel.cell_value(row,2),'path':sheel.cell_value(row,3)})
    #刷新页面
    self.driver.refresh()
    return self.driver

    【2】cookie·登陆跳过验证获取、

    import time
    import xlwt
    from webdriver_manager.chrome import ChromeDriverManager
    from seleniumwire import webdriver

    #前置部署
    driver=webdriver.Chrome(ChromeDriverManager().install())
    driver.implicitly_wait(10)
    driver.get("https://")
    #30秒时间手动登陆够不够
    time.sleep(60)
    #把新生成的cookie写入xlsx
    workbook=xlwt.Workbook(encoding='utf-8')
    worksheet=workbook.add_sheet('sheet1')
    worksheet.write(0,0,'name')
    worksheet.write(0,1,'value')
    worksheet.write(0,2,'domain')
    worksheet.write(0,3,'path')
    i=1
    for cookie in driver.get_cookies():
    worksheet.write(i,0,cookie['name'])
    worksheet.write(i,1,cookie['value'])
    worksheet.write(i,2,cookie['domain'])
    worksheet.write(i,3,cookie['path'])
    i=i+1
    workbook.save('cookie.xlsx')
    #退出页面
    driver.quit()

    【3】HTMLTestReportCN·网页版测试报告

    2、reports·存放测试报告

    3、testcases·存放测试用例

    4、run_all_cases.py·执行所有测试用例并保存测试报告到reports

    import os
    import unittest
    from common import HTMLTestReportCN

    #导入所有case
    case_path=os.path.dirname(__file__)+'/testcases/'
    discover=unittest.defaultTestLoader.discover(start_dir=case_path,pattern='test_*.py',top_level_dir=case_path)
    all_case_suite=unittest.TestSuite()
    all_case_suite.addTest(discover)

    #把运行结果导入文件中
    report_path=os.path.dirname(__file__)+'/reports/'
    reports_dir=HTMLTestReportCN.ReportDirectory(report_path)
    reports_dir.create_dir('***自动化测试项目')
    report_html_path=HTMLTestReportCN.GlobalMsg.get_value('report_path')
    html_report_file=open(report_html_path,'wb')
    test_runner=HTMLTestReportCN.HTMLTestRunner(stream=html_report_file,title='***自动化测试项目',description='testV1.0',tester='老拐')
    test_runner.run(all_case_suite)
  • 相关阅读:
    bzoj 1025: [SCOI2009]游戏【数学+dp】
    bzoj 1195: [HNOI2006]最短母串【状压dp】
    洛谷 P1083 借教室【二分+差分/线段树】
    bzoj 2151: 种树【贪心+堆】
    bzoj 1055: [HAOI2008]玩具取名【区间dp】
    bzoj 2152: 聪聪可可【点分治】
    bzoj 4552: [Tjoi2016&Heoi2016]排序【二分+线段树】
    bzoj 1103: [POI2007]大都市meg【dfs序+树状数组】
    bzoj 3751: [NOIP2014]解方程【数学】
    bzoj 3612: [Heoi2014]平衡【整数划分dp】
  • 原文地址:https://www.cnblogs.com/luoguoxing/p/14914792.html
Copyright © 2011-2022 走看看