2

I'm trying to switch from Browserstack to Sauce Labs (the former spawns a zombie process in docker which hangs up the whole container). And while everything seems to connect and listen to ports, the HAR is null.

My setup is straightforward: on the machine that's running the tests I launch both BMP and SC from my code. Then my test fires up a remote WebDriver which opens a web page (I use here Google just as an example). Then, this internet connection should be proxied through BMP so that I could capture all the analytics.

In my experience with BrowserStack that worked. However, in the very same setup with Sauce Labs, I don't get anything intercepted.

@BeforeClass
public void SetUp() {
    SauceConnectFourManager = new SauceConnectFourManager(true);
    browserMobProxyServer = new BrowserMobProxyServer();
    browserMobProxyServer.setTrustAllServers(true);
    browserMobProxyServer.start(9191);
    browserMobProxyServer.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);

    try {
        SauceConnectFourManager.openConnection(username, key,4445,
                null, "-v --pac file://" + filePath,
                null, false, null);
    } catch (IOException e) {
        e.printStackTrace();
    }

    DesiredCapabilities caps = DesiredCapabilities.chrome();
    caps.setCapability("platform", "Windows 10");
    caps.setCapability("version", "latest");
    String url = "https://" + username + ":" + key + "@ondemand.saucelabs.com:443/wd/hub";
    try {
        driver = new RemoteWebDriver(new URL(url), caps);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

@Test
public void TestShouldPass() {
    /**
     * Goes to Google's page just as an example
     */

    driver.get("https://google.com");
    System.out.println("title of page is: " + driver.getTitle());
}

@AfterClass
public void TearDown() {
    driver.quit();
    SauceConnectFourManager.closeTunnelsForPlan(username, null, null);
    //har is null here!
    Har har = browserMobProxyServer.getHar();
    FileOutputStream fos;
    try {
        fos = new FileOutputStream("debug.har");
        har.writeTo(fos);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    browserMobProxyServer.stop();
}
Nick Slavsky
  • 1,260
  • 3
  • 18
  • 37

0 Answers0