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:org.mitre.mpf.wfm.ui.Utils.java

License:Open Source License

public static void safeClickByLinkText(WebDriver driver, String linktext) {
    WebElement webElement = driver.findElement(By.linkText(linktext));
    if (webElement != null) {
        webElement.click();/* ww  w  .j av a  2s .c  om*/
    } else {
        // Using the TestNG API for logging
        throw new IllegalStateException(
                "link text: " + linktext + ", is not available on page - " + driver.getCurrentUrl());
    }
}

From source file:org.mousephenotype.cda.selenium.support.SearchFacetTable.java

License:Apache License

/**
 * Creates a new instance (called by descendent classes).
 *
 * @param driver A valid <code>WebDriver</code> instance
 * @param timeoutInSeconds timeout/*  w  w w . j  av  a2 s  .c o  m*/
 * @param byMap a map of HTML table-related definitions, keyed by <code> TableComponent</code>.
 *
 * @throws TestException
 */
public SearchFacetTable(WebDriver driver, long timeoutInSeconds, Map<TableComponent, By> byMap)
        throws TestException {
    this.driver = driver;
    this.target = driver.getCurrentUrl();
    this.timeoutInSeconds = timeoutInSeconds;
    this.wait = new WebDriverWait(driver, timeoutInSeconds);
    this.byMap = byMap;
    try {
        setTable(driver.findElement(byMap.get(TableComponent.BY_TABLE)));
    } catch (Exception e) {
        logger.error("URL: " + target);
        throw e;
    }
}

From source file:org.mousephenotype.cda.selenium.support.SearchPage.java

License:Apache License

/**
 * Creates a new <code>SearchPage</code> instance. No web page is loaded.
 * @param driver Web driver//  w  w w  .java2  s  .  c o  m
 * @param timeoutInSeconds The <code>WebDriver</code> timeout, in seconds
 * @param baseUrl A fully-qualified hostname and path, such as
 *   http://ves-ebi-d0:8080/mi/impc/dev/phenotype-arcihve
 * @param map a map of HTML table-related definitions, keyed by <code>
 * TableComponent</code>.
 */
public SearchPage(WebDriver driver, int timeoutInSeconds, String baseUrl,
        Map<SearchFacetTable.TableComponent, By> map) throws TestException {
    this(driver, timeoutInSeconds, null, baseUrl, map);
    this.target = driver.getCurrentUrl();
    this.map = map;
}

From source file:org.mousephenotype.www.testing.model.SearchFacetTable.java

License:Apache License

/**
 * Initializes the generic components of a <code>SearchFacetTable</code>.
 * @param driver A <code>WebDriver</code> instance pointing to the search
 * facet table with thead and tbody definitions.
 * <code>By</code> definitions for: table, tabletr, and selectxxGridLength.
 * @param timeoutInSeconds timeout/* w  w  w .j  a  v  a2  s .c  om*/
 * @param byMap a map of HTML table-related definitions, keyed by <code>
 * TableComponent</code>.
 */
public SearchFacetTable(WebDriver driver, int timeoutInSeconds, Map<TableComponent, By> byMap) {
    graphUrl = driver.getCurrentUrl();
    this.driver = driver;
    this.wait = new WebDriverWait(driver, timeoutInSeconds);
    this.timeoutInSeconds = timeoutInSeconds;
    this.byMap = byMap;
    setTable(driver.findElement(byMap.get(TableComponent.BY_TABLE)));
}

From source file:org.mousephenotype.www.testing.model.SearchPage.java

License:Apache License

/**
 * Creates a new <code>SearchPage</code> instance. No web page is loaded.
 * @param driver Web driver/*w w  w.j a  v a2 s.co m*/
 * @param timeoutInSeconds The <code>WebDriver</code> timeout, in seconds
 * @param phenotypePipelineDAO
 * @param baseUrl A fully-qualified hostname and path, such as
 *   http://ves-ebi-d0:8080/mi/impc/dev/phenotype-arcihve
 */
