How to run BrowserMob Proxy with RobotFramework and Capture HAR files

三世轮回 提交于 2019-12-13 12:44:49

问题


I have written this code in robotframework

${proxy}=            |  Evaluate |  sys.modules['selenium.webdriver'].Proxy()   sys, selenium.webdriver | 
${proxy.http_proxy}= |  Set Variable           |    127.0.0.1:8080   | 
Create Webdriver     |  Firefox proxy=${proxy} |     
Go To                |  http://www.knowledgefarm.in/tst/a.html | 

And I am running BrowserMob proxy from command line like this:

browsermob-proxy.bat --address 127.0.0.1 --port 8080

Now, when i run robotframework, it open the browser and simple give this message on page.

HTTP ERROR: 404

Problem accessing /tst/a.html. Reason:
Not Found
Powered by Jetty:// 

Two questions:

  1. why my pages are not loaded. (it works if I remove proxy setting)

  2. After the workaround, how do I specify to generate HAR file and how should I specify the location of HAR file


回答1:


The above code does not actually start a proxy. To start a proxy, you need to run these commands.

Create     | http context    |  localhost:8080 |    http    
Post       | /proxy     
${json} | Get Response Body     
${port}    | Get Json Value  | ${json} | /port
${proxy}=  | Evaluate           | sys.modules['selenium.webdriver'].Proxy()  | sys,selenium.webdriver
${proxy.http_proxy}= |  Set Variable |  127.0.0.1:${port}   
Create Webdriver     | Firefox   | proxy=${proxy}   
Go To      | ${LOGIN URL}   

Set Request Body | pageRef=LOGIN&captureContent=false&captureHeaders=true       
PUT        | /proxy/${port}/har 
${json} | HttpLibrary.HTTP.Get Response Body        
OperatingSystem.Create File | D:\\myfile.har  | ${json} 


来源:https://stackoverflow.com/questions/35474500/how-to-run-browsermob-proxy-with-robotframework-and-capture-har-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!