Example usage for org.openqa.selenium WebDriver navigate

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

Introduction

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

Prototype

Navigation navigate();

Source Link

Document

An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

Usage

From source file:org.alfresco.po.share.util.SiteUtil.java

License:Open Source License

/**
 * Deletes site using share/*from w w w  . j av a  2 s . com*/
 * 
 * @param siteName String site name
 * @return true if site deleted
 */
public boolean deleteSite(WebDriver driver, final String siteName) {
    if (siteName == null || siteName.isEmpty())
        throw new IllegalArgumentException("site name is required");

    try {
        // Alfresco.cloud.constants.CURRENT_TENANT

        String url = driver.getCurrentUrl();
        String target = url.replaceFirst("^*/page.*", SITE_FINDER_LOCATION_SUFFIX);
        driver.navigate().to(target);
        int count = 0;
        while (count < 5) {
            if (target.equalsIgnoreCase(driver.getCurrentUrl())) {
                break;
            }
            count++;
        }
        SharePage page = factoryPage.getPage(driver).render();
        SiteFinderPage siteFinder = page.getNav().selectSearchForSites().render();
        siteFinder = siteSearchRetry(driver, siteFinder, siteName);
        if (siteFinder.hasResults()) {
            siteFinder = siteFinder.deleteSite(siteName).render();
            return !siteFinder.hasResults();
        }
    } catch (UnsupportedOperationException une) {
        String msg = String.format(ERROR_MESSAGE_PATTERN, siteName);
        throw new RuntimeException(msg, une);
    } catch (PageException e) {
    }
    return false;
}

From source file:org.apache.nutch.protocol.interactiveselenium.DefaultClickAllAjaxLinksHandler.java

License:Apache License

public String processDriver(WebDriver driver) {

    String accumulatedData = "";
    try {/*from   www .  ja va  2 s.  com*/

        driver.findElement(By.tagName("body")).getAttribute("innerHTML");
        Configuration conf = NutchConfiguration.create();
        new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));

        List<WebElement> atags = driver.findElements(By.tagName("a"));
        int numberofajaxlinks = atags.size();
        for (int i = 0; i < numberofajaxlinks; i++) {

            if (atags.get(i).getAttribute("href") != null
                    && atags.get(i).getAttribute("href").equals("javascript:void(null);")) {

                atags.get(i).click();

                if (i == numberofajaxlinks - 1) {
                    // append everything to the driver in the last round
                    JavascriptExecutor jsx = (JavascriptExecutor) driver;
                    jsx.executeScript(
                            "document.body.innerHTML=document.body.innerHTML " + accumulatedData + ";");
                    continue;
                }

                accumulatedData += driver.findElement(By.tagName("body")).getAttribute("innerHTML");

                // refreshing the handlers as the page was interacted with
                driver.navigate().refresh();
                new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
                atags = driver.findElements(By.tagName("a"));
            }
        }
    } catch (Exception e) {
        LOG.info(StringUtils.stringifyException(e));
    }
    return accumulatedData;
}

From source file:org.apache.zeppelin.WebDriverManager.java

License:Apache License

public static WebDriver getWebDriver() {
    WebDriver driver = null;

    if (driver == null) {
        try {// www.  j a  v a2s. c o  m
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to
                // run with DISPLAY 99
            }
            int firefoxVersion = WebDriverManager.getFirefoxVersion();
            LOG.info("Firefox version " + firefoxVersion + " detected");

            downLoadsDir = FileUtils.getTempDirectory().toString();

            String tempPath = downLoadsDir + "/firefox/";

            downloadGeekoDriver(firefoxVersion, tempPath);

            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.dir", downLoadsDir);
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", true);
            profile.setPreference("app.update.auto", false);
            profile.setPreference("app.update.enabled", false);
            profile.setPreference("dom.max_script_run_time", 0);
            profile.setPreference("dom.max_chrome_script_run_time", 0);
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
            profile.setPreference("network.proxy.type", 0);

            System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, tempPath + "geckodriver");
            System.setProperty(SystemProperty.DRIVER_USE_MARIONETTE, "false");

            FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setBinary(ffox);
            firefoxOptions.setProfile(profile);
            driver = new FirefoxDriver(firefoxOptions);
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
        }
    }

    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
        }
    }

    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while SafariDriver ", e);
        }
    }

    String url;
    if (System.getenv("url") != null) {
        url = System.getenv("url");
    } else {
        url = "http://localhost:8080";
    }

    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.get(url);

    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
            driver.navigate().to(url);
        }
    }

    if (loaded == false) {
        fail();
    }

    driver.manage().window().maximize();
    return driver;
}

