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:com.bitbreeds.webrtc.signaling.BrowserTest.java

License:Open Source License

@Test
public void testFull() throws Exception {

    String firefoxPath = System.getProperty("firefox.path");
    //OS X * /Firefox.app/Contents/MacOS/firefox
    System.setProperty("com.bitbreeds.keystore", "./src/test/resources/ws2.jks");
    System.setProperty("com.bitbreeds.keystore.alias", "websocket");
    System.setProperty("com.bitbreeds.keystore.pass", "websocket");

    if (firefoxPath != null) {
        SimpleSignalingExample.main();//from   w  ww  .j a  va2s.co  m

        File fl = new File(".././web/index.html");

        String url = "file://" + fl.getAbsolutePath();
        System.out.println(url);
        FirefoxBinary binary = new FirefoxBinary(new File(firefoxPath));
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        WebDriver driver = new FirefoxDriver(binary, firefoxProfile);
        driver.get(url);

        (new WebDriverWait(driver, 20)).until((ExpectedCondition<Boolean>) d -> {
            assert d != null;
            return d.findElement(By.id("status")).getText().equalsIgnoreCase("ONMESSAGE");
        });

        driver.quit();
    }

}

From source file:com.booleanworks.kryptopterus.selenium.testsuite001.BaseWelcomePageTest.java

