【selenium+testng 学习笔记】 失败截图

在web自动化测试时,case执行失败时,提供截图功能,可以通过截取的失败图片,快速发现问题。这里只说明了截图方法,自动化测试中要加上监听器,可以监听用例执行失败时进行截图

通过 getScreenshotAs 方法截取图片

public void TakeScreenShot(){

        //获取时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");//格式化类对象
        String curTime = sdf.format(new Date());格式化当前时间
        //获取类名
        String  curClassName = this.getClass().getName();
        //存放路径
        String curPath = System.getProperty("user.dir");
        String pngPath = curClassName+"_"+curTime+".png";

        //截取图片
        File ScrPng = ((RemoteWebDriver) driver).getScreenshotAs(OutputType.FILE);
        try {
            Files.copy(ScrPng,new File(curPath+"/"+pngPath));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
getScreenshotAs源码
public &
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值