Browsermob不通过Sauce Connect与Sauce Labs拦截任何内容

时间:2018-04-19 18:26:43

标签: java selenium-webdriver saucelabs browsermob-proxy browsermob

我试图从Browserstack切换到Sauce Labs(前者在docker中产生僵尸进程,挂起整个容器)。虽然一切似乎都连接并监听端口,但HAR是空的。

我的设置非常简单:在运行测试的计算机上,我从代码中启动了BMP和SC。然后我的测试启动了一个远程WebDriver,它打开了一个网页(我在这里以Google为例)。然后,应通过BMP代理此互联网连接,以便我可以捕获所有分析。

根据我使用BrowserStack的经验。但是,在与Sauce Labs完全相同的设置中,我没有得到任何拦截。

@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();
}

0 个答案:

没有答案