Example usage for org.openqa.selenium WebDriver get

List of usage examples for org.openqa.selenium WebDriver get

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver get.

Prototype

void get(String url);

Source Link

Document

Load a new web page in the current browser window.

Usage

From source file:io.github.bonigarcia.wdm.test.PerformanceRemoteTest.java

License:Apache License

private void singleTestExcution(WebDriver driver, int index) {
    driver.get("https://en.wikipedia.org/wiki/Main_Page");
    String title = driver.getTitle();
    assertTrue(title.equals("Wikipedia, the free encyclopedia"));

    SessionId sessionId = ((RemoteWebDriver) driver).getSessionId();
    System.out.println(index + " -- " + sessionId + " -- " + title);
}

From source file:io.github.bonigarcia.wdm.test.StabilityTest.java

License:Apache License

@Test
public void test() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(NUM_THREADS);
    ExecutorService executorService = newFixedThreadPool(NUM_THREADS);

    for (int i = 0; i < NUM_THREADS; i++) {
        executorService.submit(() -> {
            try {
                WebDriverManager.chromedriver().setup();
                ChromeOptions options = new ChromeOptions();
                options.addArguments("--headless");
                WebDriver driver = new ChromeDriver(options);
                driver.get("https://bonigarcia.github.io/selenium-jupiter/");
                String title = driver.getTitle();
                System.out.println(title);
                driver.quit();/* w w w .  j ava2  s.c  om*/
            } finally {
                latch.countDown();
            }
        });
    }

    latch.await();
    executorService.shutdown();
}

From source file:io.github.mike10004.vhs.testsupport.MakeFileUploadHar.java

License:Open Source License

@SuppressWarnings("UnusedReturnValue")
public static net.lightbody.bmp.core.har.Har main(Charset harOutputCharset, File binaryFile)
        throws IOException {
    File harFile = File.createTempFile("traffic-with-file-upload", ".har");
    int port = 49111;
    int proxyPort = 60999;
    String landingHtml = "<!DOCTYPE html>\n" + "<html>\n" + "<body>\n"
            + "  <form method=\"post\" action=\"/upload\" enctype=\"multipart/form-data\">\n"
            + "    <input type=\"file\" name=\"f\" required>\n"
            + "    <label>Tag <input type=\"text\" name=\"tag\" value=\"this will be url-encoded\"></label>\n"
            + "    <input type=\"submit\" value=\"Upload\">\n" + "  </form>\n" + "</body>\n" + "</html>";
    byte[] landingHtmlBytes = landingHtml.getBytes(StandardCharsets.UTF_8);
    Map<String, TypedContent> storage = Collections.synchronizedMap(new HashMap<>());
    fi.iki.elonen.NanoHTTPD nano = new fi.iki.elonen.NanoHTTPD(port) {
        @Override//  w  w w  .ja  v a2s  .co  m
        public fi.iki.elonen.NanoHTTPD.Response serve(fi.iki.elonen.NanoHTTPD.IHTTPSession session) {
            System.out.format("%s http://localhost:%s%s%n", session.getMethod(), port, session.getUri());
            URI uri = URI.create(session.getUri());
            if ("/".equals(uri.getPath())) {
                return newFixedLengthResponse(Response.Status.OK, MediaType.HTML_UTF_8.toString(),
                        new ByteArrayInputStream(landingHtmlBytes), landingHtmlBytes.length);
            } else if ("/upload".equals(uri.getPath())) {
                return processUpload(session, storage);
            } else if ("/file".equals(uri.getPath())) {
                return serveFileById(storage, session.getParms().get("id"));
            } else {
                return newFixedLengthResponse(NanoHTTPD.Response.Status.NOT_FOUND, "text/plain",
                        "404 Not Found");
            }
        }
    };
    nano.start();
    BrowserMobProxy proxy = new BrowserMobProxyServer();
    proxy.newHar();
    proxy.enableHarCaptureTypes(EnumSet.allOf(CaptureType.class));
    proxy.start(proxyPort);
    try {
        try {
            String url = String.format("http://localhost:%s/%n", nano.getListeningPort());
            System.out.format("visiting %s%n", url);
            WebDriver driver = createWebDriver(proxyPort);
            try {
                driver.get(url);
                // new CountDownLatch(1).await();
                WebElement fileInput = driver.findElement(By.cssSelector("input[type=\"file\"]"));
                fileInput.sendKeys(binaryFile.getAbsolutePath());
                WebElement submitButton = driver.findElement(By.cssSelector("input[type=\"submit\"]"));
                submitButton.click();
                new WebDriverWait(driver, 10).until(ExpectedConditions.urlMatches("^.*/file\\?id=\\S+$"));
                System.out.format("ending on %s%n", driver.getCurrentUrl());
            } finally {
                driver.quit();
            }
        } finally {
            nano.stop();
        }
    } finally {
        proxy.stop();
    }
    net.lightbody.bmp.core.har.Har bmpHar = proxy.getHar();
    removeConnectEntries(bmpHar.getLog().getEntries());
    String serializer = "gson";
    serialize(serializer, bmpHar, harFile, harOutputCharset);
    System.out.format("%s written (%d bytes)%n", harFile, harFile.length());
    bmpHar.getLog().getEntries().stream().map(HarEntry::getRequest).forEach(request -> {
        System.out.format("%s %s%n", request.getMethod(), request.getUrl());
    });
    return bmpHar;
}

