zoukankan      html  css  js  c++  java
  • 截图方法get_screenshot_as_file()注意点

    def img_screenshot(self,Image_name):
        try:
           self.driver.get_screenshot_as_file('D:\workspace\thinksns\result\screenshot\fail\'+Image_name+'.jpg')
        except:
           self.log.error(u'截图失败:')

    get_screenshot_as_file()如上述代码所示,截图保存的路径必须为绝对路径,如果上述写为相对路径截图会失败哦!切记

    如果我们想在截的图名字上加上时间可以如下:

        def img_screenshot(self,Image_name):
            try:
                now = time.strftime('%Y-%m-%d_%H-%M-%S') #截图的方法中不允许存在以下符号 / : * ? # ” < > |
                self.driver.get_screenshot_as_file('D:\workspace\thinksns\result\screenshot\fail\'+Image_name+now+'.png') #这里路径必须为绝对路径不然截图失败
            except:
                self.log.error(u'截图失败:')
    原本方法是这样写的time.strftime('%Y-%m-%d_%H:%M:%S') 但是因为截图的方法中不允许存在以下符号 / : * ? # ” < > |不然截图失败,所以只能将:改为-
    墨者看遍天下皆是丹青,测试看尽万物皆是bug
  • 相关阅读:
    [C#1] 2类型基础
    [C#2] 5迭代器
    [C#1] 6方法
    [C#1] 8数组
    [C#1] 12特性
    [C#1] 10事件
    [C#2] 2匿名方法
    实用代码JavaScript实用小函数一枚(深入对象取值)
    [C#1] 11接口
    实用代码C#获取本机网络适配器信息及MAC地址
  • 原文地址:https://www.cnblogs.com/striver-dl/p/14083594.html
Copyright © 2011-2022 走看看