lightbody / browsermob-proxy

A free utility to help web developers watch and manipulate network traffic from their AJAX applications.
http://bmp.lightbody.net
Apache License 2.0
2.17k stars 659 forks source link

Proxy blocks js content and changes the intended behaviour of application #429

Closed p00j4 closed 8 years ago

p00j4 commented 8 years ago

My application is js extensive (Angular web, Material design- https://material.angularjs.org/latest/) I have configured proxy for my selenium test, but while executing the test, many of my application's JS is blocked or somehow interpreted wrong that the application's most of the pages doesn't load as intended and my tests fails which is false failure (I see many js errors in console @ the time ) after I reach at the exact page, i'm capturing the Har like this: is it because of : SSL Support thing? do I need to do add some .cert? https://github.com/lightbody/browsermob-proxy#ssl-support , is there any guide on How To? for 3rd party js files with https -> returns 500 and which are internal js files -> they fail with "$variable_name is not defined"

Here is my sample code:

public class NetworkCapture_broswerMob {

    public static void main(String[] args) throws Exception {
        String strFilePath =System.getProperty("user.dir")+ "/Har/harFile.har";

        int PROXY_PORT=9100;       
        String PROXY_HOST="localhost";

        ProxyServer proxyServer = new ProxyServer(PROXY_PORT);
        proxyServer.start();
        proxyServer.setCaptureHeaders(true);
        proxyServer.setCaptureContent(true);

        Proxy proxy = proxyServer.seleniumProxy();
        String proxyString = PROXY_HOST + ":" + PROXY_PORT;
        proxy.setHttpProxy(proxyString);

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, proxy);
        WebDriver driver = new FirefoxDriver(capabilities);
        proxyServer.newHar("MY_UAT_harFile");

        driver.get("http://MY_UAT");
        driver.navigate().refresh();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.findElement(By.name("email")).sendKeys("");
        driver.findElement(By.name("password")).sendKeys("");
        driver.findElement(By.xpath("//span[text()='Sign in']")).click();

               Thread.sleep(5000);

        Har har = proxyServer.getHar();
        FileOutputStream fos = new FileOutputStream(strFilePath);
        har.writeTo(fos);
        //Thread.sleep(10000);
        proxyServer.stop();
        //driver.quit();
    }

}
p00j4 commented 8 years ago

@jekh any insights would be helpful since it becomes not useful if my application under test doesn't load properly. Do I need to add or remove something ?

jekh commented 8 years ago

It looks like you're using the legacy ProxyServer class. Use the new BrowserMobProxyServer class, and make sure you're using the browsermob-core-littleproxy module. SSL should "just work" with the most recent betas.

p00j4 commented 8 years ago

yes I came to close the issue for future readers, yes with BrowserMobProxyServer it works now.