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)
  • 相关阅读:
    SQL Server2008中删除重复记录
    Php环境在Windows (server 2003) 服务器部署标准 白丁简明版
    国外服务器鸟文windows,时间12小时制,如何改成24小时呢?我来告诉你
    将Capicom调用代码封装到ActiveX——解决javascript调Capicom读取数字证书信息时,IE弹出安全提示的问题
    Linq处理List数据
    C#将窗口最小化到系统托盘,并显示图标和快捷菜单
    C# 将程序添加到启动项 (写入注册表),及从启动项中删除
    C#中string[]数组和list<string>泛型的相互转换
    IIS7.5部署ASP.NET失败
    IIS 7.5版本中一些诡异问题的解决方案
  • 原文地址:https://www.cnblogs.com/luoguoxing/p/14914792.html
Copyright © 2011-2022 走看看