IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发测试 -> How to use browsermob with python-selenium -> 正文阅读

[开发测试]How to use browsermob with python-selenium

BrowserMob Proxy

BrowserMob Proxy?is an open source tools which is used to?capture performance data?for a web applications in an HAR format. It also allows to manipulate browser behavior and traffic, such as simulating network traffic, rewriting HTTP requests and responses etc and manipulate network traffic from their AJAX applications. In short,?BrowserMob proxy?helps us to capture client side performance data for a web application using Selenium WebDriver automated tests.

You can find more details about?BrowserMob Proxy?from the?Python Documentation?and?this tutorial.

Demonstration of BrowserMob Proxy 2.0 with Python client on Windows

  • Install?browsermob-proxy?through the CLI :

    C:\Users\your_user>pip install browsermob-proxy
    Collecting browsermob-proxy
      Downloading browsermob-proxy-0.8.0.tar.gz
    Collecting requests>=2.9.1 (from browsermob-proxy)
      Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
        100% |||||||||||||||||||||||||||||||||| 92kB 148kB/s
    Collecting idna<2.7,>=2.5 (from requests>=2.9.1->browsermob-proxy)
      Downloading idna-2.6-py2.py3-none-any.whl (56kB)
        100% |||||||||||||||||||||||||||||||||| 61kB 639kB/s
    Collecting urllib3<1.23,>=1.21.1 (from requests>=2.9.1->browsermob-proxy)
      Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
        100% |||||||||||||||||||||||||||||||||| 133kB 250kB/s
    Collecting certifi>=2017.4.17 (from requests>=2.9.1->browsermob-proxy)
      Downloading certifi-2017.11.5-py2.py3-none-any.whl (330kB)
        100% |||||||||||||||||||||||||||||||||| 337kB 401kB/s
    Collecting chardet<3.1.0,>=3.0.2 (from requests>=2.9.1->browsermob-proxy)
      Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
        100% |||||||||||||||||||||||||||||||||| 143kB 296kB/s
    Installing collected packages: idna, urllib3, certifi, chardet, requests, browse
    rmob-proxy
      Running setup.py install for browsermob-proxy ... done
    Successfully installed browsermob-proxy-0.8.0 certifi-2017.11.5 chardet-3.0.4 id
    na-2.6 requests-2.18.4 urllib3-1.22
    
  • Download?the?browsermob-proxy?binaries?browsermob-proxy-2.1.4-bin?form the following url :

    https://bmp.lightbody.net/
    
  • Extract?and?Save?the directory within?C:\Utility

  • Launch?the?Browsermobproxy Server?manually through the CLI command :

    C:\Utility\browsermob-proxy-2.1.4\lib>java -jar browsermob-dist-2.1.4.jar --port 9090
    Running BrowserMob Proxy using LittleProxy implementation. To revert to the legacy implementation, run the proxy with the command-line option '--use-littleproxy false'.
    [INFO  2018-01-17T19:01:30,276 net.lightbody.bmp.proxy.Main] (main) Starting BrowserMob Proxy version 2.1.4
    [INFO  2018-01-17T19:01:30,388 org.eclipse.jetty.util.log] (main) jetty-7.x.y-SNAPSHOT
    [INFO  2018-01-17T19:01:30,471 org.eclipse.jetty.util.log] (main) started o.e.j.s.ServletContextHandler{/,null}
    [INFO  2018-01-17T19:01:30,871 org.eclipse.jetty.util.log] (main) Started SelectChannelConnector@0.0.0.0:9090
    
  • You can also launch the?Browsermobproxy Server?through your code as below.

  • Create a new?PyDev?module (if using?Eclipse) and write a basic program through your?IDE?as follows :

    from browsermobproxy import Server
    server = Server("C:\\Utility\\browsermob-proxy-2.1.4\\bin\\browsermob-proxy")
    server.start()
    proxy = server.create_proxy()
    
    from selenium import webdriver
    profile  = webdriver.FirefoxProfile()
    profile.set_proxy(proxy.selenium_proxy())
    driver = webdriver.Firefox(firefox_profile=profile)
    
    
    proxy.new_har("google")
    driver.get("http://www.google.co.in")
    proxy.har # returns a HAR JSON blob
    
    server.stop()
    driver.quit()
    
  • Snapshot :

  • Execute your?Test?as a?Python Run
  • While your?Program?executes you will observe?Firefox Quantum Browser?gets initialized and the?url?http://www.google.co.in?opens up and gets closed at the end of the test.
  • On completion of the?Test Execution?you will find the following files within your work space which will give you all the details of the?Test Execution?:

    bmp.log
    geckodriver.log
    server.log
    
  开发测试 最新文章
pytest系列——allure之生成测试报告(Wind
某大厂软件测试岗一面笔试题+二面问答题面试
iperf 学习笔记
关于Python中使用selenium八大定位方法
【软件测试】为什么提升不了?8年测试总结再
软件测试复习
PHP笔记-Smarty模板引擎的使用
C++Test使用入门
【Java】单元测试
Net core 3.x 获取客户端地址
上一篇文章      下一篇文章      查看所有文章
加:2022-03-15 22:56:38  更:2022-03-15 22:57:43 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/18 0:14:12-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码