public SearchPage(WebDriver driver, int timeoutInSeconds, PhenotypePipelineDAO phenotypePipelineDAO,
        String baseUrl) {
    this(driver, timeoutInSeconds, null, phenotypePipelineDAO, baseUrl);
    this.target = driver.getCurrentUrl();
}

From source file:org.mozilla.zest.core.v1.ZestClientWindowHandle.java

License:Mozilla Public License

@Override
public String invoke(ZestRuntime runtime) throws ZestClientFailException {
    WebDriver window;
    Pattern p = null;//from   w w w .java2s .c om
    String runUrl = runtime.replaceVariablesInString(this.url, true);
    if (this.isRegex()) {
        p = Pattern.compile(runUrl);
    }
    boolean found = false;
    for (WebDriver wd : runtime.getWebDrivers()) {
        for (String wh : wd.getWindowHandles()) {
            window = wd.switchTo().window(wh);
            if (this.isRegex()) {
                if (p.matcher(window.getCurrentUrl()).matches()) {
                    runtime.addWebDriver(this.windowHandle, wd);
                    runtime.debug(
                            "Matched window " + window.getWindowHandle() + " url: " + window.getCurrentUrl());
                    found = true;
                    break;
                } else {
                    runtime.debug("Didnt match window " + window.getWindowHandle() + " url: "
                            + window.getCurrentUrl());
                }
            } else {
                if (window.getCurrentUrl().equals(runUrl)) {
                    runtime.addWebDriver(this.windowHandle, wd);
                    runtime.debug(
                            "Matched window " + window.getWindowHandle() + " url: " + window.getCurrentUrl());
                    found = true;
                    break;
                } else {
                    runtime.debug("Didnt match window " + window.getWindowHandle() + " url: "
                            + window.getCurrentUrl());
                }
            }
        }
    }
    if (!found) {
        runtime.output("Failed to find window " + this.getUrl() + " regex=" + this.isRegex());
        throw new ZestClientFailException(this,
                "Failed to find window " + this.getUrl() + " regex=" + this.isRegex());
    }

    return this.windowHandle;
}

From source file:org.nuxeo.ftest.wizard.ITWizardAndUpdateCenterTests.java

License:Apache License

