Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WhiteList and BlackList are not working with the new BrowserMobProxy #279

Closed
josemoO opened this issue Jul 14, 2015 · 4 comments
Closed

Comments

@josemoO
Copy link

josemoO commented Jul 14, 2015

The Urls that match the blacklist or the Urls that do not match the whitelist do not return, the browser timeouts waiting for an answer of those Urls.

I am using Maven, Windows 7 64bits, Java 1.8, TestNG, Selenium 2.46 and browsermob-core-littleproxy 2.1.0-beta-1.

I prepared a sample maven project with the case to reproduce this issue, but it seems that I can't upload it, so here you have my TestNG test case:

package test.whiteList;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;

import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class WhiteListTest {

private WebDriver driver;
private BrowserMobProxy proxyServer;

@BeforeMethod
public void setUp() throws UnknownHostException {       

    // Set up the BrowserMob proxy in order to block the calls to Google Ads that some times block the browser
    proxyServer = new BrowserMobProxyServer();              

    // This are the patterns of our sites, in real life there are more...
    List<String> allowUrlPatterns = new ArrayList<String>();
    allowUrlPatterns.add("https?://.*(newhomesource.com)+.*");

    // All the URLs that are not from our sites are blocked and a status code of 403 is returned
    proxyServer.whitelistRequests(allowUrlPatterns, 404);

    proxyServer.start(9091, InetAddress.getLocalHost());

    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    // get the Selenium proxy object
    Proxy proxy = ClientUtil.createSeleniumProxy(proxyServer);
    capabilities.setCapability(CapabilityType.PROXY, proxy);

    driver = new FirefoxDriver(capabilities);
}

@Test
public void test() {

    driver.get("http://www.newhomesource.com");

    // Do a search
    driver.findElement(By.id("SearchText")).sendKeys("Austin, tx area");

    driver.findElement(By.id("HomeSearchBtn")).click();
}

@AfterTest
public void cleamUp(){
    driver.quit();

    proxyServer.stop();
}

}

And this is the content of my pom.xml


4.0.0
test
test
0.0.1-SNAPSHOT
WhiteListExample

<suite.xml.file>testsuite.xml</suite.xml.file>



org.seleniumhq.selenium
selenium-java
2.46.0


org.testng
testng
6.8


net.lightbody.bmp
browsermob-core-littleproxy
2.1.0-beta-1


org.apache.commons
commons-lang3
3.1


com.google.guava
guava
18.0


com.googlecode.json-simple
json-simple
1.1.1


org.apache.commons
commons-lang3
3.1



${project.basedir}/${output_folder}
${project.build.directory}/classes


org.apache.maven.plugins
maven-surefire-plugin
2.18

false
1
true

${suite.xml.file}




org.apache.maven.plugins
maven-resources-plugin
2.6

UTF-8





src/main/resources
true



Thanks in advance for all your work, BrowserMob proxy is a great tool, and the whitelist and blacklist an important feature and I have to say that I am glad the development of browsermob proxy continues after a time without releases. Please let me know if you need more information.

Thanks,
Jose

@jekh
Copy link
Collaborator

jekh commented Jul 16, 2015

This issue was fixed by PR #261 and PR #273, which are now in master. There is one outstanding issue I want to get fixed before beta-2 is released, but it will most likely be released to Central within the next few days.

@jekh
Copy link
Collaborator

jekh commented Jul 20, 2015

Beta-2 is out! Update your pom and that should fix your issue.

@josemoO
Copy link
Author

josemoO commented Jul 20, 2015

Hi jekh,
It is working great now! Thank you!

@josemoO josemoO closed this as completed Jul 20, 2015
@jekh
Copy link
Collaborator

jekh commented Jul 20, 2015

Awesome, thanks for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants