测试开发Web-UI自动化-selenium

H5-UI自动化实现

2021-08-18  本文已影响0人  沈宥
H5AutoRun.png F102E18F-D532-4CED-B995-53D5C78382E3.png

一、ChromeDriver配置

1、指定使用本地文件

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

2、配置手机机型
    mobileEmulation = {'deviceName':'iPhone X'}
    options.add_experimental_option('mobileEmulation', mobileEmulation)
    driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
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可配置的机型枚举:

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、使用
    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、拆分失败用例详情
# 错误用例信息
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>中直接引用

<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>

四、效果图

F102E18F-D532-4CED-B995-53D5C78382E3.png
上一篇下一篇

猜你喜欢

热点阅读