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.NodesAndProcessPage.java

License:Open Source License

public static boolean ValidPage(WebDriver driver) {
    boolean exists = Utils.checkIDExists(driver, "nodes-and-processes-table");
    log.info("Current Title: {} Desired:{} Current Url: {}, table exists: {}", driver.getTitle(), PAGE_TITLE,
            driver.getCurrentUrl(), exists);
    return driver.getCurrentUrl().contains(PAGE_URL) && exists;
}

From source file:org.mitre.mpf.wfm.ui.NodesAndProcessPage.java

License:Open Source License

public static NodesAndProcessPage getNodesAndProcessPage(WebDriver driver) {
    log.info("Going to NodesAndProcessPage");
    // must be on homepage
    if (!HomePage.ValidPage(driver)) {
        throw new IllegalStateException(
                "This is not Home Page of logged in user, current page is: " + driver.getCurrentUrl());
    }/*from   w  w w.  j  a  v a  2  s .  c om*/
    log.info("Clicking link : " + NodesAndProcessPage.NAV_ID);
    // click the nav link
    Utils.safeClickById(driver, NodesAndProcessPage.NAV_ID);

    // Wait for the login page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 20)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return NodesAndProcessPage.ValidPage(d);
        }
    });

    return new NodesAndProcessPage(driver);
}

From source file:org.mitre.mpf.wfm.ui.NodesAndProcessPage.java

License:Open Source License

public List<String> getCurrentNodesAndProcess(WebDriver driver) {
    if (!HomePage.ValidPage(driver)) {
        throw new IllegalStateException(
                "This is not Home Page of logged in user, current page is: " + driver.getCurrentUrl());
    }//from   w  w  w  .j a  v a  2  s.co  m

    // get list of shutdown btns
    List<WebElement> rows = driver.findElements(By.xpath("//*[@id='dataTable-processes']/tbody/tr"));
    ArrayList<String> list = new ArrayList<String>();

    for (WebElement row : rows) {
        List<WebElement> columns = row.findElements(By.tagName("td"));
        list.add(columns.get(0).getText() + ":" + columns.get(2).getText());// name:state
    }

    return list;
}

From source file:org.mitre.mpf.wfm.ui.UploadMediaPage.java

License:Open Source License

public UploadMediaPage(WebDriver driver) {
    if (!ValidPage(driver)) {
        throw new IllegalStateException(
                "This is not Home Page of logged in user, current page is: " + driver.getCurrentUrl());
    }//from w  w w .  ja v a  2s  . c  o m
}

From source file:org.mitre.mpf.wfm.ui.UploadMediaPage.java

License:Open Source License

public static boolean ValidPage(WebDriver driver) {
    log.debug("Current Title:" + driver.getTitle() + "  Desired:" + PAGE_TITLE);
    return driver.getTitle().startsWith(PAGE_TITLE) && driver.getCurrentUrl().contains(PAGE_URL)
            && Utils.checkIDExists(driver, "fileManager");
}

From source file:org.mitre.mpf.wfm.ui.UploadMediaPage.java

License:Open Source License

public static UploadMediaPage getUploadMediaPage(WebDriver driver) {
    //must be on homepage
    if (!HomePage.ValidPage(driver)) {
        throw new IllegalStateException(
                "This is not Home Page of logged in user, current page" + "is: " + driver.getCurrentUrl());
    }// w  w  w.java 2 s. c  om
    // click the nav link
    log.debug("Nav link click:" + UploadMediaPage.NAV_ID);
    Utils.safeClickById(driver, UploadMediaPage.NAV_ID);

    // Wait for the login page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return UploadMediaPage.ValidPage(d);
        }
    });

    return new UploadMediaPage(driver);
}

From source file:org.mitre.mpf.wfm.ui.UploadMediaPage.java

License:Open Source License

/***
 * //from  ww  w . ja va  2  s  . c  o m
 * @param driver
 * @param base_url
 * @return
 */
public String uploadMediaFromUrl(WebDriver driver, String base_url, String media_url)
        throws InterruptedException {
    if (!UploadMediaPage.ValidPage(driver)) {
        throw new IllegalStateException(
                "This is not the correct page, current page" + "is: " + driver.getCurrentUrl());
    }
    //click on the remote-media directory and wait for it
    List<WebElement> rows = driver.findElements(By.className("list-group-item"));
    int idx = rows.size();
    //log.info("#level directories:" + idx);
    boolean found = false;
    for (WebElement row : rows) {
        String ele = row.getText();
        //log.info(ele);
        if (ele.equals("remote-media")) {
            row.click();
            found = true;
        }
    }
    if (!found) {
        // Using the TestNG API for logging
        throw new IllegalStateException("remote-media not found " + driver.getCurrentUrl());
    }
    log.info("Clicking btn-upload and wating for modal");
    Utils.safeClickByClassname(driver, "btn-upload");
    // wait for modal to popup
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.findElement(By.id("submitURLs")) != null;
        }
    });

    log.info("sending media :" + media_url);
    driver.findElement(By.id("URLsInput")).sendKeys(media_url);//insert a img url

    log.info("clicking submit");
    Utils.safeClickById(driver, "submitURLs");

    log.info("Waiting for file upload 600s {}", media_url);
    (new WebDriverWait(driver, 600)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.findElement(By.className("localName")).getText().contains("Uploaded: ");
        }
    });
    log.info("File uploaded");

    log.info("clicking close");
    Utils.safeClickById(driver, "cancelURLUpload");
    Thread.sleep(600);

    return media_url;
}

From source file:org.mitre.mpf.wfm.ui.Utils.java

License:Open Source License

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

From source file:org.mitre.mpf.wfm.ui.Utils.java

License:Open Source License

public static void safeClickByCss(WebDriver driver, String css) {
    WebElement webElement = driver.findElement(By.cssSelector(css));
    if (webElement != null) {
        webElement.click();//  ww  w  .  ja v  a  2 s .c om
    } else {
        // Using the TestNG API for logging
        throw new IllegalStateException(
                "cssSelector: " + css + ", is not available on page - " + driver.getCurrentUrl());
    }
}

From source file:org.mitre.mpf.wfm.ui.Utils.java

License:Open Source License

public static void safeClickByClassname(WebDriver driver, String classname) {
    WebElement webElement = driver.findElement(By.className(classname));
    if (webElement != null) {
        webElement.click();//w  ww.  java  2  s. c  om
    } else {
        // Using the TestNG API for logging
        throw new IllegalStateException(
                "classname: " + classname + ", is not available on page - " + driver.getCurrentUrl());
    }
}