Esempio n. 1
0
  @Ignore(
      value = {ANDROID, IPHONE, OPERA_MOBILE, PHANTOMJS, SAFARI},
      reason = "Android/Iphone/PhantomJS - not tested," + "Opera mobile/Safari - not implemented")
  @NeedsLocalEnvironment
  @Test
  public void canConfigureProxyThroughPACFile() {
    WebServer helloServer =
        createSimpleHttpServer("<!DOCTYPE html><title>Hello</title><h3>Hello, world!</h3>");
    WebServer pacFileServer =
        createPacfileServer(
            Joiner.on('\n')
                .join(
                    "function FindProxyForURL(url, host) {",
                    "  return 'PROXY " + getHostAndPort(helloServer) + "';",
                    "}"));

    Proxy proxy = new Proxy();
    proxy.setProxyAutoconfigUrl("http://" + getHostAndPort(pacFileServer) + "/proxy.pac");

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(PROXY, proxy);

    WebDriver driver = new WebDriverBuilder().setDesiredCapabilities(caps).get();
    registerDriverTeardown(driver);

    driver.get(pages.mouseOverPage);
    assertEquals(
        "Should follow proxy to another server",
        "Hello, world!",
        driver.findElement(By.tagName("h3")).getText());
  }
Esempio n. 2
0
  @Test
  public void testPACProxy() {
    Proxy proxy = new Proxy();
    proxy.setProxyAutoconfigUrl("http://aaa/bbb.pac");

    assertEquals(proxy.getProxyType(), ProxyType.PAC);
    assertEquals("http://aaa/bbb.pac", proxy.getProxyAutoconfigUrl());

    assertNull(proxy.getFtpProxy());
    assertNull(proxy.getHttpProxy());
    assertNull(proxy.getSslProxy());
    assertNull(proxy.getSocksProxy());
    assertNull(proxy.getSocksUsername());
    assertNull(proxy.getSocksPassword());
    assertNull(proxy.getNoProxy());
    assertFalse(proxy.isAutodetect());
  }
Esempio n. 3
0
  @Ignore(
      value = {ANDROID, IPHONE, OPERA_MOBILE, PHANTOMJS, SAFARI},
      reason = "Android/Iphone/PhantomJS - not tested," + "Opera mobile/Safari - not implemented")
  @NeedsLocalEnvironment
  @Test
  public void canUsePACThatOnlyProxiesCertainHosts() throws Exception {
    WebServer helloServer =
        createSimpleHttpServer("<!DOCTYPE html><title>Hello</title><h3>Hello, world!</h3>");
    WebServer goodbyeServer =
        createSimpleHttpServer("<!DOCTYPE html><title>Goodbye</title><h3>Goodbye, world!</h3>");
    WebServer pacFileServer =
        createPacfileServer(
            Joiner.on('\n')
                .join(
                    "function FindProxyForURL(url, host) {",
                    "  if (url.indexOf('" + getHostAndPort(helloServer) + "') != -1) {",
                    "    return 'PROXY " + getHostAndPort(goodbyeServer) + "';",
                    "  }",
                    "  return 'DIRECT';",
                    "}"));

    Proxy proxy = new Proxy();
    proxy.setProxyAutoconfigUrl("http://" + getHostAndPort(pacFileServer) + "/proxy.pac");

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(PROXY, proxy);

    WebDriver driver = new WebDriverBuilder().setDesiredCapabilities(caps).get();
    registerDriverTeardown(driver);

    driver.get("http://" + getHostAndPort(helloServer));
    assertEquals(
        "Should follow proxy to another server",
        "Goodbye, world!",
        driver.findElement(By.tagName("h3")).getText());

    driver.get(pages.simpleTestPage);
    assertEquals(
        "Proxy should have permitted direct access to host",
        "Heading",
        driver.findElement(By.tagName("h1")).getText());
  }
Esempio n. 4
0
  @Test
  public void testCanNotChangeAlreadyInitializedProxyType() {
    Proxy proxy = new Proxy();
    proxy.setProxyType(ProxyType.DIRECT);

    try {
      proxy.setAutodetect(true);
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setSocksPassword("");
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setSocksUsername("");
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setSocksProxy("");
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setFtpProxy("");
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setHttpProxy("");
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setNoProxy("");
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setProxyAutoconfigUrl("");
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setProxyType(ProxyType.SYSTEM);
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    try {
      proxy.setSslProxy("");
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }

    proxy = new Proxy();
    proxy.setProxyType(ProxyType.AUTODETECT);

    try {
      proxy.setProxyType(ProxyType.SYSTEM);
      fail("Didn't throw expected assertion");
    } catch (IllegalStateException e) {
      // Success - expected.
    }
  }