*** Settings ***
Library Selenium2Library
Library Collections
Library OperatingSystem
Library BrowserMobProxyLibrary
*** Variables ***
${PAGE_URL} https://www.google.com
${BROWSER} Chrome
*** Keywords ***
Start Browser
Set Selenium Implicit Wait 10
Start Local Server ${CURDIR}/DownloadFiles/browsermob-proxy.bat options={'port': 8090}
${BrowserMob_Proxy}= create proxy
open browser ${PAGE_URL} ${BROWSER} ${BrowserMob_Proxy} executable_path=${CURDIR}/DownloadFiles/chromedriver.exe
Close Browsers
Close All Browsers
Stop Local Server
*** Test Cases ***
Check something
[Documentation] Check the page title
Start Browser
#Go to ${PAGE_URL}
New Har google
${har}= get har as json
create file C:/har/file.har ${har}
log to console ${har}
log to console Browsermob Proxy HAR file saved as C:/har/file.har
Close Browsers
The output I am getting is : "log": {"version": "1.2", "creator": {"name": "BrowserMob Proxy", "version": "2.1.4", "comment": ""}, "pages": [{"id": "google", "startedDateTime": "2023-03-23T11:36:57.997+05:30", "title": "google", "pageTimings": {"comment": ""}, "comment": ""}], "entries": [], "comment": ""}}
It doesn’t have any entry here. Can someone please help me here what am I missing.
I wasn’t aware of BrowserMobProxyLibrary, so thank you
If I was to guess, it’s because the browser didn’t do anything while between creating the har and saving it, maybe open the browser on a blank page, create the har, navigate to the url and then save the har, something like this:
*** Settings ***
Library Selenium2Library
Library Collections
Library OperatingSystem
Library BrowserMobProxyLibrary
*** Variables ***
${PAGE_URL} https://www.google.com
${BROWSER} Chrome
*** Keywords ***
Start Browser
Set Selenium Implicit Wait 10
Start Local Server ${CURDIR}/DownloadFiles/browsermob-proxy.bat options={'port': 8090}
${BrowserMob_Proxy}= create proxy
open browser about:blank ${BROWSER} ${BrowserMob_Proxy} executable_path=${CURDIR}/DownloadFiles/chromedriver.exe
Close Browsers
Close All Browsers
Stop Local Server
*** Test Cases ***
Check something
[Documentation] Check the page title
Start Browser
New Har google
Go to ${PAGE_URL}
${har}= get har as json
create file C:/har/file.har ${har}
log to console ${har}
log to console Browsermob Proxy HAR file saved as C:/har/file.har
Close Browsers
My first guess was without looking at the documentation, seems I was right about the need to do the browser activity between New Har and get har as json.
But now your problem seems to be related to the proxy settings in this line:
open browser about:blank ${BROWSER} ${BrowserMob_Proxy} executable_path=${CURDIR}/DownloadFiles/chromedriver.exe
I’m not sure how you set the proxy settings for open browser, but i think its a value you add to options, it’s been a few years since I did it last.
I’d suggest you just start by following the basic example they provide, get that working first, then change just the browser, if it’s still working change 1 thing at a time till you get it doing what you want.
I’m not really sure what the difference between open browser and Create Webdriver is but the do appear to have very different arguments, so you can’t just substitute one for the other, you’ll need to make sure you structure the arguments correctly to ensure the browser uses the proxy that BrowserMobProxyLibrary creates