package com.github.mike10004.seleniumhelp;

import net.lightbody.bmp.core.har.HarContent;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;

import java.net.URL;

public class ChromeWebDriverFactoryHttpCollectionTest extends CollectionTestBase {

    public ChromeWebDriverFactoryHttpCollectionTest() {
        super("http");
    }

    @BeforeClass
    public static void setUpDriver() {
        String driverPath = System.getProperty("webdriver.chrome.driver");
        if (driverPath == null) {
            UnitTests.setupRecommendedChromeDriver();
        }
    }

    @Test
    public void http() throws Exception {
        String display = xvfb.getController().getDisplay();
        WebDriverFactory webDriverFactory = ChromeWebDriverFactory.builder()
                .chromeOptions(UnitTests.createChromeOptions())
                .environment(ChromeWebDriverFactory.createEnvironmentSupplierForDisplay(display))
                .build();
        testTrafficCollector(webDriverFactory);
    }

    @Test
    public void http_headless() throws Exception {
        Assume.assumeFalse("headless tests disabled", UnitTests.isHeadlessChromeTestsDisabled());
        WebDriverFactory webDriverFactory = ChromeWebDriverFactory.builder()
                .chromeOptions(UnitTests.createChromeOptions())
                .headless()
                .build();
        testTrafficCollector(webDriverFactory);
    }

    @Test
    public void http_headless_brotli() throws Exception {
        Assume.assumeFalse("headless tests disabled", UnitTests.isHeadlessChromeTestsDisabled());
        WebDriverFactory webDriverFactory = ChromeWebDriverFactory.builder()
                .chromeOptions(UnitTests.createChromeOptions())
                .headless()
                .build();
        HarContent content = testTrafficCollector(webDriverFactory, new URL("http://httpbin.org/brotli"));
        System.out.println(content.getText());
    }
}
@@ -83,16 +83,63 @@
 ontent;%0A
+import net.lightbody.bmp.core.har.HarResponse;%0A
 import o
@@ -1854,23 +1854,25 @@
  Har
-Content content
+Response response
  = t
@@ -1944,24 +1944,76 @@
 /brotli%22));%0A
+        HarContent content = response.getContent();%0A
         Syst

use har response instead of har content in brotli test