public void runWizardAndRestart() throws Exception {
    // **********************
    // welcome//w w  w  .ja v a2s  .  c  om
    WizardPage welcomePage = get(NUXEO_URL, WizardPage.class);
    assertTrue(welcomePage.getTitle().contains("Welcome to "));

    // **********************
    // Settings
    WizardPage settingsPage = welcomePage.next();
    assertNotNull(settingsPage);

    assertEquals("General Settings", settingsPage.getTitle());

    welcomePage = settingsPage.previous();
    assertNotNull(welcomePage);
    assertFalse(welcomePage.hasError());
    assertTrue(welcomePage.getTitle().contains("Welcome to "));

    // **********************
    // proxy
    WizardPage proxyPage = welcomePage.next().next();
    assertNotNull(proxyPage);
    assertFalse(proxyPage.hasError());
    assertEquals("HTTP Proxy Settings", proxyPage.getTitle());

    // check validation
    assertTrue(proxyPage.selectOption("nuxeo.http.proxy.type", "anonymous"));
    proxyPage.clearInput("nuxeo.http.proxy.host");
    proxyPage.clearInput("nuxeo.http.proxy.port");
    proxyPage = proxyPage.next(true);
    assertTrue(proxyPage.hasError());

    proxyPage.fillInput("nuxeo.http.proxy.host", "myproxy");
    proxyPage.fillInput("nuxeo.http.proxy.port", "AAAA");
    proxyPage = proxyPage.next(true);
    assertTrue(proxyPage.hasError());

    proxyPage.fillInput("nuxeo.http.proxy.port", "8080");
    WizardPage somePage = proxyPage.next();
    assertFalse(somePage.hasError());
    proxyPage = somePage.previous();

    assertTrue(proxyPage.selectOption("nuxeo.http.proxy.type", "authenticated"));
    proxyPage.clearInput("nuxeo.http.proxy.login");
    proxyPage.clearInput("nuxeo.http.proxy.password");
    proxyPage = proxyPage.next(true);
    assertTrue(proxyPage.hasError());

    assertTrue(proxyPage.selectOption("nuxeo.http.proxy.type", "none"));

    // **********************
    // Database settings
    WizardPage dbPage = proxyPage.next();
    assertNotNull(dbPage);
    assertFalse(dbPage.hasError());
    assertEquals("Database Settings", dbPage.getTitle());

    // **********************
    // Directory settings
    WizardPage userPage = dbPage.next();
    assertNotNull(userPage);
    assertFalse(userPage.hasError());
    assertEquals("Users & Groups Settings", userPage.getTitle());
    userPage.selectOptionWithReload("nuxeo.directory.type", "ldap");
    userPage.fillInput("nuxeo.ldap.url", "ldap://ldap.testathon.net:3890");
    userPage = userPage.navById(WizardPage.class, "checkNetwork");
    assertTrue(userPage.hasError());
    userPage.clearInput("nuxeo.ldap.url");
    userPage.fillInput("nuxeo.ldap.url", "ldap://ldap.testathon.net:389");
    userPage = userPage.navById(WizardPage.class, "checkNetwork");
    assertFalse(userPage.hasError());
    userPage.selectOptionWithReload("nuxeo.directory.type", "default");

    // **********************
    // SMTP Settings
    WizardPage smtpPage = userPage.next();
    assertNotNull(smtpPage);
    assertEquals("SMTP Settings", smtpPage.getTitle());
    // check port validation
    assertTrue(smtpPage.selectOption("mail.transport.auth", "false"));
    smtpPage.fillInput("mail.transport.host", SMTP_SERVER_HOST);
    smtpPage.fillInput("mail.transport.port", "AAA");
    smtpPage = smtpPage.next(true);
    assertTrue(smtpPage.hasError());

    // check login/password validation
    smtpPage.fillInput("mail.transport.port", SMTP_SERVER_PORT);
    assertTrue(smtpPage.selectOption("mail.transport.auth", "true"));
    smtpPage.clearInput("mail.transport.user");
    smtpPage.clearInput("mail.transport.password");
    smtpPage = smtpPage.next(true);
    assertTrue(smtpPage.hasError());
    assertTrue(smtpPage.selectOption("mail.transport.auth", "false"));

    // **********************
    // Connect Form
    WizardPage connectWizardPage = smtpPage.next();
    assertNotNull(connectWizardPage);
    assertFalse(connectWizardPage.hasError());

    // enter embedded IFrame
    ConnectWizardPage connectPage1 = connectWizardPage.getConnectPage();
    assertNotNull(connectPage1);
    assertEquals(CONNECT_FORM_TITLE, connectPage1.getTitle());

    // try to validate
    ConnectWizardPage connectPage2 = connectPage1.submitWithError();
    assertNotNull(connectPage2);
    assertTrue(connectPage2.getErrorMessage().startsWith("There were some errors in your form:"));

    // ok, let's try to skip the screen
    WizardPage connectSkip = connectPage1.navByLink(WizardPage.class, "Or skip and don't register", true);
    assertNotNull(connectSkip);
    assertEquals("You have not signed up for a free trial of Nuxeo Online Services.", connectSkip.getTitle2());

    // ok, let's register
    connectWizardPage = connectSkip.navById(WizardPage.class, "btnRetry", true);
    connectPage1 = connectWizardPage.getConnectPage(); // enter iframe
                                                       // again
    assertNotNull(connectPage1);

    // Register with a existing account
    ConnectRegistrationPage connectSignIn = connectPage1.getLink("click here")
            .asPage(ConnectRegistrationPage.class);

    // Login through CAS
    String mainWindow = driver.getWindowHandle();
    WebDriver popup = AbstractTest.getPopup();
    System.out.println(popup.getCurrentUrl());
    popup.findElement(By.id("username")).sendKeys(CONNECT_LOGIN);
    popup.findElement(By.id("password")).sendKeys(getTestPassword());
    popup.findElement(By.cssSelector(".btn-submit")).click();

    driver.switchTo().window(mainWindow);

    IFrameHelper.focusOnConnectFrame(driver);
    assertEquals("Register your new Nuxeo instance", connectSignIn.getTitle());

    // select the associated project
    connectSignIn.selectOption("project", CONNECT_PROJECT_SELECTOR_UUID);
    // connectProjectPage.fillInput("project", CONNECT_PROJECT_SELECTOR);

    // **********************
    // Exit Online Registration Form and Display Packages selection
    WizardPage packageSelectiondPage = connectSignIn.nav(WizardPage.class, "Continue");

    assertNotNull(packageSelectiondPage);
    assertEquals("Select Modules", packageSelectiondPage.getTitle());

    // use specific url
    String currentUrl = driver.getCurrentUrl();
    currentUrl = currentUrl + "?showPresets=true";
    packageSelectiondPage = get(currentUrl, WizardPage.class);

    WebElement presetBtn = Locator.findElementWithTimeout(By.id("preset_nuxeo-dm"));
    presetBtn.click();
    Thread.sleep(1000);

    // **************************
    // Package Download Screen
    WizardPage packageDownloadPage = packageSelectiondPage.next();
    assertNotNull(packageDownloadPage);
    assertEquals("Download Module(s)", packageDownloadPage.getTitle());

    // **********************
    // Summary screen
    SummaryWizardPage summary = packageDownloadPage.next(SummaryWizardPage.class);
    assertNotNull(summary);
    assertEquals("Summary", summary.getTitle());
    assertNotNull(summary.getRegistration());

    // Restart
    summary.restart();
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * @since 5.9.2//  w w  w.  java2 s. c  o m
 */
private static void waitUntilURLContainsOrNot(String string, final boolean contain) {
    final String refurl = string;
    ExpectedCondition<Boolean> condition = new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            String currentUrl = d.getCurrentUrl();
            boolean result = !(currentUrl.contains(refurl) ^ contain);
            if (!result) {
                AbstractTest.log.debug("currentUrl is : " + currentUrl);
                AbstractTest.log
                        .debug((contain ? "It should contains : " : "It should not contains : ") + refurl);
            }
            return result;
        }
    };
    WebDriverWait wait = new WebDriverWait(AbstractTest.driver, URLCHANGE_MAX_WAIT);
    wait.until(condition);
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Waits until the URL is different from the one given in parameter, with a timeout.
 *
 * @param url the URL to compare to//  ww  w  .  j av a2s.  c om
 */