@Test
@Ignore//from www  .  ja v a 2s. com
public void testSimple() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("phantomjs.page.settings.userAgent",
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36");
    capabilities.setCapability("phantomjs.page.settings.localToRemoteUrlAccessEnabled", true);
    capabilities.setCapability("phantomjs.page.settings.browserConnectionEnabled", true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
            "/usr/local/bin/phantomjs");
    capabilities.setCapability("takesScreenshot", true);

    WebDriver driver = new PhantomJSDriver((Capabilities) capabilities);
    driver.manage().window().setSize(new Dimension(1200, 800));
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

    // And now use this to visit NetBeans
    driver.get("http://localhost:8084/kryptopterus/");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.netbeans.org");

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:com.ceiwc.compugain.setup.TestBase.java

public void launchURL(String surl, WebDriver driver) {
    driver.get(surl);
    logger.info("Application lauched with URL" + surl);
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method build and return a webDriver instance by which one can use to control the automation of a specified
 * web browser and platform or Operating System.
 *
 * @param url - main test url/*from w w  w.  j a v  a  2  s  .  co m*/
 * @param browserType - type of browser to automate
 * @param platform - operating system or platform type
 * @return
 * @return - Instance of WebBrowser
 */
@SuppressWarnings("resource")
public static CommonFunctions buildWebDriver(String url, String browserName, Method method) {
    Annotation[] a = method.getAnnotations();
    String description = null;
    try {
        description = a[0].toString().split("description=")[1].split(", retryAnalyzer=")[0];
    } catch (Exception e) {
    }
    System.gc();
    log.info("");
    log.info("=========================================================");
    log.info("Test: {}", method.getName());
    log.info("Test Description: {}", description);
    log.info("=========================================================");
    WebDriver wd = buildWebDriver(browserName);
    CommonFunctions wDriver = new CommonFunctions(wd);
    log.info("Starting WebDriver: { Browser: {} } { Version: {} } { Platform: {} } ",
            wDriver.getBrowserName().trim(), wDriver.getBrowserVersion().trim(),
            wDriver.discoverPlatform().toString());
    log.info("Navigating to: {}", url);
    wd.get(url);
    return new CommonFunctions(wd);
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method build and return a webDriver instance by which one can use to control the automation of a specified
 * web browser and platform or Operating System.
 *
 * @param url - main test url//from ww  w . j a va 2  s  .  c  om
 * @param browserType - type of browser to automate
 * @param platform - operating system or platform type
 * @param seleniumGridUrl - selenium Grid Url
 * @return
 * @return - Instance of WebBrowser
 */
@SuppressWarnings("resource")
public static CommonFunctions buildRemoteWebDriver(String url, String browserName, Method method) {
    Annotation[] a = method.getAnnotations();
    String description = null;
    try {
        description = a[0].toString().split("description=")[1].split(", retryAnalyzer=")[0];
    } catch (Exception e) {
    }
    System.gc();
    log.info("");
    log.info("=========================================================");
    log.info("Test: {}", method.getName());
    log.info("Test Description: {}", description);
    log.info("=========================================================");
    WebDriver wd = buildRemoteWebDriver(browserName);
    CommonFunctions wDriver = new CommonFunctions(wd);
    log.info("Starting Remote WebDriver: { Browser: {} } { Version: {} } { Platform: {} } ",
            wDriver.getBrowserName().trim(), wDriver.getBrowserVersion().trim(),
            wDriver.discoverPlatform().toString());
    log.info("Navigating to: {}", url);
    wd.get(url);
    return new CommonFunctions(wd);
}

From source file:com.citrix.g2w.webdriver.pages.SystemStatusPage.java

License:Open Source License

/**
 * Constructor to initialize instance variables and verify if we are on the
 * correct page.//  w  w w  . j  av a2s.co m
 * @param webDriver
 *            (web driver)
 * @param testG2wHost
 *            (test G2w host)
 */
public SystemStatusPage(final WebDriver webDriver, final String testG2wHost) {
    String url = "https://" + testG2wHost + "/system-status";
    webDriver.get(url);
    Assert.assertTrue(webDriver.getCurrentUrl().contains("/system-status"));
    this.logger.logWithScreenShot("After opening system-status page having url :" + url, webDriver);
}

From source file:com.cloudbees.test.SeleniumTest.java

License:Apache License

private void testSeleniumDriver(WebDriver webDriver) {
    System.err.println("");
    System.err.println("#############################");
    System.err.println("# TEST WITH " + webDriver);
    System.err.println("#############################");
    try {/*from w  w  w. j av a2s  .c o  m*/
        String url = "https://google.com";
        webDriver.get(url);
        Assert.assertEquals("Unexpected page title requesting " + url + " with selenium driver "
                + webDriver.toString() + " displaying " + webDriver.getCurrentUrl(), "Google",
                webDriver.getTitle());
        System.err.println("SUCCESSFULLY invoked Selenium driver" + webDriver.toString() + " with URL "
                + webDriver.getCurrentUrl() + ", page.title='" + webDriver.getTitle() + "'");
    } finally {
        webDriver.close();
        webDriver.quit();
    }
}

From source file:com.cloudbees.workflow.ui.view.BuildArtifactsTest.java

License:Open Source License

@Ignore("remove phantomjs: https://trello.com/c/JpUg8S5z/159-get-rid-of-phantomjs-webdriver")
@Test//from   w w  w  .ja  v a2s  .  c om
public void test() throws Exception {
    WebDriver webdriver = getWebDriver();

    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job");

    job.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Archiving'); "
            + "   sh('mkdir targs && echo hello > targs/hello1.txt && echo hello > targs/hello2.txt'); "
            + "   archive(includes: 'targs/*.txt'); " + "}"));

    QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0);
    jenkinsRule.assertBuildStatusSuccess(build);

    String jobUrl = getItemUrl(jenkinsRule.jenkins, job);
    webdriver.get(jobUrl);

    // Look for the build artifacts popup button...
    WebElement buildArtifactsPopupBtn = webdriver.findElement(By.cssSelector(".build-artifacts-popup"));
    Assert.assertNotNull(buildArtifactsPopupBtn);

    // Move over the button to load the popover...
    moveMouseToElement(webdriver, buildArtifactsPopupBtn);

    // Look for and test the popover content...
    List<WebElement> buildArtifactsPopover = waitForElementsAdded(webdriver, ".cbwf-build-artifacts");
    Assert.assertEquals(1, buildArtifactsPopover.size());

    WebElement popover = buildArtifactsPopover.get(0);
    List<WebElement> artifacts = waitForElementsAdded(popover, ".artifact");
    Assert.assertEquals(2, artifacts.size());

    // TODO: Something strange here with selenium.
    // Can't seem to get the text of that element even though it is there if you sout the whole page.
    // isDisplayed on those anchor elements returns false for some reason, even though the parent elements
    // are "displayed".
    // Assert.assertEquals("hello1.txt", artifacts.get(0).findElement(By.cssSelector(".name")).getText());
    // Assert.assertEquals("hello2.txt", artifacts.get(1).findElement(By.cssSelector(".name")).getText());

    // Make sure it goes away once we move off the popover...
    moveMouseOffElement(webdriver);
    waitForElementsRemoved(webdriver, ".cbwf-build-artifacts");
}

