Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97776

Har file always returns empty when run via browsermob proxy in selenium

$
0
0

I'm trying to read sources of page traversed during selenium replay via browsermob proxy but I always get an empty har file.

Selenium 3.141 browsermob-core 2.1.5 jar

Below is my code.

If I set

WebDriver driver = new ChromeDriver(options); page gets loaded

WebDriver driver = new ChromeDriver(capabilities); page fails to load and return page isn't loading

Proxy is getting launched correctly as per the logs

/*******************************/

[RemoteTestNG] detected TestNG version 6.14.3

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

net.lightbody.bmp.BrowserMobProxyServer@61322f9dBrowserMobProxy 59858is port number

Proxy(manual, http=10.88.16.64:59858, ssl=10.88.16.64:59858)seleniumProxy

/********************************/

Any suggestions would be helpful.

public void test() throws Exception 
    {

        BrowserMobProxy proxy = getProxyServer(); //getting browsermob proxy
        System.out.println(proxy+"BrowserMobProxy");
        Proxy seleniumProxy = getSeleniumProxy(proxy);
        System.out.println(seleniumProxy+"seleniumProxy");
        DesiredCapabilities capabilities = new DesiredCapabilities().chrome();


        capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        System.setProperty("webdriver.chrome.driver", "C:\\APMWS\\testmvnproject\\src\\drivers\\chromedriver76.exe");
         ChromeOptions options = new ChromeOptions();
         WebDriver driver = new ChromeDriver(options);

        proxy.newHar(); // creating new HAR
        driver.get("https://google.com");
        driver.navigate().to("https://pizzahut.com"); //example

        List<HarEntry> entries = proxy.getHar().getLog().getEntries();
        for (HarEntry entry : entries) 
        {
            HarRequest request = entry.getRequest();
            HarResponse response = entry.getResponse();
            System.out.println(request.getUrl()+" : "+response.getStatus()+","+entry.getTime()+"ms");
        }
    proxy.stop();
    driver.close();
    }

    public Proxy getSeleniumProxy(BrowserMobProxy proxyServer) 
    {
        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyServer);
        System.out.println(seleniumProxy.getHttpProxy());
    try
    {
        String hostIp = Inet4Address.getLocalHost().getHostAddress();
        System.out.println(hostIp);
        seleniumProxy.setHttpProxy(hostIp + ":" + proxyServer.getPort());
        seleniumProxy.setSslProxy(hostIp + ":" + proxyServer.getPort());
        System.out.println(proxyServer.getPort()+"is port number");
    } 
    catch (UnknownHostException e) 
    {
        e.printStackTrace();
        System.out.println("invalid host");
    }
    return seleniumProxy;
}

public BrowserMobProxy getProxyServer() 
{
    BrowserMobProxy proxy = new BrowserMobProxyServer();
    proxy.setTrustAllServers(true);
    proxy.start(0);
    return proxy;
}

Expected Result: Write traces run via proxy to HAR file

Actual Result: Proxy gets set, page gets launched but HAR file is empty.


Viewing all articles
Browse latest Browse all 97776

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>