Example usage for org.openqa.selenium WebDriver getPageSource

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

Introduction

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

Prototype

String getPageSource();

Source Link

Document

Get the source of the last loaded page.

Usage

From source file:com.citrix.g2w.webdriver.TestLogger.java

License:Open Source License

/**
 * Method to log message along with screenshot.
 * //from  w w w .  j  av  a 2  s  .co m
 * @param message
 *            (message to log)
 * @param webDriver
 *            (web driver object)
 */
public void logWithScreenShot(final String message, final WebDriver webDriver) {
    StringBuilder logText = new StringBuilder(message);
    if (screenShotsDirectory != null) {
        File screenShotFile = new File(screenShotsDirectory, getUniqueString() + ".html");
        try {
            FileUtils.writeStringToFile(screenShotFile, webDriver.getPageSource());
            logText.append(
                    " <a href=\"" + screenShotFile.getName() + "\" target=\"_blank\">Resulting Page</a>");
        } catch (IOException e) {
            logText.append(" Unable to log screenshot");
        }
    } else {
        logText.append(" <i>Screenshots directory not set. Not logging screenshot<i>");
    }

    logText.append("<br>");
    Reporter.log(logText.toString());
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Checks if is text displayed in source.
 * /*from  ww  w.  j av a 2  s .c  om*/
 * @param driver the driver
 * @param content the content
 * @param timeout the timeout
 * @return true, if is text displayed in source
 */
public static boolean isTextDisplayedInSource(final WebDriver driver, final String content, Timeout timeout) {

    try {
        return new WebDriverWait(driver, timeout.getValue()).until(new ExpectedCondition<Boolean>() {

            public Boolean apply(final WebDriver driver) {

                return driver.getPageSource().contains(content);
            }
        });
    } catch (Exception ex) {
        return false;
    }
}

From source file:com.comcast.magicwand.drivers.AbstractPhoenixDriver.java

License:Apache License

/**
 * {@inheritDoc}/*from   w w w .ja  v  a  2  s. c  o  m*/
 */
public String getPageSource() {
    WebDriver driver = this.getDriver();
    String pageSource = null;

    if (null != driver) {
        pageSource = driver.getPageSource();
    }

    return pageSource;
}

From source file:com.ecofactor.qa.automation.insite.page.UserManagementImpl.java

License:Open Source License

/**
 * <p>/* w w w.java  2s  . c  om*/
 * Send Account details for the New User
 * </p>
 * .
 * @param driver the driver
 * @param firstName the first name
 * @param lastName the last name
 * @param emailAddress the email address
 * @param accountUserName the account user name
 * @param activeUser the active user
 * @param partnerType the partner type
 * @param partner the partner
 */
private void sendAccountDetails(final WebDriver driver, final String firstName, final String lastName,
        final String emailAddress, final String accountUserName, final String activeUser,
        final String partnerType, final String partner) {

    DriverConfig.setLogString("Click on Account Pane and send account details to the required fields.", true);
    logger.info("check accout details tab is displayed.");
    clickAccountDetailsTab();
    isDisplayedById(driver, userConfig.get(FIRST_NAME), MEDIUM_TIMEOUT);
    DriverConfig.setLogString("Enter first name as " + firstName, true);
    driver.findElement(By.id(userConfig.get(FIRST_NAME))).sendKeys(firstName);
    DriverConfig.setLogString("Enter last name as " + lastName, true);
    driver.findElement(By.id(userConfig.get(LAST_NAME))).sendKeys(lastName);
    DriverConfig.setLogString("Enter email address " + emailAddress, true);
    driver.findElement(By.id(userConfig.get(EMAIL_FIELD))).sendKeys(emailAddress);
    DriverConfig.setLogString("Enter user name " + accountUserName, true);
    driver.findElement(By.id(userConfig.get(ACCESS_LOGIN))).sendKeys(accountUserName);
    DriverConfig.setLogString("select user status ", true);
    final Select select1 = new Select(driver.findElement(By.id(userConfig.get(USER_STATUS))));
    select1.selectByVisibleText(activeUser);

    /*
     * Select select2 = new Select(driver.findElement(By.id(userConfig.get(PARTNER_TYPE))));
     * select2.selectByVisibleText(partnerType);
     */
    DriverConfig.setLogString("check partner element displayed.", true);
    final boolean partnerElement = isDisplayedById(driver, userConfig.get(PARTNER_ID), MEDIUM_TIMEOUT);

    (new WebDriverWait(driver, SHORT_TIMEOUT)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {

            boolean outcome = false;
            outcome = !d.getPageSource().contains(userConfig.get(DEFAULT_PARTNER_ID)) ? true : false;
            return outcome;
        }
    });
    if (!partnerElement) {
        final WebElement partnerText = driver
                .findElement(By.xpath("//td[contains(text(),'Partner')]/following-sibling::td"));
        DriverConfig.setLogString("Default Partner :" + partnerText.getText(), true);
    }
    if (!partner.isEmpty()) {
        final Select select3 = new Select(driver.findElement(By.id(userConfig.get(PARTNER_ID))));
        select3.selectByVisibleText(partner);
    }
}

