• 解决手工测试兼容浏览器重复工作


    问题点:每次做兼容页面测试,都需要打开浏览器一个一个查看,实在麻烦,其实可以启动浏览器,截下每张图,根据图片就比较了,不用一个一个浏览器打开在手动输入网址查看:

    实现点:

    1 在 ie chrome firefox 三种浏览器下
    2 分别截图 baidu sogou youdao
    3 保存在当前日期的目录下,方便查看,名称为浏览器名称和网站名称
    4 网址保存在某个数据文件中,方便直接读取,

    直接上代码:

    from selenium import webdriver
    import time
    import datetime
    import os
    import re
    global pathfile
    def create_time_file(path): #创建文件的方法
        gettime=time.localtime()
        filename=time.strftime('%H-%M-%S',time.localtime(time.time()))
        print u"创建的文件为",filename
        if not os.path.exists(path+filename):  #不存在这个文件,文件为了测试,用的时分秒创建文件名
            os.mkdir(path+filename)
            print u"文件创建成功地址为:",path+filename
        return path+filename
    
    def  create_url_file():
        with open("e:\config.txt","w") as fp:#可写三行,或者一行都行,主要是打开的地址
            fp.write("http://www.sogou.com
    ")
            fp.write("http://www.baidu.com
    ")
            fp.write("http://www.youdao.com
    ")
    
    def capture_browser(browser_name,url):
        if(browser_name=="ie"or browser_name=="IE"):#需要不区分大小写
            driver=webdriver.Ie(executable_path="D:\IEDriverServer")
        elif (browser_name=="chrome"or browser_name=="CHROME"):
            driver = webdriver.Chrome(executable_path = "d:\chromedriver")
        else:  #默认就启动火狐
            driver =webdriver.Firefox(executable_path = "d:\geckodriver")
        driver.get(url)
        
        print u"目前地址为:",os.getcwd()
        os.chdir(pathfile)
        print u"进入创建的目前地址:",os.getcwd()
       
        print u"浏览器为:",browser_name
        #要注意,直接携带http://给文件命名是不规范的,
        pictpath=browser_name+"_"+url[11:16]+".png"#取文件名也可以用正则,re.search(r"http://www.(w+)..*",url).group(1)+".png"
        print u"创建图片名称为:",pictpath
        driver.get_screenshot_as_file(pictpath) #截图
        print u"截图成功关闭浏览器"
        driver.quit()
    
    if __name__=="__main__":
        pathfile=create_time_file("d:\")#创建路径在D盘
        create_url_file()
        browser_namelist=["ie","chrome","firefox"]
        for browser_name in browser_namelist:
            with open("e:\config.txt") as fp:#读取配置文件
                for line in fp:
                    print u"打开地址为:",line
                    url=line.strip()  #删除字符串中开头、结尾处空格
                    capture_browser(browser_name,url)

    日志内容为:

    实现效果:

    只需要对比图片内容就可以发现兼容问题

  • 相关阅读:
    .NetCore Grpc 客服端 工厂模式配置授权
    DOCKER 拉取 dotnet 镜像太慢 docker pull mcr.microsoft.com too slow
    Introducing .NET 5
    VSCode 出现错误 System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached.
    Omnisharp VsCode Attaching to remote processes
    zookeeper3.5.5 centos7 完全分布式 搭建随记
    Hadoop2.7.7 centos7 完全分布式 配置与问题随记
    MySQL索引 索引分类 最左前缀原则 覆盖索引 索引下推 联合索引顺序
    SQL基础随记3 范式 键
    MySQL调优 优化需要考虑哪些方面
  • 原文地址:https://www.cnblogs.com/chongyou/p/6538328.html
Copyright © 2020-2023  润新知