From source file:io.github.mmichaelis.selenium.client.provider.AbstractWebDriverProviderTest.java

License:Apache License

private void prepareResetTest(final HtmlUnitDriver testedDriver)
        throws InterruptedException, ExecutionException {
    final URL otherPageUrl = Resources.getResource(this.getClass(), "page2.html");
    final URL newPageUrl = Resources.getResource(this.getClass(), "page3.html");
    final WebDriverProvider driverProvider = new NoExceptionWebDriverProvider(testedDriver);
    final ExecutorService executorService = newCachedThreadPool();
    final Future<Void> openWindowResultFuture = executorService.submit(new Callable<Void>() {
        @Nullable//from  ww  w  .  j  a  va2  s . c  o  m
        @Override
        public Void call() {
            final WebDriver driver = driverProvider.get();
            driver.get(otherPageUrl.toExternalForm());
            final JavascriptExecutor executor = (JavascriptExecutor) driver;
            executor.executeScript("window.open(arguments[0])", newPageUrl.toExternalForm());
            final Set<String> windowHandles = driver.getWindowHandles();
            checkState(windowHandles.size() > 1, "Failed to open additional window for driver: %s", driver);
            driverProvider.reset();
            return null;
        }
    });
    openWindowResultFuture.get();
}

From source file:io.github.siscultural.system_tests.AccessNonexistentPage.java

@Test
public void accessNonexistentPage() {

    WebDriver driver = new FirefoxDriver();

    driver.get("http://localhost:8080/istoeoacrenomecxiste");

    String text = driver.findElements(By.tagName("h1")).get(0).getText();

    Assert.assertEquals("Whitelabel Error Page", text);

    driver.close();//from   w w  w .j  a  va 2s  .c  o  m
}

From source file:io.github.siscultural.system_tests.CompleteLogin.java

@Test
public void completeLogin() throws Exception {

    WebDriver driver = new FirefoxDriver();

    driver.get("http://localhost:8080/");

    driver.findElement(By.name("email")).sendKeys("victor.hugo.origins@gmail.com");
    driver.findElement(By.name("password")).sendKeys("abacaxi");
    new WebDriverWait(driver, 500) {
    };//ww  w. ja  v  a2  s .c o m
    driver.findElement(By.id("input-login")).click();
    new WebDriverWait(driver, 500) {
    };
    new WebDriverWait(driver, 500) {
    };

    Assert.assertEquals("http://localhost:8080/home", driver.getCurrentUrl());

    driver.close();
}

From source file:io.github.siscultural.system_tests.CompleteLoginAndThemDoLogout.java

@Test
public void completeLogin() throws Exception {

    WebDriver driver = new FirefoxDriver();

    driver.get("http://localhost:8080/");

    driver.findElement(By.name("email")).sendKeys("victor.hugo.origins@gmail.com");
    driver.findElement(By.name("password")).sendKeys("abacaxi");
    new WebDriverWait(driver, 500) {
    };//  w  w w .java 2  s .  com
    driver.findElement(By.id("input-login")).click();
    new WebDriverWait(driver, 500) {
    };
    driver.get("http://localhost:8080/logout");
    new WebDriverWait(driver, 500) {
    };

    Assert.assertEquals("http://localhost:8080/", driver.getCurrentUrl());

    driver.close();
}

From source file:io.github.siscultural.system_tests.CompleteLoginAndTryBackAndDoLoginAgain.java

@Test
public void CompleteLoginAndTryBackAndDoLoginAgain() {

    WebDriver driver = new FirefoxDriver();

    driver.get("http://localhost:8080/");

    driver.findElement(By.name("email")).sendKeys("victor.hugo.origins@gmail.com");
    driver.findElement(By.name("password")).sendKeys("abacaxi");
    new WebDriverWait(driver, 500) {
    };//from   ww w.j av a  2s .c  o  m
    driver.findElement(By.id("input-login")).click();
    new WebDriverWait(driver, 500) {
    };
    new WebDriverWait(driver, 500) {
    };
    driver.navigate().to("http://localhost:8080/");

    Assert.assertEquals("http://localhost:8080/home", driver.getCurrentUrl());

    driver.close();

}

From source file:io.github.siscultural.system_tests.FailLoginWithEmailField.java

@Test
public void failLoginWithEmailField() throws Exception {

    WebDriver driver = new FirefoxDriver();

    driver.get("http://localhost:8080/");

    driver.findElement(By.name("email")).sendKeys("victor.hugo.origins@gmail.com");
    new WebDriverWait(driver, 500) {
    };/*from   w ww  .  j ava  2s .c  om*/
    driver.findElement(By.id("input-login")).click();
    new WebDriverWait(driver, 500) {
    };
    new WebDriverWait(driver, 500) {
    };

    Assert.assertEquals("http://localhost:8080/", driver.getCurrentUrl());

    driver.close();
}

From source file:io.github.siscultural.system_tests.FailLoginWithEmptyFields.java

@Test
public void FailLoginWithEmptyFields() throws Exception {

    WebDriver driver = new FirefoxDriver();

    driver.get("http://localhost:8080/");

    new WebDriverWait(driver, 500) {
    };// ww  w  . j a v a 2 s  . c  om
    driver.findElement(By.id("input-login")).click();
    new WebDriverWait(driver, 500) {
    };
    new WebDriverWait(driver, 500) {
    };

    Assert.assertEquals("http://localhost:8080/", driver.getCurrentUrl());

    driver.close();
}