browserup / browserup-proxy

BrowserUp Proxy is a free utility to watch, test, and manipulate web application network traffic and performance.
https://browserup.com
Apache License 2.0
164 stars 41 forks source link

Selenium, Embedded, Gradle: No internet when running embedded proxy with gradle and run tests with intellij idea #289

Open Kremliovskyi opened 4 years ago

Kremliovskyi commented 4 years ago

To Reproduce Steps to reproduce the behavior:

  1. Setup gradle project in intellij idea with embedded BrowserUp proxy:
    
    plugins {
    id 'java'
    }

group 'org.example' version '1.0-SNAPSHOT'

sourceCompatibility = JavaVersion.VERSION_11

repositories { mavenCentral() }

dependencies { compile 'org.testng:testng:6.14.3' testCompile group: 'junit', name: 'junit', version: '4.13' compile 'org.seleniumhq.selenium:selenium-java:3.141.59' compile 'com.browserup:browserup-proxy-core:2.1.1' }

test { // enable TestNG support (default is JUnit) useTestNG()

// show standard out and standard error of the test JVM(s) on the console
testLogging.showStandardStreams = true

// set heap size for the test JVM(s)
minHeapSize = "128m"
maxHeapSize = "512m"

// set JVM arguments for the test JVM(s)
jvmArgs '-XX:MaxPermSize=256m'

}


 2. Select Run tests using intellij idea
![Screenshot_2](https://user-images.githubusercontent.com/12884831/86033884-58e17580-ba42-11ea-8578-eea483a800a1.png) 

3. Execute simple test as testng or junit test like:
    ChromeOptions chromeOptions = new ChromeOptions();

    BrowserUpProxy proxy = new BrowserUpProxyServer();
    proxy.setTrustAllServers(true);
    proxy.start();
    proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT,
            CaptureType.RESPONSE_CONTENT,
            CaptureType.REQUEST_HEADERS,
            CaptureType.RESPONSE_HEADERS,
            CaptureType.REQUEST_COOKIES,
            CaptureType.RESPONSE_COOKIES);

    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
    proxy.newHar("itc.ua");
    seleniumProxy.setHttpProxy(InetAddress.getLocalHost().getHostAddress()+":"+proxy.getPort());
    seleniumProxy.setSslProxy(InetAddress.getLocalHost().getHostAddress()+":"+proxy.getPort());

    chromeOptions.setCapability(CapabilityType.PROXY, seleniumProxy);
    chromeOptions.setCapability("enableVNC", true);
    chromeOptions.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
    WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), chromeOptions);
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    try {
        driver.get("https://itc.ua/");
        Thread.sleep(10000L);
        proxy.getHar().writeTo(new File("src/main/resources/dev.har"));
    } catch (InterruptedException | IOException e) {
        e.printStackTrace();
    } finally {
        driver.quit();
        proxy.stop();
    }

NOTE: Test above is ran in selenoid, tried pure WebDriver and result is the same.

**Expected behavior**
Test is run successfully.

**Actual Result**
Browser states there is no internet

**Please complete the following information:**
 - OS: any
 - Browser chrome

**Additional context**
If I select for the test Run Using gradle (not intellij idea) or execute it not with the testng/junit test but in main method or just use maven instead of gradle then the issue is not reproducible, the test runs fine. Moreover old version `compile 'net.lightbody.bmp:browsermob-core:2.1.5'` does not have such issue, the test runs successfully with any option.
PetroAndrushchak commented 4 years ago

Also, have the same issue