In this post, we will learn BrowserMob Proxy Selenium Java test automation. The execution of web pages generally involves three tasks: fetching resources, page layout and rendering, and JavaScript execution. Apart from these, sometimes websites need to track user behaviors so they need many third-party integrations and this may affect page load time. Also, we can have different problems like javascript, instability, etc. We can filter all these things using BroserMob Proxy. We will go over how can we get performance-related data from selenium test scenarios & integrate them with browsermob proxy.
BrowserMob Proxy Outline
- Page Load & Bandwith & Latency Relation
- What is BrowserMob Proxy?
- BrowserMob Features
- What is HAR?
- Creating Profile
- Creating a Selenium project using BrowserMob
- Chrome Developer Tools
Page Load & Bandwidth & Latency Relation
(Picture from High-Performance Browser Networking)
Latency: The time from the source sending a packet to the destination receiving it.
Bandwidth: Maximum throughput of a logical or physical communication path.
What is BrowserMob Proxy?
BrowserMob Proxy is a free tool that supports monitoring and manipulating the network traffic from web applications. You can download it from https://github.com/lightbody/browsermob-proxy
On that page its definition is as follows: BrowserMob Proxy allows you to manipulate HTTP requests and responses, capture HTTP content, and export performance data as a HAR file. BMP works well as a standalone proxy server, but it is especially useful when embedded in Selenium tests.
Features of BrowserMob Proxy
The proxy is programmatically controlled via a REST interface or by being embedded directly inside Java-based programs and unit tests. It captures performance data in the HAR format. In addition, it can actually control HTTP traffic, such as:
- Black-listing and white-listing certain URL patterns
- Simulating various bandwidth and latency
- Remapping DNS lookups
- Flushing DNS caching
- Automatic BASIC authorization
What is HAR?
The HAR format is based on JSON, as described in RFC 4627. Har is an open format for exporting HTTP tracing information called HTTP Archive (HAR). The data is stored as a JSON document.
What kind of information we can get from har file:
- DNS information load time
- Each object requested (load time)
- Connection time to the server
- From server to a browser (load time)
- The object is blocked or not
Some of HAR object types are log, creator, browser, pages, page timings, etc.
We can check har file results using different tools:
- softwareishard (online, installation here)
- Monitoring service
- Developer tools
HAR viewer is a free and open-source (PHP + JavaScript) application, which you can host yourself.
The gem will start a local server and automatically open a browser tab to view the HAR file.
If you go to harviewer website, copy and past your .har file inside & you will get an interactive timeline.
Part of my HAR file created by WebDriver.
{ "log": { "version": "1.2", "creator": { "name": "BrowserMob Proxy", "version": "2.1.0-beta-2-littleproxy", "comment": "" }, "browser": { "name": "Firefox", "version": "44.0", "comment": "" } } }
You can format the file using Notepad++ json viewer plugin, or JSON viewer website, you can get more information about har specification from here.
Create a BrowserMob Proxy Selenium Java Project
You can add this to your pom.xml:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.swtestacademy</groupId> <artifactId>browsermobproxy</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>net.lightbody.bmp</groupId> <artifactId>browsermob-core</artifactId> <version>2.1.5</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>22.0</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> <version>1.8.0-beta0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.20</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.7.1</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.53.1</version> </dependency> </dependencies> </project>
import java.io.File; import java.net.Inet4Address; import lombok.SneakyThrows; import net.lightbody.bmp.BrowserMobProxyServer; import net.lightbody.bmp.client.ClientUtil; import net.lightbody.bmp.core.har.Har; import net.lightbody.bmp.proxy.CaptureType; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestMethodOrder; import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; @TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestMethodOrder(MethodOrderer.MethodName.class) public class BrowserMobProxyExample { WebDriver driver; BrowserMobProxyServer proxy; Proxy seleniumProxy; @SneakyThrows @BeforeAll public void setup() { //Proxy Operations proxy = new BrowserMobProxyServer(); proxy.start(8080); seleniumProxy = ClientUtil.createSeleniumProxy(proxy); String hostIp = Inet4Address.getLocalHost().getHostAddress(); seleniumProxy.setHttpProxy(hostIp + ":" + proxy.getPort()); seleniumProxy.setSslProxy(hostIp + ":" + proxy.getPort()); proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT); System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver"); System.setProperty("webdriver.chrome.whitelistedIps", ""); DesiredCapabilities seleniumCapabilities = new DesiredCapabilities(); seleniumCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy); seleniumCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-web-security"); options.addArguments("--allow-insecure-localhost"); options.addArguments("--ignore-urlfetcher-cert-requests"); driver = new ChromeDriver(seleniumCapabilities); } @SneakyThrows @Test public void browserMobProxyTest() { proxy.newHar("google.com"); driver.get("https://www.google.com"); Thread.sleep(2000); Har har = proxy.getHar(); File harFile = new File("google.har"); har.writeTo(harFile); } @AfterAll public void teardown() { proxy.stop(); driver.quit(); } }
check the location of the har file:
You can check the new browser mob proxy interface and its methods from this link
Chrome Developer Tools
- Copy All as HAR: Copies all resources to the system clipboard as HAR data. A HAR file contains a JSON data structure.
- Save as HAR with Content: Saves all network data to a HAR file along with each page resource.
Chrome Developer Tools, go to the Network tab, and make sure you’ve selected the Preserve log checkbox, otherwise, the log is reset when you change the page.
Unfortunately with the latest selenium versions create problems. I tried all options to fix the problem but I could not. If you find a solution to run BrowserMobProxy with Selenium’s latest versions, please write a comment about that solution or you can create PR in github repo.
GitHub Project
https://github.com/swtestacademy/browsermobproxy
Thanks,
Onur Yazir

Onur YAZIR is a Senior Software Testing & DevOps Engineer 10+ years of experience. He has worked Huawei, Ericsson, Vodafone, Several FinTech companies, Gulf News, and Emirates Airlines. You can find detailed information about him on his linked-in page.
I am using browser-mob with Nightwatch js, Is there any way by which I can start my server directly from my tests?
Yes I got the HAR file but how will I parse it in java??
You may use below options:
– https://toolbox.googleapps.com/apps/har_analyzer/
– http://www.softwareishard.com/blog/har-viewer/
You can try to use these libraries in Java to read HAR file:
https://github.com/sdstoehr/har-reader
https://sites.google.com/site/frogthinkerorg/projects/harlib (introduction to the library)
http://sourceforge.net/projects/benchlab/files/HarLib/
Use Jackson Har reader
I got the har file from browsermob but unable to convert that har file to JMX.
Can you please provide me solution for the same.
Hi Ankit you should write google how to convert har to jmx basically.
Hi Ankit,
This link may help you. https://har.tech/services/har2jmx.html
When I tried convert Har to Jmx through blazemeter then it’s showing me “Fatal error during conversion:
Failed to validate json file SeleniumEasy.har: check file format”.
Also getting below error logs:
2017/04/25 04:40:08 INFO – com.blazemeter.utils.Configuration: Configuration was loaded…
2017/04/25 04:40:08 INFO – com.blazemeter.Main: Log file=/var/cache/tomcat8/temp/7nhbj8kaarnlk3jemcnttusson9067326786491721299/SeleniumEasy.log
2017/04/25 04:40:08 INFO – com.blazemeter.Main: Input file=/var/cache/tomcat8/temp/7nhbj8kaarnlk3jemcnttusson9067326786491721299/SeleniumEasy.har
2017/04/25 04:40:08 INFO – com.blazemeter.Main: Output file=/var/cache/tomcat8/temp/7nhbj8kaarnlk3jemcnttusson9067326786491721299/SeleniumEasy.jmx
2017/04/25 04:40:08 INFO – com.blazemeter.utils.Utils: Trying to detect input file type vie mime_type….
2017/04/25 04:40:08 INFO – com.blazemeter.utils.Utils: Detected input file type=text/html
2017/04/25 04:40:08 ERROR – com.blazemeter.Main: Failed to start converting: com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: Failed to find jsonSchema for /var/cache/tomcat8/temp/7nhbj8kaarnlk3jemcnttusson9067326786491721299/SeleniumEasy.har
level: “fatal”
at com.blazemeter.utils.JsonFormatDetector.converterType(JsonFormatDetector.java:187)
at com.blazemeter.utils.Utils.converterType(Utils.java:78)
at com.blazemeter.utils.Utils.converter(Utils.java:187)
at com.blazemeter.Main.main(Main.java:83)
at com.blazemeter.Conversion$ConversionTask.call(Conversion.java:56)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Can you please help me on the same.
It is better to ask Blazemeter support. :( This part has a problem. It can not find json schema.
com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: Failed to find jsonSchema for /var/cache/tomcat8/temp/7nhbj8kaarnlk3jemcnttusson9067326786491721299/SeleniumEasy.har
level: “fatal”
Thank you for your helpful Tutorial, I did as you explain but I get this it fail up in the first Test,
AILED CONFIGURATION: @BeforeClass setup
java.lang.NoSuchMethodError: com.google.common.io.Closeables.closeQuietly(Ljava/io/Closeable;)V
at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:62)
at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:527)
at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:505)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:75)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:149)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:72)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:128)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:87)
at com.proxy.BrowserMobProxy.MobProxy.setup(MobProxy.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:551)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:768)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1188)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1113)
at org.testng.TestNG.run(TestNG.java:1025)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
I need your help please ! Thank you
Please check this link: https://stackoverflow.com/questions/32180358/java-lang-nosuchmethoderror-com-google-common-io-closeables-closequietlyljava
com.google.guava
guava
22.0
Thank your for yout answer I fixed this problem then I get exception on @Before test, The problem is surely in the seleniumCapabilities, it can’t accept this constructor driver = new FirefoxDriver(seleniumCapabilities);
[TestNG] Running:
C:\Users\Hamza Abkar\AppData\Local\Temp\testng-eclipse–1727457014\testng-customsuite.xml
FAILED CONFIGURATION: @BeforeClass setup
org.openqa.selenium.SessionNotCreatedException: InvalidArgumentError: Expected [object Undefined] undefined to be an integer
Build info: version: ‘3.4.0’, revision: ‘unknown’, time: ‘unknown’
System info: host: ‘LAPTOP-CE1IQ7E0’, ip: ‘192.168.1.95’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
0: 0x48916f –
1: 0x489f59 –
2: 0x439ced –
3: 0x4473ea –
4: 0x445128 –
5: 0x41dbb1 –
6: 0x407997 –
7: 0x6bbb39 –
8: 0x415b39 –
9: 0x6b6043 –
10: 0x7ffcdc038364 – BaseThreadInitThunk
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$22(ProtocolHandshake.java:365)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:368)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:137)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:191)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:108)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:137)
at com.proxy.BrowserMobProxy.MobProxy.setup(MobProxy.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:551)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:768)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1188)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1113)
at org.testng.TestNG.run(TestNG.java:1025)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
SKIPPED CONFIGURATION: @AfterClass shutdown
SKIPPED: teknosa_test1
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
[TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: 22 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@4909b8da: 13 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@60addb54: 87 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@614c5515: 58 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6df97b55: 6 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter@6537cf78: 5 ms
I faced the same problem, did you find the solution finally?
What is the Solution you have found as the Passinng the Capability constructor deprecated .
Please let me know
https://stackoverflow.com/questions/46786043/chromedrivercapabilities-capabilities-is-deprecated
This worked flawlessly for me!
package makemyhar;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.proxy.CaptureType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class MakeMyHAR {
public static void main(String[] args) throws IOException, InterruptedException {
//BrowserMobProxy
BrowserMobProxy server = new BrowserMobProxyServer();
server.start(0);
server.setHarCaptureTypes(CaptureType.getAllContentCaptureTypes());
server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
server.newHar(“Google”);
//PHANTOMJS_CLI_ARGS
ArrayList cliArgsCap = new ArrayList();
cliArgsCap.add(“–proxy=localhost:”+server.getPort());
cliArgsCap.add(“–ignore-ssl-errors=yes”);
//DesiredCapabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,”C:\\phantomjs.exe”);
//WebDriver
WebDriver driver = new PhantomJSDriver(capabilities);
driver.get(“https://www.google.co.in/”);
//HAR
Har har = server.getHar();
FileOutputStream fos = new FileOutputStream(“C:\\HAR-Information.har”);
har.writeTo(fos);
server.stop();
}
}
Great. Happy to hear that it works perfect.
I want to you browsermobproxy in TESTNG such that in @BeforeSuite annotation/method , it will get started and n @AfterSuite annotation/ method, it will get closed.
How can I meet my requirement ?
http://www.awesome-testing.com/2016/10/browsermob-proxy-selenium-network.html This article will give you an insight.
I want to run Browsermobproxy tool in windows 7 and Mac with selenium cucumber. please some one help how to setup Browsemobproxy and integrate with selenium cucumber
Didn’t you find any articles on google about it?
Hi Onur Baskit,
I found some articles on google but am facing some issues.
Hi guys, i’m currently using the browsermob, and i’m tracking the mixed content URL but the browsermob did not return any mixed content. mixed content are url that was is http. Right now, our website was migrated to https. Please response, thanks
I haven’t got any experience on it but I hope SW Test Academy community will help.
hi onur baskirt
can u please write an code that asserts two values in network tap using java in selenium .
i have an requirement like ,
consider two strings(json format) that are in different links , we need to compare them whether they are equal or not.
Nani, I really would like to help but nowadays I am super busy. If I will have time, I will help. But I will also search this on the internet. But when I read your request, I think it is better to do this with Rest-Assured. As I understand, you are trying to compare an API result and that result format is JSON. With rest-assured you can do this much easier. Please check here: https:/api-testing-with-rest-assured/
Hi Onur,
This is not working could u please check and fix.
import java.io.File;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.List;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.core.har.HarEntry;
import net.lightbody.bmp.proxy.CaptureType;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.xbill.DNS.Options;
public class MobProxy {
public static WebDriver driver;
public static BrowserMobProxyServer proxy;
public static void main(String[] args){
System.setProperty(“webdriver.chrome.driver”,”D:\\Projects\\chromedriver.exe”);
//System.setProperty(“webdriver.gecko.driver”,”D:\\Projects\\geckodriver.exe”);
proxy = new BrowserMobProxyServer();
proxy.setTrustAllServers(true);
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
try {
String hostIp = InetAddress.getLocalHost().getHostAddress();
seleniumProxy.setHttpProxy(hostIp + “:” + proxy.getPort());
seleniumProxy.setSslProxy(hostIp + “:” + proxy.getPort());
System.out.println(hostIp + “:” + proxy.getPort());
} catch (UnknownHostException e) {
e.printStackTrace(); }
ChromeOptions chromeOptions1 = new ChromeOptions();
chromeOptions1.addArguments(“test-type”);
chromeOptions1.addArguments(“disable-notifications”);
chromeOptions1.addArguments(“disable-infobars”);
chromeOptions1.addArguments(“start-maximized”);
chromeOptions1.setExperimentalOption(“useAutomationExtension”, false);
chromeOptions1.setExperimentalOption(“excludeSwitches”,Collections.singletonList(“enable-automation”));
DesiredCapabilities seleniumCapabilities = new DesiredCapabilities();
seleniumCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
seleniumCapabilities = DesiredCapabilities.chrome();
seleniumCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
seleniumCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions1);
driver=new ChromeDriver(seleniumCapabilities);
//driver=new FirefoxDriver(seleniumCapabilities);
proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
try {
proxy.newHar();
driver.get(“https:”);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(“Entered”);
/*
* List entries = proxy.getHar().getLog().getEntries(); for (HarEntry
* entry : entries) { System.out.println(entry.getRequest().getUrl()); }
*/
System.out.println(“passed”);
Har har = proxy.getHar();
File harFile = new File(“academy.har”);
har.writeTo(harFile);
} catch (IOException ioe) {
ioe.printStackTrace();
}
proxy.stop();
driver.quit();
}
}
I did not write this solution but what kind of error did you get? Maybe we can find a solution on StackOverflow.
How to use BMP in JS test script?
Maybe these help:
https://stackoverflow.com/questions/36203022/configure-webdriverio-with-browsermobproxy
https://snyk.io/advisor/npm-package/browsermob-proxy-client-nodejs
https://webdriver.io/docs/proxy/
Hi Onur Baskirt,
I have a scenario here to get help from you. After few navigation on UI I need to get the some API response from the browser network and do verify the some value in the response.
How to get the specific API response from the har logs in java.
OR
is there any other to get the required API response from the browser network tab.?
Hi Onur, im tryin to capture all requests on a webpage, but unable to do so, can i connect to you