From source file:org.apache.zeppelin.ZeppelinIT.java

License:Apache License

private WebDriver getWebDriver() {
    WebDriver driver = null;

    if (driver == null) {
        try {//from w  ww  .  j  a v a 2 s .c  o m
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to
                                                               // run with DISPLAY 99
            }
            FirefoxProfile profile = new FirefoxProfile();
            driver = new FirefoxDriver(ffox, profile);
        } catch (Exception e) {
        }
    }

    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
        }
    }

    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
        }
    }

    String url;
    if (System.getProperty("url") != null) {
        url = System.getProperty("url");
    } else {
        url = "http://localhost:8080";
    }

    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.get(url);

    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.partialLinkText("Create new note")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            driver.navigate().to(url);
        }
    }

    if (loaded == false) {
        fail();
    }

    return driver;
}

From source file:org.auraframework.impl.AuraClientServiceUITest.java

License:Apache License

/**
 * Verify that a refresh during a location change does not display an alert.
 * The component under test uses DelayedController.java to ensure that the
 * refresh occurs while the location change is still taking place.
 * //from   w w w .j  a v  a 2s  .  co m
 * Excluded on ipad/iphone due to known WebDriver issue:
 * http://code.google.com/p/selenium/issues/detail?id=4348
 */
@ExcludeBrowsers({ BrowserType.IPAD, BrowserType.IPHONE })
public void testRefreshDuringLocationChange() throws Exception {
    open("/clientServiceTest/refreshDuringLocationChange.app");

    WebDriver d = getDriver();
    d.findElement(By.cssSelector(".uiOutputURL")).click();
    d.navigate().refresh();

    assertFalse("Alert should not be shown on refresh", isAlertPresent());
}

From source file:org.auraframework.integration.test.MarkupCaseSensitivityUITest.java

License:Apache License

/**
 * Test for case.//from  w w w  .  j  a  va  2 s  . c o m
 *
 * we have library imported in testMarkupCaseSensitivityApp.app like this:
 *  <aura:import library="test:test_Library" property="importED" /> 
<aura:import library="test:TEST_Library" property="importedWithWrongCase" /> 
 * test_Library.lib include a list of JS files (for example: 'basicFirst.js' by: <aura:include name="basicFirst" />) 
 * This verify after first loading the testApp (it loads fine)
 * we modify test_Library.lib, change all basicFirst to BASICFirst (wrong case, BASICFirst.js doesn't exist)
 * then reload the testApp, it still loads fine, and what we changed is updated in lib too (verify through helper).
 *   fix it and enable plz: W-2984818   
 */
