自动化测试生成的HTMLTestRunner支持Python3
1.原因是官网的是python2语法写的,看官手动把官网的HTMLTestRunner.py改成python3的语法:
https://pan.baidu.com/s/1dJjKRHch3lNOB5Elf4pe9A (可以直接下载)
# -*- coding:utf-8 -*-
# -*- 以梦为马 不负韶华 -*-
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
import time
import unittest
import HTMLTestRunner
class Test(unittest.TestCase):
def setUp(self):
desired_caps = {
'platformName': 'Android',
'platformVersion': '5.1',
'deviceName': '192.168.56.101:5555',
'appPackage': 'com.tencent.mm',
'appActivity': '.ui.LauncherUI',
'automationName': 'Appium',
# 'unicodeKeyboard': True,
# 'resetKeyboard': True,
'noReset': True,
'chromeOptions': {'androidProcess': 'com.tencent.mm:appbrand0'}
}
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
print('回话已创建')
self.driver.implicitly_wait(30)
def test_open(self):
def swipeDown(driver, t=500, n=1):
'''向下滑动屏幕'''
l = driver.get_window_size()
x1 = l['width'] * 0.5 # x坐标
y1 = l['height'] * 0.25 # 起始y坐标
y2 = l['height'] * 0.75 # 终点y坐标
for i in range(n):
driver.swipe(x1, y1, x1, y2, t)
# 向下滑动
swipeDown(self.driver)
time.sleep(5)
# 点开小程序
self.driver.find_elements_by_id("com.tencent.mm:id/uk")[0].click()
time.sleep(4)
print(self.driver.contexts)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
#定义一个测试容器
suite = unittest.TestSuite()
#将测试用例,加入到测试容器中
suite.addTest(Test("test_open"))
#现在的时间
now = time.strftime("%Y-%m-%d %H_%M_%S")
#测试报告添加到上级目录下的Reports文件中中
filename = '../Reports\\'+ now +'result.html'
fp = open(filename,'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title='测试报告',description='用例执行情况:')
runner.run(suite)
fp.close()#关闭报告文件