From source file:com.cloudbees.workflow.ui.view.FailedJobTest.java

License:Open Source License

@Ignore("remove phantomjs: https://trello.com/c/JpUg8S5z/159-get-rid-of-phantomjs-webdriver")
@Test/*from  w w  w . ja  v  a  2s . co m*/
public void test() throws Exception {
    WebDriver webdriver = getWebDriver();

    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job");

    job.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build'); " + "   sh ('blah'); " + "}"));

    QueueTaskFuture<WorkflowRun> build = job.scheduleBuild2(0);
    jenkinsRule.assertBuildStatus(Result.FAILURE, build.get());

    String jobUrl = getItemUrl(jenkinsRule.jenkins, job);
    webdriver.get(jobUrl);

    // Make sure the stage cell was marked as failed...
    List<WebElement> failedStageCells = webdriver
            .findElements(By.cssSelector(".stage-cell.FAILED .stage-wrapper"));
    Assert.assertEquals(1, failedStageCells.size());

    // Make the sure the stage-failed-popover widget was added to the cell
    WebElement failedStageCell = failedStageCells.get(0);
    List<WebElement> stageFailedPopovers = failedStageCell
            .findElements(By.cssSelector(".stage-failed-popover"));
    Assert.assertEquals(1, stageFailedPopovers.size());

    // Make sure that when we mouse over the failed stage cell we get a popup...
    moveMouseToElement(webdriver, failedStageCell);
    List<WebElement> popovers = waitForElementsAdded(webdriver, ".cbwf-popover");
    //        System.out.println(webdriver.getPageSource());
    Assert.assertTrue(popovers.size() > 0);

    // Make sure the popover has what we expect...
    Assert.assertEquals("Failed with the following error(s)\n" + "Shell Script script returned exit code 127\n"
            + "See stage logs for more detail.\n" + "Logs", popovers.get(0).getText().trim());

    // Make sure the popover is removed once we move off it
    //moveMouseOffElement(webdriver);
    //waitForElementsRemoved(webdriver, ".cbwf-popover");
}

From source file:com.cloudbees.workflow.ui.view.PausedJobTest.java

License:Open Source License

@Ignore("remove phantomjs: https://trello.com/c/JpUg8S5z/159-get-rid-of-phantomjs-webdriver")
@Test/*from  w  w w  .j av a2s  .  c om*/
public void test() throws Exception {
    WebDriver webdriver = getWebDriver();

    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "Noddy Job");

    job.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build'); " + "   echo ('build'); "
            + "   input (message: 'Is the build okay?'); " + "}"));

    QueueTaskFuture<WorkflowRun> q = job.scheduleBuild2(0);
    WorkflowRun b = q.getStartCondition().get();
    CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get();

    while (b.getAction(InputAction.class) == null) {
        e.waitForSuspension();
    }

    String jobUrl = getItemUrl(jenkinsRule.jenkins, job);
    webdriver.get(jobUrl);

    // Make sure the stage cell was marked as pending input...
    List<WebElement> pausedStageCells = webdriver
            .findElements(By.cssSelector(".stage-cell.PAUSED_PENDING_INPUT .stage-wrapper"));
    Assert.assertEquals(1, pausedStageCells.size());

    // Move over the paused build and check for the popup...
    moveMouseToElement(webdriver, pausedStageCells.get(0));
    List<WebElement> inputRequiredPopovers = waitForElementsAdded(webdriver,
            ".cbwf-popover .run-input-required");
    Assert.assertEquals(1, inputRequiredPopovers.size());

    // Check the popup content...
    WebElement inputRequiredPopover = inputRequiredPopovers.get(0);
    WebElement message = inputRequiredPopover.findElement(By.cssSelector(".message"));
    Assert.assertEquals("Is the build okay?", message.getText());

    // Click on the proceed button
    WebElement proceedBtn = inputRequiredPopover.findElement(By.cssSelector(".action.proceed"));
    //        clickOnElement(webdriver, proceedBtn);
    //
    //        // Wait for the build to complete successfully
    //        Util.waitForBuildCount(job, 1, Result.SUCCESS);
    //
    //        // Click on the proceed button and wait for the popup to disappear
    //        waitForElementsRemoved(webdriver, ".cbwf-popover .run-input-required");
}