H5AutoRun.png
F102E18F-D532-4CED-B995-53D5C78382E3.png
一绸罗、ChromeDriver配置
1爱咬、指定使用本地文件
官網(wǎng):https://chromedriver.chromium.org/downloads
國內(nèi):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
三镇草、靜態(tài)模板
1眶痰、主題列表
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