查到一个资料:

是使用装饰器来进行截图操作的

https://testerhome.com/topics/8883

先记录一下:

可以使用装饰器:

def getImage(function):
@wraps(function)
def get_ErrImage(self,*args, **kwargs):
try:
result = function(self,*args, **kwargs)
except:
timestr = time.strftime("%Y-%m-%d_%H_%M_%S")
self.dr.get_screenshot_as_file('E:\\Appium\\Mailchat\\image\\getscreen\\%s %s.png' %
(function.__name__timestr))
else:
logging.info (" %s 脚本运行正常" %
(function.__name__)
)
return result
return get_ErrImage

 

使用:

class myInitiate_addOppionTest(unittest.TestCase):

def setUp(self):
public.setUp.setUp(self)

def tearDown(self):
self.dr.quit()

@getImage
def test_myInitiate_addOppion(self):
go_loginPage(self) #访问登录页

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(myInitiate_addOppionTest)
unittest.TextTestRunner(verbosity=2).run(suite)
02-14 04:11