@Test
public void testLibFileChangeAfterCached() throws Exception {
    //load the test app, and verify the lib loads fine
    AuraTestingUtil util = getAuraTestingUtil();
    DefDescriptor<LibraryDef> lib = util.addSourceAutoCleanup(LibraryDef.class, library);
    DefDescriptor<IncludeDef> incl = definitionService
            .getDefDescriptor(String.format("js://%s.basicFirst", lib.getNamespace()), IncludeDef.class, lib);
    util.addSourceAutoCleanup(incl, basicFirst);
    // Now generate our broken case versions
    String namespace = lib.getNamespace();
    String name = lib.getName();
    String namespace_wrong = namespace.toUpperCase();

    DefDescriptor<ApplicationDef> root = util.addSourceAutoCleanup(ApplicationDef.class,
            String.format(rootComponent, namespace, name, namespace_wrong, name));
    DefDescriptor<ControllerDef> rootControllerDesc = definitionService.getDefDescriptor(
            String.format("js://%s.%s", root.getNamespace(), root.getName()), ControllerDef.class);
    util.addSourceAutoCleanup(rootControllerDesc, rootController);
    DefDescriptor<HelperDef> rootHelperDesc = definitionService.getDefDescriptor(
            String.format("js://%s.%s", root.getNamespace(), root.getName()), HelperDef.class);
    util.addSourceAutoCleanup(rootHelperDesc, rootHelper);
    String url = "/" + root.getNamespace() + "/" + root.getName() + ".app";
    open(url, Mode.DEV);
    getAuraUITestingUtil().waitForElement(By.className(testLibButtonClass));
    findDomElement(By.className(testLibButtonClass)).click();
    //change lib source
    AuraContext context = contextService.getCurrentContext();
    if (context == null) {
        context = contextService.startContext(Mode.SELENIUM, Format.HTML, Authentication.AUTHENTICATED);
    }
    //ApplicationDef ad = definitionService.getDefinition(root);
    //List<LibraryDefRef> aid = ad.getImports();
    TextSource<?> source = null;
    source = (TextSource<?>) definitionService.getSource(lib);
    String originalContent = source.getContents();
    String newSource = originalContent.replace("basicFirst", "BASICFirst");
    if (newSource != null) {
        //update the test_Library.lib source, then refresh
        getAuraTestingUtil().updateSource(lib, newSource);
        //refresh the testApp, until it pick up the source change in test_Library.lib
        getAuraUITestingUtil().waitUntilWithCallback(new Function<WebDriver, Integer>() {
            @Override
            public Integer apply(WebDriver driver) {
                driver.navigate().refresh();
                //click the button
                getAuraUITestingUtil().waitForElement(By.className(testLibButtonClass));
                findDomElement(By.className(testLibButtonClass)).click();
                //get the text from output div
                getAuraUITestingUtil().waitForElement(By.className(testLibButtonClass));
                String text = findDomElement(By.className(outputDivClass)).getText();
                if (text.contains("BASICFirst")) {
                    return 1;
                } else {
                    return null;
                }
            }
        }, new ExpectedCondition<String>() {
            @Override
            public String apply(WebDriver d) {
                return "outputDiv doesn't contain 'BASICFirst'"
                        + findDomElement(By.className(outputDivClass)).getText();
            }
        }, 30, "fail waiting on test app pick up new source in test_Library.lib");
    } else {
        Assert.fail(
                "expect to find 'test:test_Library' in auratest:testMarkupCaseSensitivityApp's import libs");
    }
}

From source file:org.codehaus.mojo.screenshot.ScreenshotMojo.java

License:Apache License

protected void doScreenshot(WebDriver driver, String qualifier, URI uri, String outBaseName)
        throws MalformedURLException {
    if (!(driver instanceof TakesScreenshot)) { // no point in going further
        return;//from  ww w.j a va 2  s  .c  o m
    }
    driver.navigate().to(uri.toURL());
    try {
        TimeUnit.SECONDS.sleep(1); // sleep 1 second to allow for javascript to execute
    } catch (InterruptedException e1) {
    }

    File tempScreenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

    try {
        FileUtils.copyFile(tempScreenshot, new File(outBaseName + "-" + qualifier + ".jpg"));
    } catch (IOException e) {
    }
}

From source file:org.craftercms.cstudio.share.selenium.basic.CStudioSeleniumUtil.java

License:Open Source License

public static void navigate_to_dashboard(WebDriver driver) {
    driver.navigate().to(properties.getProperty("acme.dashboard.url"));
    wait_until_displayed(driver, SHORT_TIMEOUT, By.id("acn-wcm-logo-image"));
    wait_until_displayed(driver, SHORT_TIMEOUT, By.id("acn-dropdown-toggler"));
    assertTrue(driver.getCurrentUrl().equals(properties.getProperty("acme.dashboard.url")));
}

From source file:org.craftercms.cstudio.share.selenium.basic.CStudioSeleniumUtil.java

License:Open Source License

public static void navigate_to_unauthorized_url(WebDriver driver, String username) {
    driver.navigate().to(properties.getProperty("acme.dashboard.url"));
    assertTrue(driver.getCurrentUrl()/* w  w w  . j ava 2 s .c om*/
            .equals(String.format(properties.getProperty("user.dashboard.url"), username)));
}

From source file:org.craftercms.cstudio.share.selenium.basic.CStudioSeleniumUtil.java

License:Open Source License

private static void navigate_to(WebDriver driver, String url) {
    driver.navigate().to(url);
    new WebDriverWait(driver, SHORT_TIMEOUT);
    assertTrue(driver.getCurrentUrl().equals(url));
}