python怎么输出图像测试_appium 中输出的测试报告加上执行异常的截图问题,请教!(Python)...

class take_screen_shot(): #这个类将在下面作为装饰器使用

def __init__(self, func):

self.func = func

self.name = func.__name__ + ' (error).png' #拼接截图文件名

def __call__(self, *args): #对每次调用的函数都做截图操作

try:

self.func(self, *args)

except Exception as msg:

pic=self.driver.get_screenshot_as_file('C:\\Users\\zhengtao\\Desktop\\pic\\'+self.name)

return pic

raise msg

class HotelBook(unittest.TestCase):

@classmethod

def setUpClass(self):

desired_caps={}

desired_caps['platformName']='Android'

desired_caps['platformVersion']='6.0.1'

desired_caps['deviceName']='MI NOTE LTE'

desired_caps['appPackage']='com.tuniu.app.ui'

desired_caps['appActivity']='.homepage.LaunchActivity'

desired_caps['unicodeKeyboard']=True

desired_caps['resetKeyboard']=True

self.driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)

self.driver.implicitly_wait(10)

@take_screen_shot

def simpletest(self):

self.driver.find_element_by_id('com.tuniu.app.ui:id/iv_style3_card_1').click()

self.driver.find_element_by_id('com.tuniu.hotel:id/tv_query222').click()

if __name__ == '__main__':

suite = unittest.TestSuite()

suite.addTest(HotelBook('simpletest'))

timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))

filename = 'D:\\report\\HotelBook_result_'+timestr+'.html'

fp = open(filename,'wb')

runner = HTMLTestReportCN.HTMLTestRunner(

stream=fp,

title='HotelBook测试报告',

description='HotelBook测试报告',

tester='测试'

)

runner.run(suite)

fp.close()

下面是我的HTML测试报告输出的部分代码

%(status)s

 
  

%(script)s

代码执错误信息:

ETraceback (most recent call last):

File "D:\appium\workspace\newtest\AppRegressionTest\ForTest\pic.py", line 83, in

runner.run(suite)

File "C:\Users\zhengtao\AppData\Local\Programs\Python\Python35\lib\HTMLTestReportCN.py", line 574, in run

self.generateReport(test, result)

File "C:\Users\zhengtao\AppData\Local\Programs\Python\Python35\lib\HTMLTestReportCN.py", line 624, in generateReport

report = self._generate_report(result)

File "C:\Users\zhengtao\AppData\Local\Programs\Python\Python35\lib\HTMLTestReportCN.py", line 689, in _generate_report

self._generate_report_test(rows, cid, tid, n, t, o, e)

File "C:\Users\zhengtao\AppData\Local\Programs\Python\Python35\lib\HTMLTestReportCN.py", line 740, in _generate_report_test

status = self.STATUS[n],

KeyError: 'pic'

我是python初学者,请问我这样写的输出截图的代码问题原因在哪里?

或者各位前辈有比较好的测试报告带截图的方法,可以借小弟借鉴一下呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值