Example usage for org.openqa.selenium.support.ui ExpectedConditions urlMatches

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions urlMatches

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions urlMatches.

Prototype

public static ExpectedCondition<Boolean> urlMatches(final String regex) 

Source Link

Document

Expectation for the URL to match a specific regular expression

Usage

From source file:NumOfWHGamesTest.java

@Before
public void setup() throws MalformedURLException, UnknownHostException {

    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile myProfile = allProfiles.getProfile("SimBin");
    myProfile.setAcceptUntrustedCertificates(true);
    myProfile.setAssumeUntrustedCertificateIssuer(false);
    driver2 = new FirefoxDriver(myProfile);

    WebDriverWait wait = new WebDriverWait(driver2, 15);
    driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    driver2.navigate().to(urlWHGames);/* w ww  . j  a  v  a2s. c o m*/
    driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver2.navigate().to(urlWHGamesAZ);

    wait.until(ExpectedConditions.urlMatches(urlWHGamesAZ));

    wait = new WebDriverWait(driver2, 30);
    driver2.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java

License:Apache License

@Test
public void userJourney() throws Exception {
    // Do selenium tests on the deployed version, if applicable
    String endpoint = "http://localhost:8080";
    if (!LOCAL_TEST) {
        endpoint = String.format("https://%s-dot-%s.appspot.com", APP_VERSION, APP_ID);
    }//from w  w w .jav  a 2 s.  c  om
    System.out.println("Testing endpoint: " + endpoint);
    driver.get(endpoint);

    try {
        WebElement button = checkLandingPage();

        if (LOCAL_TEST) {
            WebElement loginButton = driver.findElement(By.linkText("Login"));
            loginButton.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches("login"));

            login(EMAIL);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches("/books"));

            button = checkLandingPage(EMAIL);

            button.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/create$"));

            checkAddBookPage();

            submitForm(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/read\\?id=[0-9]+$"));

            checkReadPage(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION, EMAIL);

            logout(EMAIL);
            (new WebDriverWait(driver, 10))
                    .until(ExpectedConditions.presenceOfElementLocated(By.linkText("Login")));

        } else {
            button.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/create$"));

            checkAddBookPage();

            submitForm(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/read\\?id=[0-9]+$"));

            checkReadPage(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION, "Anonymous");

            // Now check the list of books for the one we just submitted
            driver.findElement(By.linkText("Books")).click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/$"));

            checkBookList(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
        }
    } catch (Exception e) {
        System.err.println(driver.getPageSource());
        throw e;
    }
}

From source file:com.liferay.blade.sample.test.functional.utils.BladeSampleFunctionalActionUtil.java

License:Apache License

public static boolean isPageLoaded(WebDriver webDriver, String string) {
    WebDriverWait webDriverWait = new WebDriverWait(webDriver, 30);

    try {//ww w .  j a  va 2s . co  m
        webDriverWait.until(ExpectedConditions.urlMatches(string));

        return true;
    } catch (org.openqa.selenium.TimeoutException te) {
        return false;
    }
}

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//from   ww w.  j a va2 s  .c om
        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:org.keycloak.testsuite.util.URLAssert.java

License:Apache License

public static void waitUntilUrlStartsWith(String url, int timeOutInSeconds) {
    new WebDriverWait(DroneUtils.getCurrentDriver(), timeOutInSeconds)
            .until(ExpectedConditions.urlMatches("^" + url));
}