webmetrics / browsermob-proxy

NOTICE: this project has been forked and is being maintained at https://github.com/lightbody/browsermob-proxy
https://github.com/lightbody/browsermob-proxy
Apache License 2.0
234 stars 773 forks source link

Unable to monitor requests via Har #39

Closed selenium34 closed 12 years ago

selenium34 commented 12 years ago

Issue created from Patrick Lightbody's request.

The following test code will fail at line 38 due to a concurrent modification exception. This requires developers to implement the HttpRequestInterceptor interface to do this type of processing.

import java.util.Iterator;
import java.util.List;

import org.browsermob.core.har.Har;
import org.browsermob.core.har.HarEntry;
import org.browsermob.core.har.HarLog;
import org.browsermob.core.har.HarNameValuePair;
import org.browsermob.proxy.ProxyServer;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SeleniumProxyTesting {

    @Test
    public void testYahoo() throws Exception {
        ProxyServer server = new ProxyServer(9000);
        server.start();
        server.newHar("yahoo.com");

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy());
        WebDriver driver = new FirefoxDriver(capabilities);
        driver.get("http://www.yahoo.com");

        boolean found = false;
        Har har = null;

        //This should never complete in this example
        while(!found) {
            har = server.getHar();
            HarLog harLog = har.getLog();
            List <HarEntry> entries = harLog.getEntries();
            for (Iterator<HarEntry> i = entries.iterator(); i.hasNext() && !found;) {
                for(HarNameValuePair queryData :  i.next().getRequest().getQueryString()) { //CME occurrs here
                    found = (queryData.getName().compareToIgnoreCase("FOO_BAR") == 0) && (queryData.getValue().contains("FOO_BAZ"));
                }
            }
        }
    }
}
lightbody commented 12 years ago

I just checked in a fix for this. I'll try to do a release this week!