#你也想跟webdriver一样搞出逼格高的测试报告么,appium一样也可以~不说废话了,请看,仔细学习~
#coding=utf-8
import os
import unittest,sys,time,re,datetime,HTMLTestRunner
from appium import webdriver
from time import sleep
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
class ContactsAndroidTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.3'
desired_caps['deviceName'] = '192.168.56.101:5555'
'''desired_caps['app'] = PATH(
'../../../sample-code/apps/ContactManager/ContactManager.apk'
)'''
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator'
self.driver = webdriver.Remote('http://192.168.10.95:4723/wd/hub', desired_caps)
def tearDown(self):
self.driver.close_app()
self.driver.quit()
def test_add_contacts(self):
self.driver.find_element_by_id('com.android.calculator2:id/digit9').click()
if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(ContactsAndroidTests("test_add_contacts"))
#suite.addTest(IposCase("testmaters"))
timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
filename = "D:\\appium\\appiumresult\\result_" + timestr + ".html"
print (filename)
fp = open(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='测试结果',
description='测试报告'
)
#suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
#unittest.TextTestRunner(verbosity=2).run(suite)
runner.run(suite)
#g_browser.quit()
fp.close() #测试报告关闭
最后来看看我们的成果吧~去找到我们存放测试报告的路径~
注:最重要的是下载 HTMLTestRunner.py,放到 python 的 Lib 下
近期,我会梳理一份彩笔自学 appium 的文章出来,我是从零开始自学的,现在带公司的无线测试这个团队,希望能帮到更多的自学者~