python selenium截图_python+selenium截图操作样例
# -*- coding:utf-8 -*-
# explain : 截图操作
import os, time
class Picture:
"""
截图操作
分为正常的操作截图truepicture
和异常的操作截图errorpicture
"""
def __init__(self, driver, path):
"""
:type driver: selenium.webdriver.remote.webdriver.WebDriver
:param driver WebDriver对象
:param path 截图存放位置
"""
self.__driver = driver
self.__path = path
def __picturelocation(self):
# path = Primary.readini.getvalue("picture", "picturelocation")
path = self.__path
if not os.path.exists(path): # 判断图片位置是否存在,不存在则先创建
os.makedirs(path)
picdatetime = time.strftime("%Y-%m-%d", time.localtime()) # 文件名为日期
# 正确图片目录
turepath = os.path.join(path, picdatetime + '/turepicture') # 正确图片位置
if not os.path.exists(turepath):
os.makedirs(turepath)
# 错误图片目录
errorpath = os.path.join(path, picdatetime + '/errorpicture') # 错误图片位置
if not os.path.exists(errorpath):
os.makedirs(errorpath)
return [turepath, errorpath]
def truepicture(self, picusername):
"""
正常操作的截图
文件的保存位置在配置文件的turepicture
:param picusername: 图片的文件名称
"""
turepath = self.__picturelocation()[0]
# 通过路径来拼接图片存放路径
self.__driver.get_screenshot_as_file(turepath + os.sep + picusername +
time.strftime("%Y-%m-%d%H%M", time.localtime()) + '.png')
def errorpicture(self, picusername):
"""
出现错误的截图操作
文件的保存位置在配置文件的errorpicture
:param picusername: 图片的文件名称
"""
# 通过路径来拼接图片存放路径
errorpath = self.__picturelocation()[1]
# 截图
self.__driver.get_screenshot_as_file(errorpath + os.sep + picusername +
time.strftime("%Y-%m-%d%H%M", time.localtime()) + '.png')
UI自动化截图操作简单样例
python selenium截图_python+selenium截图操作样例相关推荐
- C# 多线程操作样例
C# 多线程操作样例 using System; using System.Threading; //引用多线程namespace ThreadTest {public class Alpha{pub ...
- python测试脚本截图_Python+selenium实现截图图片并保存截取的图片
这篇文章介绍如何利用Selenium的方法进行截图,在测试过程中,是有必要截图,特别是遇到错误的时候进行截图.在selenium for Python中主要有三个截图方法,我们挑选其中最常用的一种. ...
- python selenium自动化_python selenium自动化之-环境搭建
安装python和pip上述文章有介绍,在这里不在赘述.直接安装seleinum pip3 install selenium 安装完成以后, pip3 show selenium 显示 Name: s ...
- python自动化简历_python+selenium实现简历自动刷新的示例代码
本文用到的文件的下载地址 百度网盘链接: https://pan.baidu.com/s/1tmpdEfAZKff5TOMAitUXqQ 提取码: e6at 1 安装Python 和 selenium ...
- python页面切换_Python+Selenium学习--窗口切换及操作元素
场景 有时候我们在测试一个web 应用时会出现多个浏览器窗口的情况,在selenium1.0 中这个问题比较难处理.webdriver 提供了相关相方法可以很轻松的在多个窗口之间切换并操作不同窗口上的 ...
- python selenium语法_Python+Selenium基本语法
对Selenium自动化已有了解,最近开始做h5端的自动化,所以总结了下Python+Selenium自动化基本语法 一.启动浏览器 1.普通方式启动 #coding=utf-8 importtime ...
- python自动化测试登录_Python selenium自动化测试框架入门实战--登录测试案例
本文为Python自动化测试框架基础入门篇,主要帮助会写基本selenium测试代码又没有规划的同仁. 本文应用到POM模型.selenium.unittest框架.configparser配置文件. ...
- python自动评论_Python+selenium自动评价器
Python+selenium自动评价器 年年岁岁又一年,为了纪念一哈2020年的最后一天,我决定写下这篇文章.你问我为什么要纪念?因为那天我女朋友加班了...,具体什么任务呢?就是一个指标任务,需要 ...
- python 无头模式_Python + Selenium(二十五)无头模式 headless
所谓浏览器的无头模式headless,就是浏览器在运行时处于后台操作的模式,不会看到浏览器打开,也就不会干扰你手头的工作.对于自动化测试和网络爬虫都有很大的价值. 早期我们使用 phantomJS 浏 ...
最新文章
- hung_task_timeout_secs和blocked for more than 120 seconds的解决方法
- st edmunds和emmanuel college
- 提高 webpack 构建 Vue 项目的速度
- winform 线程监听两个目录下的文件_vb.net 利用.net自带的GZipStream压缩或者解压文件的代码,不需要任何第三方控件...
- union intersect minus
- Unity3D-协同程序
- c++字符数组整数转换中文大写金额的形式_如何对PHP日期数组进行排序
- Windows Server 2003 AD域升级至Windows Server 2008 R2实战案例
- 2016.01.18 UILabel
- 大华ITC215WEB相机常用功能设置说明
- matlab 平滑曲线连接_兔学 | MATLAB由离散数据点绘制曲线图像
- 幸运红包娱乐微信小程序源码下载-多玩法安装简单
- 世纪难题相关问题被证明!?——黎曼猜想的前后今生
- 7-24 猜数字游戏 (15分)
- 网页全屏的代码实现要不要了解一下(最全)
- 【USB描述符系列】二维码扫描枪
- python实现提取视频里的语音转换为文字
- 网络安全基础(十四)
- fasterRCNN系列
- 影像的滑动窗口裁切与拼接(附代码)
热门文章
- c# uri.host_C#| Uri.HostNameType属性与示例
- Pyalgotrade量化交易回测框架
- SimpleITK使用深度学习识别肺癌CT DICOM数据集
- openssl rsa密钥
- shiro整合mybatis数据库
- CentOS 7.3镜像挂载搭建本地yum源
- js十秒没有点击怎么判断_MAC口红怎么判断真假?没批号就没有生产日期,网友:品控太差...
- php实现文本替换,php 如何实现文字替换
- 上位机与1200组态步骤_西门子1200的HSC的应用实例!
- 鸿蒙手机是个噱头,华为鸿蒙不是谈判噱头 必要时会应用手机当中!