本文介绍了如何使用RobotFramework运行BrowserMob代理并捕获HAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在robotframework中编写了这段代码
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 |
我正在这样从命令行运行BrowserMob代理:
And I am running BrowserMob proxy from command line like this:
browsermob-proxy.bat --address 127.0.0.1 --port 8080
现在,当我运行robotframework时,它会打开浏览器并在页面上简单显示此消息。
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://
两个问题:
-
为什么我的页面未加载。 (如果删除代理设置,则可以使用)
why my pages are not loaded. (it works if I remove proxy setting)
解决方法之后,如何指定生成HAR文件以及如何指定HAR文件的位置
After the workaround, how do I specify to generate HAR file and how should I specify the location of HAR file
推荐答案
上面的代码实际上并未启动代理。要启动代理,您需要运行以下命令。
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}
这篇关于如何使用RobotFramework运行BrowserMob代理并捕获HAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!