赞
踩
python实现截图操作(android、PC)
- def pcScreenShot(saveName,x1=0,y1=0,x2=1920,y2=1080):
- from PIL import ImageGrab
-
- # 参数说明
- # 第一个参数 开始截图的x坐标
- # 第二个参数 开始截图的y坐标
- # 第三个参数 结束截图的x坐标
- # 第四个参数 结束截图的y坐标
- bbox = (x1, y1, x2, y2)
- im = ImageGrab.grab(bbox)
- # 参数 保存截图文件的路径
- print('电脑屏幕截图保存至:{}'.format(saveName))
- im.save(saveName)
- def takeScreenShot(self, pngName0='', count="1", filePath=".\\TestLogs\\"):
- """
- 移动设备屏幕截图,截图文件保存位置可以自定义,如:.\\TestLogs\\SavePng\\201911061135_test_1.png
- :param pngName0: 保存的文件名
- :param count: 保存的文件名中,用于计数的数值
- :param self.folderName: 截图文件的目录,默认为:"\\SavePng"
- :param filePath: 测试文件保存的主目录,默认为:".\\TestLogs"
- :return:
- """
- #
-
- pngName = pngName0.replace(' ', '_').replace('\n', '_').replace('\t', '_')
- takeScreenShot_all_path_0 = str(filePath).strip('\\') + "\\" + getDate('-', 0) + "\\" + self.getDT("", "", "") + "_" + pngName + "_" + str(count) + '.png'
- takeScreenShot_all_path = str(takeScreenShot_all_path_0).replace('.\\TestLogs\\.', '.').replace(r"\\", "\\")
- logging.info('takeScreenShot_all_path={}'.format(takeScreenShot_all_path))
- folderPath = takeScreenShot_all_path(filePath, 0)
-
- if not os.path.exists(folderPath):
- self.logOut("屏幕截图文件夹 {} 不存在,正在重新创建...".format(folderPath))
- os.makedirs(folderPath)
-
- try:
- self.logOut('PowerTest 当前屏幕截图已保存至: {}'.format(takeScreenShot_all_path))
- self.d.screenshot(takeScreenShot_all_path)
- return 1
- except Exception as e:
- self.logOut('PowerTest 当前屏幕截图保存至: {} 失败,错误信息={}...'.format(takeScreenShot_all_path, e))
- return 0
- @ECHO off
-
- set Str=快速截屏至电脑_V2.0_20170829 by HRD
-
- title %Str%
- ECHO.
- ECHO %Str%
- ECHO.
-
- :start
- color 1f
-
- ECHO 等待Android设备插入...
- ECHO.
- ECHO wait-for-device
- ECHO.
- adb wait-for-device
- ECHO.
- ECHO Start...
- ECHO.
- ECHO 已识别到Android设备...
- ECHO.
- ECHO 正在截图中,请稍候...
- ECHO.
- adb shell screencap -p /sdcard/screenshot.png
- ECHO.
- ECHO 正在将截图复制到PC,请稍候...
- ECHO.
- adb pull /sdcard/screenshot.png .\.
-
- adb shell rm /sdcard/screenshot.png
-
- ECHO.
- set/a a=%time:~0,2%,b=a+100
- ECHO 截图文件为: %date:~0,4%%date:~5,2%%date:~8,2%%b:~-2%%time:~3,2%%time:~6,2%.png ,请查看...
-
- ren screenshot.png %date:~0,4%%date:~5,2%%date:~8,2%%b:~-2%%time:~3,2%%time:~6,2%.png
-
-
- goto :eof
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。