public static void waitUntilURLDifferentFrom(String url) {
    final String refurl = url;
    ExpectedCondition<Boolean> urlchanged = new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            String currentUrl = d.getCurrentUrl();
            AbstractTest.log.debug("currentUrl is still: " + currentUrl);
            return !currentUrl.equals(refurl);
        }
    };
    WebDriverWait wait = new WebDriverWait(AbstractTest.driver, URLCHANGE_MAX_WAIT);
    wait.until(urlchanged);
    if (AbstractTest.driver.getCurrentUrl().equals(refurl)) {
        log.warn("Page change failed");
    }
}

From source file:org.nuxeo.functionaltests.pages.AbstractPage.java

License:Open Source License

/**
 * Waits until the URL is different from the one given in parameter, with a
 * timeout./*from w  w  w .j a  v  a2  s  . c om*/
 *
 * @param url the URL to compare to
 */
public void waitUntilURLDifferentFrom(String url) {
    final String refurl = url;
    ExpectedCondition<Boolean> urlchanged = new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return !d.getCurrentUrl().equals(refurl);
        }
    };
    WebDriverWait wait = new WebDriverWait(driver, URLCHANGE_MAX_WAIT);
    wait.until(urlchanged);
    if (driver.getCurrentUrl().equals(refurl)) {
        System.out.println("Page change failed");
    }
}