前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >H5-UI自动化实现

H5-UI自动化实现

作者头像
沈宥
发布2022-05-10 13:55:22
5790
发布2022-05-10 13:55:22
举报
文章被收录于专栏:从头开始学习测试开发

一、ChromeDriver配置

1、指定使用本地文件

官网:https://chromedriver.chromium.org/downloads 国内:https://npm.taobao.org/mirrors/chromedriver/ 将文件拖入项目中: driver_path = BASEDIRPATH + '/chromedriver'

2、配置手机机型
  • 通过机型名称指定
代码语言:javascript
复制
    mobileEmulation = {'deviceName':'iPhone X'}
    options.add_experimental_option('mobileEmulation', mobileEmulation)
    driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
  • 直接限制分辨率
代码语言:javascript
复制
mobile_emulation = {
   "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
   "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" 
}
chrome_options = Options()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

mobileEmulation可配置的机型枚举:

代码语言:javascript
复制
mobile_emulation = { 
            #"deviceName": "Apple iPhone 3GS"
            #"deviceName": "Apple iPhone 4"
            #"deviceName": "Apple iPhone 5"
            #"deviceName": "Apple iPhone 6"
            #"deviceName": "Apple iPhone 6 Plus"
            #"deviceName": "BlackBerry Z10"
            #"deviceName": "BlackBerry Z30"
            #"deviceName": "Google Nexus 4"
            "deviceName": "Google Nexus 5"
            #"deviceName": "Google Nexus S"
            #"deviceName": "HTC Evo, Touch HD, Desire HD, Desire"
            #"deviceName": "HTC One X, EVO LTE"
            #"deviceName": "HTC Sensation, Evo 3D"
            #"deviceName": "LG Optimus 2X, Optimus 3D, Optimus Black"
            #"deviceName": "LG Optimus G"
            #"deviceName": "LG Optimus LTE, Optimus 4X HD" 
            #"deviceName": "LG Optimus One"
            #"deviceName": "Motorola Defy, Droid, Droid X, Milestone"
            #"deviceName": "Motorola Droid 3, Droid 4, Droid Razr, Atrix 4G, Atrix 2"
            #"deviceName": "Motorola Droid Razr HD"
            #"deviceName": "Nokia C5, C6, C7, N97, N8, X7"
            #"deviceName": "Nokia Lumia 7X0, Lumia 8XX, Lumia 900, N800, N810, N900"
            #"deviceName": "Samsung Galaxy Note 3"
            #"deviceName": "Samsung Galaxy Note II"
            #"deviceName": "Samsung Galaxy Note"
            #"deviceName": "Samsung Galaxy S III, Galaxy Nexus"
            #"deviceName": "Samsung Galaxy S, S II, W"
            #"deviceName": "Samsung Galaxy S4"
            #"deviceName": "Sony Xperia S, Ion"
            #"deviceName": "Sony Xperia Sola, U"
            #"deviceName": "Sony Xperia Z, Z1"
            #"deviceName": "Amazon Kindle Fire HDX 7″"
            #"deviceName": "Amazon Kindle Fire HDX 8.9″"
            #"deviceName": "Amazon Kindle Fire (First Generation)"
            #"deviceName": "Apple iPad 1 / 2 / iPad Mini"
            #"deviceName": "Apple iPad 3 / 4"
            #"deviceName": "BlackBerry PlayBook"
            #"deviceName": "Google Nexus 10"
            #"deviceName": "Google Nexus 7 2"
            #"deviceName": "Google Nexus 7"
            #"deviceName": "Motorola Xoom, Xyboard"
            #"deviceName": "Samsung Galaxy Tab 7.7, 8.9, 10.1"
            #"deviceName": "Samsung Galaxy Tab"
            #"deviceName": "Notebook with touch"
            
            # Or specify a specific build using the following two arguments
            #"deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
            #"userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
        }

二、测试报告:BeautifulReport

1、安装

pip install BeautifulReport

2、使用
代码语言:javascript
复制
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite('unittest class_name'))
    myapp.run.ReportDiscover(suite, sys.argv[2])
    result = BeautifulReport(suite)
    result.report(filename=case.run_file, description=case.case_name, log_path='',report_dir=os.path.join('项目目录', 'templates/'))
3、拆分失败用例详情
代码语言:javascript
复制
# 错误用例信息
def FailReportInfo(result_list):
    """
    :param result_list:
    :return:
    """
    errors_case_list = []
    for case_info in result_list:
        case_info_list = list(case_info)
        test_status = case_info_list[4]
        if test_status == '错误' or test_status == '失败':
            class_name = case_info_list[0]
            test_name = case_info_list[1]
            case_name = case_info_list[2]
            fail_info = case_info_list[5]
            error_case_info = {'class_name': class_name, 'test_name': test_name, 'case_name': case_name,
                               'fail_info': fail_info}
            errors_case_list.append(error_case_info)
        else:
            continue

三、静态模板

1、主题列表

https://bootswatch.com/

2、下载bootstrap.css文件

移动到项目static/bootstrap-xxx-dist/css

3、如何引用

在模板文件(templates/xxx.html)的<head>中直接引用

代码语言:javascript
复制
<link href="/static/bootstrap-x.x.x-dist/css/bootstrap.min.css" rel="stylesheet">
    <![endif]-->
    <script src="/static/bootstrap-x.x.x-dist/jquery-3.6.0.min.js"></script>
    <script src="/static/bootstrap-x.x.x-dist/js/bootstrap.js"></script>
    <script src="/static/bootstrap-x.x.x-dist/js/bootstrap.min.js"></script>

四、效果图

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-01-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从头开始学习测试开发 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、ChromeDriver配置
  • 二、测试报告:BeautifulReport
  • 三、静态模板
  • 四、效果图
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档