From source file:com.firewallid.crawling.FacebookApp.java

public List<String> getUserFeeds(String id) {
    WebDriver webDriver1 = createWebDriver();
    webDriver1.get(FACEBOOK_URL + id);

    List<String> feeds = Jsoup
            /* Get page source code */
            .parse(webDriver1.getPageSource())
            /* User's posts html tag */
            .getElementsByClass(conf.get(POST_CLASS)).parallelStream().map(postHtmlTag -> postHtmlTag.text())
            .filter(post -> !post.isEmpty()).collect(Collectors.toList());

    LOG.debug(String.format("User: %s. Total feed: %s", id, feeds.size()));

    return feeds;
}

From source file:com.formkiq.web.SeleniumTestBase.java

License:Apache License

/**
 * Wait for Page Text.//  w  w  w  .  j av  a2s .  co  m
 * @param text {@link String}
 */
protected void waitUntilPageSourceText(final String text) {
    waitUntil(new Predicate<WebDriver>() {
        @Override
        public boolean apply(final WebDriver d) {
            return d.getPageSource().contains(text);
        }
    });
}

From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow22()./*w  ww  .  j  av a2 s . com*/
 * add/remove static text
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow22() throws Exception {
    // given
    ImmutableMap<String, String> values1 = ImmutableMap.of("20", "Sample Label123", "40",
            "Immediate[immediate]", "25", "Currency");

    ImmutableMap<String, String> values2 = ImmutableMap.of("70", "this is sample text");

    // when - add step
    clickAddNewWorkflow();
    addBlankForm();

    menuDragAndDrop("menu-textbox");
    addField(FormJSONFieldType.STATIC_TEXT);

    editField("1", values1);
    editField("2", values2);

    // then
    assertTrue(getPageSource().contains("this is sample text"));

    // when - delete field
    clickDeleteFieldButton("2");

    // then
    waitUntil(new Predicate<WebDriver>() {
        @Override
        public boolean apply(final WebDriver d) {
            return !d.getPageSource().contains("this is sample text");
        }
    });

    // when
    clickDeleteFieldButton("1");

    // then
    waitUntil(new Predicate<WebDriver>() {
        @Override
        public boolean apply(final WebDriver d) {
            try {
                By by = getBy("button", "data-uuid", "1");
                d.findElement(by);
                return false;
            } catch (NoSuchElementException e) {
                return true;
            }
        }
    });
}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.pages.EnvironmentDetailsPageSeleniumImpl.java

License:Apache License

private void assertWeAreInTheRequiredPage(WebDriver wd) {
    try {/*from   w w w.  ja va2s. co m*/
        wd.findElement(By.xpath("//title[contains(.,'orange paas - environment details')]"));
    } catch (NoSuchElementException e) {
        logger.error(
                "you are not in environment details page because current page title does not contain [orange paas - environment details]");
        logger.error("current page title is : " + wd.getTitle());
        logger.error("current url is : " + wd.getCurrentUrl());
        logger.error("current page source is: " + wd.getPageSource());
        throw new IllegalStateException("this is not the environment detail page");
    }
    logger.debug("current url is : " + wd.getCurrentUrl());
    logger.debug("current page title is : " + wd.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProvider2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs//from   ww w. j  a v a  2s .c  o m
 */
@Test
public void basicAuthenticationWrongUserName() throws Exception {
    getMockWebConnection().setResponse(URL_SECOND, "Hello World");

    // wrong user name
    getWebClient().getCredentialsProvider().clear();
    ((DefaultCredentialsProvider) getWebClient().getCredentialsProvider()).addCredentials("joe", "jetty");

    final WebDriver driver = loadPage2("Hi There");
    assertTrue(driver.getPageSource().contains("HTTP ERROR 401"));
}

From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProvider2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs//from w w w .  ja v a2  s  . c o m
 */
@Test
public void basicAuthenticationWrongPassword() throws Exception {
    getMockWebConnection().setResponse(URL_SECOND, "Hello World");

    // wrong user name
    getWebClient().getCredentialsProvider().clear();
    ((DefaultCredentialsProvider) getWebClient().getCredentialsProvider()).addCredentials("jetty", "secret");

    final WebDriver driver = loadPage2("Hi There");
    assertTrue(driver.getPageSource().contains("HTTP ERROR 401"));
}