前言
Airtest 生成報告的時候,每個不走都會自動帶上截圖,也可以自己添加截圖,使用 snapshot()方法
snapshot 方法使用
對目標設備進行一次截圖,並且保存到文件中。
參數:
- filename – 保存截圖的文件名,默認保存路徑為
ST.LOG_DIR
中 - msg – 截圖文件的簡短描述,將會被顯示在報告頁面中
- quality – 圖片的質量,[1,99]的整數,默認是10
- max_size – 圖片的最大尺寸,例如 1200
返回: 截圖文件的絕對路徑
支持平台: Android, iOS, Windows
示例:
>>> snapshot(msg="index")
>>> # save the screenshot to test.jpg
>>> snapshot(filename="test.png", msg="test")
可以設置截圖的畫質和大小
>>> # Set the screenshot quality to 30
>>> ST.SNAPSHOT_QUALITY = 30
>>> # Set the screenshot size not to exceed 600*600
>>> # if not set, the default size is the original image size
>>> ST.IMAGE_MAXSIZE = 600
>>> # The quality of the screenshot is 30, and the size does not exceed 600*600
>>> touch((100, 100))
>>> # The quality of the screenshot of this sentence is 90
>>> snapshot(filename="test.png", msg="test", quality=90)
>>> # The quality of the screenshot is 90, and the size does not exceed 1200*1200
>>> snapshot(filename="test2.png", msg="test", quality=90, max_size=1200)
截圖使用
點 app 啟動圖標,啟動后 sleep 5秒,對 app 屏幕截圖
查看報告,顯示截圖