lightbody/browsermob-proxy

can browsermob-proxy support seleniume grid?

ChrisD1990 opened this issue · 3 comments

hi,

i meet a issue, as our automation is seleniume grid, i have 1 hub node and 9 salve node, now i want to use the browsermorb-proxy,
I don’t know which salve node it will run automation case, so can you help tell me should i to do? thanks

Below is my code:
public void startproxy(String url) {
BrowserMobProxy proxy = new BrowserMobProxyServer();
proxy.start(0);
// get the Selenium proxy object
RemoteWebDriver rDriver = (RemoteWebDriver) ((WebDriverFacade) getDriver()).getProxiedDriver();
String browser = rDriver.getCapabilities().getBrowserName().toLowerCase();
// String browser = ConfigParser.getBrowser();
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

	String ipAddress = new NetworkUtils().getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
    int port = proxy.getPort();
    seleniumProxy.setHttpProxy(ipAddress + ":" + port);

	if (browser.equalsIgnoreCase("chrome")) {
		DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome();
		chromeCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
		String chromeBinary = System.getProperty(" ");
		if (chromeBinary == null || chromeBinary.equals("")) {
			String os = System.getProperty("os.name").toLowerCase().substring(0, 3);
			chromeBinary = "C:\\Automation\\SeleniumGrid\\chromedriver"+ ".exe";
			System.setProperty("webdriver.chrome.driver", chromeBinary);
			ChromeOptions options = new ChromeOptions();
			options.addArguments("--start-maximized");
		}
		proxy.enableHarCaptureTypes(CaptureType.getAllContentCaptureTypes());
		driver = new RemoteWebDriver(chromeCapabilities);

// driver = new ChromeDriver(chromeCapabilities);
} else {
System.out.println("Using default browser as firefox");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
}
try {
proxy.newHar("swtestacademy");
driver.get(url);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Har har = proxy.getHar();
File harFile = new File("academy.har");
har.writeTo(harFile);
} catch (IOException ioe) {
ioe.printStackTrace();
}
// driver.quit();
// proxy.stop();
}

while open page , always show cannot connect network, can you help me see see?

private static DesiredCapabilities startBrowserMobProxy() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
    browserMobProxy.setTrustAllServers(true);
    browserMobProxy.start(9092);
    browserMobProxy.enableHarCaptureTypes(CaptureType.getAllContentCaptureTypes());

    String hostIp = new NetworkUtils().getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
    Proxy proxy = ClientUtil.createSeleniumProxy(new InetSocketAddress(hostIp, browserMobProxy.getPort()));


    proxy.setHttpProxy(hostIp + ":" + browserMobProxy.getPort());
    proxy.setSslProxy(hostIp + ":" + browserMobProxy.getPort());

    capabilities.setCapability(CapabilityType.PROXY, proxy);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);

    browserMobProxyThreadLocal.set(browserMobProxy);
    System.out.println("jvm-assign port for bmp:" + browserMobProxy.getPort());
    return capabilities;
}