I tried to capture Network XHR logs (chrome browser) that generally shows Request(MethodType, Headers, parameters) and Response with Selenium webdriver but i was only able to get api's request that client sent to server(without parameter), while searching i found below code and it only provides me apis request:-
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
for (LogEntry entry : logEntries) {
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage())
}
But i want to get also all the parameters that sent by client(browser) to server and also response. *how the same feature will work for firefox.
Thanks in advance!!
You can use browsermobproxy . Following code snippet captures all request and response logs. // start the proxy BrowserMobProxy proxy = new BrowserMobProxyServer(); proxy. start(0); // get the Selenium proxy object Proxy seleniumProxy = ClientUtil.
Selenium can execute JavaScript commands with the help of the execute_script method. JavaScript command to be executed is passed as a parameter to this method. To capture the network traffic, we have to pass the command: return window. performance.
You can use browsermobproxy .
Following code snippet captures all request and response logs.
// start the proxy
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);
// get the Selenium proxy object
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
// start the browser up
WebDriver driver = new FirefoxDriver(capabilities);
// enable more detailed HAR capture, if desired (see CaptureType for the complete list)
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
// create a new HAR with the label "yahoo.com"
proxy.newHar("yahoo.com");
// open yahoo.com
driver.get("http://yahoo.com");
// get the HAR data
Har har = proxy.getHar();
The captured response can be viewed by any har viewer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With