Example usage for org.openqa.selenium WebDriver get

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

Introduction

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

Prototype

void get(String url);

Source Link

Document

Load a new web page in the current browser window.

Usage

From source file:org.apache.tomcat.maven.webapp.test.SimpleTest.java

License:Apache License

@Test
public void testHelloWorld() throws InterruptedException {
    String serverUrl = System.getProperty("serverUrl");
    assertNotNull(serverUrl, "serverUrl was not found");

    WebDriver driver = new ChromeDriver();
    driver.get(serverUrl);
    //      driver.get("http://localhost:8080/");

    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("who"))));

    driver.findElement(By.id("who")).sendKeys("Hello World!");
    driver.findElement(By.id("send-btn")).click();

    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("response"))));

    assertEquals("Unexpected response", "Hello Hello World!", driver.findElement(By.id("response")).getText());
    driver.quit();/*w  ww .ja v a  2  s.c  o m*/
}

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

License:Apache License

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

    if (driver == null) {
        try {/*from   w ww.j a  v a2s.co  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   ww w.  j av a 2 s .com*/
            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.arquillian.droidium.native_.enrichment.NativeActivityManager.java

License:Apache License

@Override
public void startActivity(String activity) {
    Validate.notNullOrEmpty(activity,//from   w ww.  ja va  2  s .  co m
            "Activity you want to start can not be a null object nor an empty string!");

    final List<DronePoint<WebDriver>> dronePoints = getDronePointsForActivity(activity);

    checkSizes(dronePoints);

    DronePoint<WebDriver> dronePoint = dronePoints.get(0);

    if (activity.startsWith(".")) {
        activity = droneContext.get(dronePoint).getMetadata(DroidiumMetadataKey.TESTED_APP_PACKAGE_NAME.class)
                + activity;
    }

    WebDriver instance = droneContext.get(dronePoint).getInstance();

    instance.get("and-activity://" + activity);
}

From source file:org.arquillian.droidium.openblend.utils.Utils.java

License:Apache License

public static void openWebPageUrl(WebDriver browser, URL context) {
    try {/* ww  w.j ava 2 s  . c  o  m*/
        browser.get(context.toExternalForm() + WEB_CONTEXT);
    } catch (final Exception ignore) {
        ignore.printStackTrace();
    }
}

From source file:org.arquillian.drone.browserstack.extension.webdriver.BrowserStackWebDriverTestCase.java

License:Apache License

private void runTest(WebDriver driver) {
    driver.get("http://www.google.com/");
    WebDriverUtil.checkElementIsPresent(driver, QUERY_FIELD, "The query field should be present");

    WebElement queryElement = driver.findElement(QUERY_FIELD);
    queryElement.sendKeys("browserstack");
    queryElement.submit();//from   ww w .  j a  v a 2 s . co  m

    WebDriverUtil.checkElementContent(driver, SEARCH_RESULTS, "BrowserStack",
            "The search result should contain a string \"BrowserStack\"");
}

From source file:org.arquillian.drone.browserstack.webdriver.BrowserStackMethodTest.java

License:Apache License

@Test
public void browserTest(@Drone final WebDriver driver) {

    driver.get("http://www.google.com/ncr");
    Graphene.waitGui().until().element(queryElement).is().visible();

    queryElement.sendKeys("BrowserStack");
    queryElement.submit();//  w  w  w.  j a v  a2 s.co m

    Graphene.waitModel().withTimeout(5, TimeUnit.SECONDS).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver notUsed) {
            return "BrowserStack - Google Search".equals(driver.getTitle());
        }
    });
    System.out.println(driver.getTitle());

}

From source file:org.arquillian.drone.saucelabs.extension.webdriver.SauceLabsWebDriverTestCase.java

License:Apache License

private void runTest(WebDriver driver) {
    driver.get("http://www.google.com/");
    WebDriverUtil.checkElementIsPresent(driver, QUERY_FIELD, "The query field should be present");

    WebElement queryElement = driver.findElement(QUERY_FIELD);
    queryElement.sendKeys("saucelabs");
    queryElement.submit();//  w ww .j  a  v a  2  s .c o m

    WebDriverUtil.checkElementContent(driver, SEARCH_RESULTS, "Sauce Labs",
            "The search result should contain a string \"Sauce Labs\"");
}

From source file:org.ballerinalang.composer.uitests.BallerinaEditorUITest.java

License:Open Source License

@Test(dataProvider = "getData")
public void openBallerinaFile(String fileName) throws IOException, InterruptedException,
        ParserConfigurationException, SAXException, TransformerException, URISyntaxException {

    //creating relevant browser webdriver
    //TODO make this generic for multiple browsers
    WebDriver driver = new FirefoxDriver();
    //opening base page - welcome page this case
    driver.get(TestConstants.SERVER_URL);
    //once the open button available click it
    waitAndGetElementByXpath(driver, TestConstants.WELCOME_PAGE_OPEN_BUTTON_XPATH).click();
    //fill the location of the ballerina file to be opened
    URL ballerinaResourceLocation = BallerinaEditorUITest.class
            .getResource(TestConstants.BALLERINA_RESOURCE_FOLDER + File.separator + fileName + ".bal");
    waitAndGetElementByXpath(driver, TestConstants.FILE_OPEN_POPUP_LOCATION_INPUT_XPATH)
            .sendKeys(ballerinaResourceLocation.getPath());
    //wait for the open button in the pop-up window
    waitAndGetElementByXpath(driver, TestConstants.FILE_OPEN_POPUP_LOCATION_OPEN_XPATH).click();
    //wait for the SVG element where the diagram is rendered
    WebElement domElement = waitAndGetElementByXpath(driver, TestConstants.SVG_XPATH);
    //Getting inner HTML of the SVG node
    String dom = TestUtils.preprocessDOMContent(domElement.getAttribute("innerHTML"));
    //TODO Add mechanism to generate DOM files
    //org.ballerinalang.composer.uitests.TestUtils.fileWriter(dom, fileName + "DOM.xml");
    URL domResourceLocation = BallerinaEditorUITest.class
            .getResource(TestConstants.DOM_RESOURCE_FOLDER + File.separator + fileName + "DOM.xml");
    //destroying browser instance
    driver.quit();//  ww w  .  j  ava  2  s. c  o  m
    //checking inner content of the DOM element
    assertEquals("Rendered diagram of " + fileName + "is not equal to the expected diagram",
            TestUtils.fileReader(domResourceLocation.getPath()), dom);
}

From source file:org.bigtester.ate.model.page.page.Homepage.java

License:Apache License

/**
 * Start homepage.// w  w  w .  j  a  v  a  2s  .  c  o m
 */
public void startHomepage() {
    WebDriver webD = super.getMyWd().getWebDriver();
    if (null == webD) {
        throw new IllegalStateException("webdriver is not correctly populated.");
    } else {
        webD.get(homeUrl);
    }
}