脚本如下:
# -*- coding:UTF-8 -*-
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import unittest
import time
import HTMLTestRunner
class Dttest(unittest.TestCase):
@classmethod
def setUpClass():
desired_caps={}
desired_caps['platformName']='Android'
desired_caps['platformVersion']='4.4.2'
desired_caps['deviceName']='HUAWEI P7-L00'
desired_caps['appPackage']='com.tuniu.app.ui'
desired_caps['appActivity']='.homepage.LaunchActivity'
driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
def tearDown():
driver.close_app()
driver.quit()
def test_click1():
driver.find_element_by_id('com.tuniu.app.ui:id/iv_style3_card_1').click()
def test_click2():
driver.find_element_by_id('com.tuniu.hotel:id/tv_query').click()
def test_click3():
driver.find_element_by_id('com.tuniu.hotel:id/iv_product_small_image').click()
if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(Dttest('test_click1'))
suite.addTest(Dttest('test_click2'))
suite.addTest(Dttest('test_click3'))
timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
filename = 'D:\\report\\result_'+timestr+'.html'
fp = open(filename,'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='result',
description='report'
)
runner.run(suite)
fp.close()
运行结果报错:
Traceback (most recent call last):
File "D:\appium\workspace\new test\Simple-test.py", line 72, in <module>
runner.run(suite)
File "C:\Python27\lib\HTMLTestRunner.py", line 628, in run
test(result)
File "C:\Python27\lib\unittest\suite.py", line 65, in __call__
return self.run(*args, **kwds)
File "C:\Python27\lib\unittest\suite.py", line 95, in run
self._handleClassSetUp(test, result)
File "C:\Python27\lib\unittest\suite.py", line 146, in _handleClassSetUp
self._addClassOrModuleLevelException(result, e, errorName)
File "C:\Python27\lib\unittest\suite.py", line 187, in _addClassOrModuleLevelException
result.addError(error, sys.exc_info())
File "C:\Python27\lib\HTMLTestRunner.py", line 584, in addError
output = self.complete_output()
File "C:\Python27\lib\HTMLTestRunner.py", line 558, in complete_output
return self.outputBuffer.getvalue()
AttributeError: '_TestResult' object has no attribute 'outputBuffer'
我用的 HTMLTestRunner 是在这里下的: http://tungwaiyip.info/software/HTMLTestRunner.html
python 版本 2.7
求大神解答,急!