Example usage for org.openqa.selenium WebDriver getCurrentUrl

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

Introduction

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

Prototype

String getCurrentUrl();

Source Link

Document

Get a string representing the current URL that the browser is looking at.

Usage

From source file:hu.traininfo.uitest.step.Steps.java

License:Open Source License

@Then("I should see $expectedPage page within $timeout seconds")
public void checkPageLoad(final String webpage, Integer timeout) {
    final String webpageUrl = getWebpageUrl(webpage);
    if (timeout == null) {
        timeout = DEFAULT_TIMEOUT_IN_SECONDS;
    }/* w  w  w  . j  a va 2  s . co  m*/
    WebDriverWait webDriverWait = new WebDriverWait(browser, timeout);
    webDriverWait.until(new Function<WebDriver, WebElement>() {
        // @Override
        public WebElement apply(WebDriver driver) {
            boolean expectedUrl = driver.getCurrentUrl().contains(webpageUrl);
            if (expectedUrl) {
                return new RemoteWebElement();
            }
            return null;
        }
    });
}

From source file:io.fabric8.selenium.FormFacade.java

License:Apache License

public void submit() {
    getFacade().until("Form inputs: " + inputValues, new ExpectedCondition<Boolean>() {
        @Override//from w ww  .  j a va 2 s .c  om
        public Boolean apply(WebDriver driver) {
            logWait("" + inputValues + " on " + driver.getCurrentUrl());
            WebElement submitElement = null;
            for (InputValue inputValue : inputValues) {
                submitElement = inputValue.doInput();
                if (submitElement == null) {
                    logInfo("Missing " + inputValue + "");
                    return false;
                }
            }
            if (submitBy == null && submitElement == null) {
                fail("No input fields submitted yet");
                return false;
            } else {
                getFacade().sleep(Millis.seconds(5));
                if (submitBy != null) {
                    getFacade().untilIsEnabled(submitBy);
                    submitElement = getFacade().findOptionalElement(submitBy);
                    if (submitElement == null) {
                        logWarn("Could not find submit button " + submitBy + "");
                        return false;
                    } else {
                        if (!submitElement.isDisplayed() || !submitElement.isEnabled()) {
                            logWarn("Submit button " + submitBy + " not enabled and visible");
                            return false;
                        }
                        logInfo("Submitting form: " + inputValues + " on " + submitElement + "");
                        submitElement.click();
                    }
                } else {
                    logInfo("Submitting form: " + inputValues + " on " + submitElement + "");
                    submitElement.submit();
                }
                return true;
            }
        }
    });
}

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  ww  .  j a v  a  2s. com
        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.internal.WebDriverInformationImpl.java

License:Apache License

/**
 * <p>/*from ww w . jav  a 2  s . c o  m*/
 * Create WebDriverInformation holder.
 * </p>
 *
 * @param driver       WebDriver instance to store
 * @param shutdownHook shutdown hook responsible for closing the WebDriver instance
 * @throws java.lang.NullPointerException if any of the parameters is {@code null}
 */
public WebDriverInformationImpl(@Nonnull final WebDriver driver, @Nonnull final Thread shutdownHook) {
    requireNonNull(driver, MUST_NOT_BE_NULL.format(P_DRIVER));
    requireNonNull(shutdownHook, MUST_NOT_BE_NULL.format(P_SHUTDOWN_HOOK));
    this.driver = driver;
    initialUrl = driver.getCurrentUrl();
    this.shutdownHook = shutdownHook;
}

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) {
    };/*w ww . j av  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/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) {
    };/*from ww w  .  j ava2s .  c  o  m*/
    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) {
    };//www  . j a v  a 2 s  .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  a v  a  2s.  c o  m*/
    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) {
    };//www. j  av a 2  s .  c o  m
    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.FailLoginWithPasswordlField.java

@Test
public void failLoginWithPasswordlField() throws Exception {

    WebDriver driver = new FirefoxDriver();

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

    driver.findElement(By.name("password")).sendKeys("abacaxi");
    new WebDriverWait(driver, 500) {
    };//from w w  w  .  ja va  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();
}