Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

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

Open
Kremliovskyi opened this issue Jun 29, 2020 · 1 comment

Comments

@Kremliovskyi
Copy link

Kremliovskyi commented Jun 29, 2020

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'
}
  1. Select Run tests using intellij idea
    Screenshot_2

  2. 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
Copy link

Also, have the same issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants