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:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunnerTest.java

License:Open Source License

@Test
public void testGetPageSource() {
    WebDriver driverExpected = Mockito.mock(WebDriver.class);
    Mockito.when(driverExpected.getPageSource()).thenReturn("source");
    WebDriverRunner runner = new WebDriverRunner();
    runner.setWebDriver(driverExpected);

    String source = runner.getPageSource();

    Assert.assertEquals("source", source);
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunnerTest.java

License:Open Source License

@Test
public void testClose() {
    WebDriver driverExpected = Mockito.mock(WebDriver.class);
    Mockito.when(driverExpected.getPageSource()).thenReturn("source");
    WebDriverRunner runner = new WebDriverRunner();
    runner.setWebDriver(driverExpected);
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunnerTest.java

License:Open Source License

@Test
public void testQuit() {
    WebDriver driverExpected = Mockito.mock(WebDriver.class);
    Mockito.when(driverExpected.getPageSource()).thenReturn("source");
    WebDriverRunner runner = new WebDriverRunner();
    runner.setWebDriver(driverExpected);
    runner.quit();//from w w w.ja  v  a 2s  .  c o  m
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunnerTest.java

License:Open Source License

@Test
public void testGetScreen() {
    WebDriver driverExpected = Mockito.mock(WebDriver.class);
    Mockito.when(driverExpected.getPageSource()).thenReturn("source");
    WebDriverRunner runner = new WebDriverRunner();
    runner.setWebDriver(driverExpected);
    Screen screen = runner.getScreen();//from w  w  w .j a v a 2 s.c o m
    Assert.assertNotNull(screen);
}

From source file:businesscomponents.ReportCompare1.java

public static void main(String[] args) throws InterruptedException {
    // TODO Auto-generated method stub

    WebDriver driver = new FirefoxDriver();
    driver.get("http://148.173.174.122:8900/acadmin/?serverURL=http://wpqwa551:8000");
    driver.manage().window().maximize();

    String strUserName = "kgoutham";
    String strPassWord = "kgoutham";

    driver.findElement(By.name("userID")).clear();
    driver.findElement(By.name("userID")).sendKeys(strUserName);
    driver.findElement(By.name("Password")).clear();
    driver.findElement(By.name("Password")).sendKeys(strPassWord);

    driver.findElement(By.name("loginBtn")).click();
    Thread.sleep(1200);//from w  ww.  ja  va  2  s.  co m
    System.out.println("Page title is: " + driver.getTitle());

    if (driver.getTitle().contains("Files & Folders")) {
        driver.findElement(By.id("Jobs")).click();
        Thread.sleep(2500);
        driver.switchTo().defaultContent();
        WebElement frame = driver.findElement(By.id("TableFrame"));
        driver.switchTo().frame(frame);
        Thread.sleep(1200);
        if (driver.findElement(By.xpath("//a[contains(@onmouseover,'completedjobs')]")).isDisplayed()) {
            try {
                JavascriptExecutor executor = (JavascriptExecutor) driver;
                executor.executeScript("arguments[0].click();",
                        driver.findElement(By.xpath("//a[contains(@onmouseover,'completedjobs')]")));
            } catch (Exception e) {
                driver.findElement(By.xpath("//a[contains(@onmouseover,'completedjobs')]")).click();
            }

            System.out.println("Clicking on Completed Tabs");
        } else {
            System.out.println("Failed:Unable to Find the Completed Tab section");
        }
        Thread.sleep(1200);
        WebElement frame1 = driver.findElement(By.id("TableFrame"));
        driver.switchTo().frame(frame1);
        String strValue = "MRF412";
        driver.findElement(By.id("FilterText")).clear();
        driver.findElement(By.id("FilterText")).sendKeys(strValue);
        Thread.sleep(1200);
        driver.findElement(By.xpath("//input[@value='Apply']")).click();
        Thread.sleep(3500);
        WebElement frame2 = driver.findElement(By.id("ifrListFrame"));
        driver.switchTo().frame(frame2);

        if (driver.findElement(By.xpath("(//a[contains(text(),'MRF412_reportcheck.ROI')])[1]")).isDisplayed()) {

            String oldTab = driver.getWindowHandle();
            driver.findElement(By.xpath("(//a[contains(text(),'MRF412_reportcheck.ROI')])[1]")).click();
            Thread.sleep(5000);
            ArrayList<String> newTab = new ArrayList<String>(driver.getWindowHandles());
            newTab.remove(oldTab);
            // change focus to new tab
            driver.switchTo().window(newTab.get(0));
            WebElement frame3 = driver.findElement(By.id("reportframe"));
            driver.switchTo().frame(frame3);
            String strPageSource = driver.getPageSource();
            CommonData.strPageSource = strPageSource;
            String strPageTitle = driver.findElement(By.xpath("//div[contains(@id,'water')]")).getText();
            CommonData.strPageTitle = strPageTitle;

            if (strPageTitle.contains("MultiUserTest License")) {
                System.out.println("Verifying the MultiUserTest License page is displayed");
                List<WebElement> products = driver
                        .findElements(By.xpath("//div[contains(@onmouseover,'Partner Name')]"));
                ArrayList<String> strPartnerName = CommonData.strPartnerName;
                ArrayList<String> strInvoiceNumber = CommonData.strInvoiceNumber;
                ArrayList<String> strTotalPayment = CommonData.strTotalPayment;
                ArrayList<String> strSENumber = CommonData.strSENumber;
                ArrayList<String> strPaymentMarket = CommonData.strPaymentMarket;
                ArrayList<String> strPaymentunit = CommonData.strPaymentunit;
                ArrayList<String> strLiabilityUnit = CommonData.strLiabilityUnit;
                ArrayList<String> strLiabilityCurrency = CommonData.strLiabilityCurrency;
                ArrayList<String> strMarketCurrency = CommonData.strMarketCurrency;
                ArrayList<String> strInvoiceReleaseDate = CommonData.strInvoiceReleaseDate;
                ArrayList<String> strUserId = CommonData.strUserId;

                for (int i = 1; i <= products.size(); i++) {
                    System.out.println(
                            "-----------------DISPLAYING LIST OF TABLE VALUES----------------------->: " + i);
                    String strPartnerNameList = driver
                            .findElement(By.xpath("(//div[contains(@onmouseover,'Partner Name')])[" + i + "]"))
                            .getText();
                    strPartnerName.add(strPartnerNameList);
                    System.out.println("Displaying the Partner Name list :" + strPartnerNameList);
                    String strInvoiceNumberList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Invoice Number')])[" + i + "]"))
                            .getText();
                    strInvoiceNumber.add(strInvoiceNumberList);
                    System.out.println("Displaying the Invoice Number list :" + strInvoiceNumberList);
                    String strTotalPaymentList;
                    if (i > 1) {
                        int j;
                        if (i == 3) {
                            j = i + 2;
                        } else {
                            j = i + 1;
                        }

                        strTotalPaymentList = driver
                                .findElement(
                                        By.xpath("(//div[contains(@onmouseover,'Total Payment')])[" + j + "]"))
                                .getText();
                    } else {
                        strTotalPaymentList = driver
                                .findElement(
                                        By.xpath("(//div[contains(@onmouseover,'Total Payment')])[" + i + "]"))
                                .getText();
                    }
                    strTotalPayment.add(strTotalPaymentList);
                    System.out.println("Displaying the Total Payment list :" + strTotalPaymentList);
                    String strSENumberList = driver
                            .findElement(By.xpath("(//div[contains(@onmouseover,'SE Number')])[" + i + "]"))
                            .getText();
                    strSENumber.add(strSENumberList);
                    System.out.println("Displaying the SE Number list :" + strSENumberList);
                    String strPaymentMarketList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Payment Market')])[" + i + "]"))
                            .getText();
                    strPaymentMarket.add(strPaymentMarketList);
                    System.out.println("Displaying the Payment Market list :" + strPaymentMarketList);
                    String strPaymentUnitList = driver
                            .findElement(By.xpath("(//div[contains(@onmouseover,'Payment Unit')])[" + i + "]"))
                            .getText();
                    strPaymentunit.add(strPaymentUnitList);
                    System.out.println("Displaying the Payment Unit list :" + strPaymentUnitList);
                    String strLiabilityUnitList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Liability Unit')])[" + i + "]"))
                            .getText();
                    strLiabilityUnit.add(strLiabilityUnitList);
                    System.out.println("Displaying the Liability Unit list :" + strLiabilityUnitList);
                    String strLiabilityCurrencyList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Liability Currency')])[" + i + "]"))
                            .getText();
                    strLiabilityCurrency.add(strLiabilityCurrencyList);
                    System.out.println("Displaying the Liability Currency list :" + strLiabilityCurrencyList);
                    String strMarketCurrencyList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Market Currency')])[" + i + "]"))
                            .getText();
                    strMarketCurrency.add(strMarketCurrencyList);
                    System.out.println("Displaying the Market Currency list :" + strMarketCurrencyList);
                    String strInvoiceReleaseDateList;
                    if (i > 1) {
                        int j;
                        if (i == 3) {
                            j = i + 2;
                        } else {
                            j = i + 1;
                        }

                        strInvoiceReleaseDateList = driver.findElement(By.xpath(
                                "(//div[contains(@onmouseover,'This is the difference in cost between Invoice Total and Market Totals')]/nobr)["
                                        + j + "]"))
                                .getText();
                    } else {
                        strInvoiceReleaseDateList = driver.findElement(By.xpath(
                                "(//div[contains(@onmouseover,'This is the difference in cost between Invoice Total and Market Totals')]/nobr)["
                                        + i + "]"))
                                .getText();
                    }
                    strInvoiceReleaseDate.add(strInvoiceReleaseDateList);
                    System.out
                            .println("Displaying the Invoice release date list :" + strInvoiceReleaseDateList);
                    String strUserIDList = driver
                            .findElement(By.xpath("(//div[contains(@onmouseover,'USER ID')])[" + i + "]"))
                            .getText();
                    strUserId.add(strUserIDList);
                    System.out.println("Displaying the UserId list :" + strUserIDList);
                }
                //               for (int i = 0; i < products.size(); i++) {
                //                  System.out.println("############ CHECKING ########################");
                //                  System.out.println(CommonData.strInvoiceNumber.get(i) + " Invoice Number");
                //                  System.out.println(CommonData.strInvoiceReleaseDate.get(i) + " Invoice Release Date");
                //                  System.out.println(CommonData.strTotalPayment.get(i) + " Total Payment");
                //
                //               }
            } else {
                System.out.println("MultiUserTest License is not displayed");
            }

            driver.switchTo().defaultContent();
            driver.close();
            driver.switchTo().window(oldTab);
            // driver.get("
            // http://148.173.174.122:8900/acadmin/?serverURL=http://wpqwa551:8000");
            driver.get(
                    "http://148.173.174.122:8900/acadmin/jobmanager.jsp?serverURL=http%3a%2f%2fwpqwa551%3a8000&volume=wpqwa551&daemonURL=http://wpqwa551:8100&daemonURL=http://wpqwa551:8100");

            if (driver.findElement(By.xpath("//td[contains(text(),'System')]")).isDisplayed()) {
                System.out.println("--------------##### Focus Changed to old window #### -----------");
            } else {
                System.out.println("---------Focus not changed---------------");
            }
            driver.switchTo().defaultContent();
            WebElement postframe = driver.findElement(By.id("TableFrame"));
            driver.switchTo().frame(postframe);
            Thread.sleep(1200);
            if (driver.findElement(By.xpath("//a[contains(@onmouseover,'completedjobs')]")).isDisplayed()) {
                try {
                    JavascriptExecutor executor = (JavascriptExecutor) driver;
                    executor.executeScript("arguments[0].click();",
                            driver.findElement(By.xpath("//a[contains(@onmouseover,'completedjobs')]")));
                } catch (Exception e) {
                    driver.findElement(By.xpath("//a[contains(@onmouseover,'completedjobs')]")).click();
                }
                System.out.println("Clicking on Completed Tabs");
            } else {
                System.out.println("Failed:Unable to Find the Completed Tab section");
            }
            Thread.sleep(5000);
            WebElement postframe1 = driver.findElement(By.id("TableFrame"));
            driver.switchTo().frame(postframe1);
            String strPostValue = "MRF412";
            driver.findElement(By.id("FilterText")).clear();
            driver.findElement(By.id("FilterText")).sendKeys(strPostValue);
            Thread.sleep(1200);
            driver.findElement(By.xpath("//input[@value='Apply']")).click();
            Thread.sleep(3500);
            WebElement postframe2 = driver.findElement(By.id("ifrListFrame"));
            driver.switchTo().frame(postframe2);
            String postoldTab = driver.getWindowHandle();
            driver.findElement(By.xpath("(//a[contains(text(),'MRF412_reportcheck.ROI')])[1]")).click();
            Thread.sleep(5000);
            ArrayList<String> newTab_1 = new ArrayList<String>(driver.getWindowHandles());
            newTab_1.remove(postoldTab);
            // change focus to new tab
            driver.switchTo().window(newTab_1.get(0));
            WebElement postframe3 = driver.findElement(By.id("reportframe"));
            driver.switchTo().frame(postframe3);
            System.out.println("-############## COMPARING PRE-REPORT and POST-REPORT-##############--");
            // String strPostPageSource = driver.getPageSource();
            String strPostPageTitle = driver.findElement(By.xpath("//div[contains(@id,'water')]")).getText();
            if (strPostPageTitle.contains(CommonData.strPageTitle)) {
                System.out.println(
                        "Passed : Page Title is matching with Pre-report and Post-Report " + strPostPageTitle);

                for (int i = 1, k = 0; i <= CommonData.strPartnerName.size(); i++, k++) {
                    System.out.println(
                            "----------------->>>  COMPARING LIST OF TABLE VALUES FORM PRE-REPORT AND POST-REPORT  ----------------------->>>: "
                                    + i);
                    String strPostPartnerNameList = driver
                            .findElement(By.xpath("(//div[contains(@onmouseover,'Partner Name')])[" + i + "]"))
                            .getText();
                    if (CommonData.strPartnerName.get(k).contains(strPostPartnerNameList)) {
                        System.out.println("Passed : Partner Name is matching with Pre-report and Post-Report :"
                                + strPostPartnerNameList);
                    } else {
                        System.out.println(
                                "Failed : Partner Name is not matching with Pre-report and Post-Report :"
                                        + strPostPartnerNameList);
                    }

                    String strPostInvoiceNumberList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Invoice Number')])[" + i + "]"))
                            .getText();
                    if (CommonData.strInvoiceNumber.get(k).contains(strPostInvoiceNumberList)) {
                        System.out.println(
                                "Passed : Post Invoice Number is matching with Pre-report and Post-Report :"
                                        + strPostInvoiceNumberList);
                    } else {
                        System.out.println(
                                "Failed : Post Invoice Number is not matching with Pre-report and Post-Report :"
                                        + strPostInvoiceNumberList);
                    }

                    String strPostTotalPaymentList;
                    if (i > 1) {
                        int j;
                        if (i == 3) {
                            j = i + 2;
                        } else {
                            j = i + 1;
                        }

                        strPostTotalPaymentList = driver
                                .findElement(
                                        By.xpath("(//div[contains(@onmouseover,'Total Payment')])[" + j + "]"))
                                .getText();
                        if (CommonData.strTotalPayment.get(k).contains(strPostTotalPaymentList)) {
                            System.out.println(
                                    "Passed : Total Payment List is matching with Pre-report and Post-Report :"
                                            + strPostTotalPaymentList);
                        } else {
                            System.out.println(
                                    "Failed : Total Payment List is not matching with Pre-report and Post-Report :"
                                            + strPostTotalPaymentList);
                        }
                    } else {
                        strPostTotalPaymentList = driver
                                .findElement(
                                        By.xpath("(//div[contains(@onmouseover,'Total Payment')])[" + i + "]"))
                                .getText();
                        if (CommonData.strTotalPayment.get(k).contains(strPostTotalPaymentList)) {
                            System.out.println(
                                    "Passed : Total Payment List is matching with Pre-report and Post-Report :"
                                            + strPostTotalPaymentList);
                        } else {
                            System.out.println(
                                    "Failed : Total Payment List is not matching with Pre-report and Post-Report :"
                                            + strPostTotalPaymentList);
                        }
                    }

                    String strPostSENumberList = driver
                            .findElement(By.xpath("(//div[contains(@onmouseover,'SE Number')])[" + i + "]"))
                            .getText();

                    if (CommonData.strSENumber.get(k).contains(strPostSENumberList)) {
                        System.out
                                .println("Passed : SE Number List is matching with Pre-report and Post-Report :"
                                        + strPostSENumberList);
                    } else {
                        System.out.println(
                                "Failed : SE Number List is not matching with Pre-report and Post-Report :"
                                        + strPostSENumberList);
                    }

                    String strPostPaymentMarketList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Payment Market')])[" + i + "]"))
                            .getText();

                    if (CommonData.strPaymentMarket.get(k).contains(strPostPaymentMarketList)) {
                        System.out
                                .println("Passed : Payment Market is matching with Pre-report and Post-Report :"
                                        + strPostPaymentMarketList);
                    } else {
                        System.out.println(
                                "Failed : Payment Market is not matching with Pre-report and Post-Report :"
                                        + strPostPaymentMarketList);
                    }

                    String strPostPaymentUnitList = driver
                            .findElement(By.xpath("(//div[contains(@onmouseover,'Payment Unit')])[" + i + "]"))
                            .getText();
                    if (CommonData.strPaymentunit.get(k).contains(strPostPaymentUnitList)) {
                        System.out.println(
                                "Passed : Payment Unit list is matching with Pre-report and Post-Report :"
                                        + strPostPaymentUnitList);
                    } else {
                        System.out.println(
                                "Failed : Payment Unit list is not matching with Pre-report and Post-Report :"
                                        + strPostPaymentUnitList);
                    }

                    String strPostLiabilityUnitList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Liability Unit')])[" + i + "]"))
                            .getText();
                    if (CommonData.strLiabilityUnit.get(k).contains(strPostLiabilityUnitList)) {
                        System.out.println(
                                "Passed : Liability Unit list is matching with Pre-report and Post-Report :"
                                        + strPostLiabilityUnitList);
                    } else {
                        System.out.println(
                                "Failed : Liability Unit list is not matching with Pre-report and Post-Report :"
                                        + strPostLiabilityUnitList);
                    }

                    String strPostLiabilityCurrencyList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Liability Currency')])[" + i + "]"))
                            .getText();
                    if (CommonData.strLiabilityCurrency.get(k).contains(strPostLiabilityCurrencyList)) {
                        System.out.println(
                                "Passed : Liability Currency list is matching with Pre-report and Post-Report :"
                                        + strPostLiabilityCurrencyList);
                    } else {
                        System.out.println(
                                "Failed : Liability Currency list is not matching with Pre-report and Post-Report :"
                                        + strPostLiabilityCurrencyList);
                    }

                    String strPostMarketCurrencyList = driver
                            .findElement(
                                    By.xpath("(//div[contains(@onmouseover,'Market Currency')])[" + i + "]"))
                            .getText();
                    if (CommonData.strMarketCurrency.get(k).contains(strPostMarketCurrencyList)) {
                        System.out.println(
                                "Passed : Market Currency list is matching with Pre-report and Post-Report :"
                                        + strPostMarketCurrencyList);
                    } else {
                        System.out.println(
                                "Failed : Market Currency list is not matching with Pre-report and Post-Report :"
                                        + strPostMarketCurrencyList);
                    }

                    String strPostInvoiceReleaseDateList;
                    if (i > 1) {
                        int j;
                        if (i == 3) {
                            j = i + 2;
                        } else {
                            j = i + 1;
                        }

                        strPostInvoiceReleaseDateList = driver.findElement(By.xpath(
                                "(//div[contains(@onmouseover,'This is the difference in cost between Invoice Total and Market Totals')]/nobr)["
                                        + j + "]"))
                                .getText();
                        if (CommonData.strInvoiceReleaseDate.get(k).contains(strPostInvoiceReleaseDateList)) {
                            System.out.println(
                                    "Passed : Invoice Release Date list is matching with Pre-report and Post-Report :"
                                            + strPostInvoiceReleaseDateList);
                        } else {
                            System.out.println(
                                    "Failed : Invoice Release Date list is not matching with Pre-report and Post-Report :"
                                            + strPostInvoiceReleaseDateList);
                        }
                    } else {
                        strPostInvoiceReleaseDateList = driver.findElement(By.xpath(
                                "(//div[contains(@onmouseover,'This is the difference in cost between Invoice Total and Market Totals')]/nobr)["
                                        + i + "]"))
                                .getText();
                        if (CommonData.strInvoiceReleaseDate.get(k).contains(strPostInvoiceReleaseDateList)) {
                            System.out.println(
                                    "Passed : Invoice Release Date list is matching with Pre-report and Post-Report :"
                                            + strPostInvoiceReleaseDateList);
                        } else {
                            System.out.println(
                                    "Failed : Invoice Release Date list is not matching with Pre-report and Post-Report :"
                                            + strPostInvoiceReleaseDateList);
                        }
                    }

                    String strPostUserIDList = driver
                            .findElement(By.xpath("(//div[contains(@onmouseover,'USER ID')])[" + i + "]"))
                            .getText();
                    if (CommonData.strUserId.get(k).contains(strPostUserIDList)) {
                        System.out.println("Passed : User ID list is matching with Pre-report and Post-Report :"
                                + strPostUserIDList);
                    } else {
                        System.out.println(
                                "Failed : User ID list is not matching with Pre-report and Post-Report :"
                                        + strPostUserIDList);
                    }

                }
                driver.switchTo().defaultContent();
                driver.close();
                driver.switchTo().window(postoldTab);
                System.out.println(
                        "########################## COMPLETED VALIDATIONS ALL ARE MATCHING ##################################");
            } else {
                System.out.println("Failed : Page Title is not matching with Pre-report and Post-Report");
            }

        } else {
            System.out.println("Failed to open the Multi user license page");
        }

    } else {
        System.out.println("Unable to open the Files and folder page after login");
    }
    driver.quit();
}

From source file:co.edu.icesi.i2t.slrtools.webdrivers.WebDriverACM.java

License:Open Source License

/**
 * Funcion que se encarga de realizar automaticamente la busqueda en la base
 * de datos ACM Digital Library conforme a una cadena de busqueda
 * introducida, ACM digital library no permite la descarga de ningun archivo
 * del resultado de la busqueda, por tal razn, se descarga el codigo fuente
 * de la pagina en el source del proyecto el cual posteriormente es usado
 * para la extraccin de la informacin y construccion del BIB con los
 * resultados obtenidos//from   ww w  .j  a v a 2  s . c o m
 *
 * @param searchStrings este parametro es la cadena de busqueda que retorna
 * la funcion mixACM#mixWords2, cada cadena de busqueda esta separada por ;
 * @param url este paremetro es el URL de la busqueda avanzada de ACM
 * Digital Library
 * @see mixWords.mixACM#mixWords2(java.lang.String, java.lang.String)
 */
public static void searchWeb(String searchStrings, String url) {
    /* a esta funcion se debe mejorar
     * 1: validar el boton siguiente sin try catch, mejorar el manejo de las expeciones
     */
    System.out.println("");
    System.out.println("-----------------------------");
    System.out.println("Searching ACM Digital Library...");
    System.out.println("Search strings: " + searchStrings + "");
    System.out.println("");

    FirefoxProfile profile = new FirefoxProfile();
    WebDriver webDriver = new FirefoxDriver(profile);
    String[] strings = searchStrings.split(";");
    for (int i = 0; i < strings.length; i++) {
        try {
            webDriver.get(url);

            WebElement searchField = webDriver.findElement(By.name("within"));
            searchField.click();
            searchField.sendKeys(strings[i]);

            WebElement buttonSearch = webDriver.findElement(By.name("Go"));
            buttonSearch.click();

            List<WebElement> stringResult = webDriver
                    .findElements(By.xpath("//span[contains(@style, 'background-color:yellow')]"));
            if (!stringResult.isEmpty()) {
                System.out.println(
                        "[WARNING] Search string " + (i + 1) + ": " + strings[i] + " retrieves no results");
            } else {
                int counter = 1;
                try {
                    WebElement nextField = null;
                    do {
                        String sourceCode = webDriver.getPageSource();
                        File targetDirectory = new File("files" + File.separator + Database.ACM.getName());
                        targetDirectory.mkdir();
                        try (PrintWriter file = new PrintWriter(
                                "files" + File.separator + Database.ACM.getName() + File.separator
                                        + "searchResults_" + i + "_" + counter + ".html",
                                "UTF-8")) {
                            file.print(sourceCode);
                        }
                        nextField = (new WebDriverWait(webDriver, 10))
                                .until(ExpectedConditions.presenceOfElementLocated(By.linkText("next")));
                        try {
                            Thread.sleep(10000);
                        } catch (InterruptedException e) {

                        }
                        nextField.click();
                        counter++;
                    } while (true);
                } catch (NoSuchElementException | TimeoutException | NullPointerException e) {
                    System.out.println("[INFO] Search string " + (i + 1) + ": " + strings[i] + " has "
                            + counter + (counter == 1 ? " result" : " results") + "returned");
                }
            }
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            System.out.println(
                    "[ERROR] Search string " + (i + 1) + ": " + strings[i] + " failed. " + e.getMessage());
        } catch (NoSuchElementException e) {
            System.out.println(
                    "[ERROR] The application has been blocked by ACM Digital Library. Try again later.");
        }
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {

        }
    }
    webDriver.quit();
    System.out.println("[INFO] Finished search in ACM Digital Library");
    System.out.println("-----------------------------");
}

From source file:com.adasasistemas.pilot.webtest3.NewSeleneseIT.java

@Test
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.
    FirefoxProfile fp = new FirefoxProfile();

    //   fp.setPreference("browser.startup.homepage", URL);
    // fp.setPreference("startup.homepage_welcome_url", URL);
    //fp.setPreference("startup.homepage_welcome_url.additional", URL);
    FirefoxBinary fb = new FirefoxBinary(new File(NAVIGATOR));
    WebDriver driver = new FirefoxDriver(fb, fp);

    // And now use this to visit NetBeans
    //  driver.get("http://www.netbeans.org");
    // 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
    driver.navigate().to("http://localhost:8085/webtest3");
    //* driver.navigate().refresh();
    //  driver.get("http://localhost:8085/webtest3");
    //    System.out.println(driver.getPageSource());

    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override/*from  www  . j  ava 2 s.c o  m*/
        public Boolean apply(WebDriver d) {
            System.out.println(d.getPageSource());
            return d.getPageSource().contains("Hello");
        }
    });

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

From source file:com.amazon.alexa.avs.AVSApp.java

License:Open Source License

/**
 * Authenticates this client to LWA./*from  w  w w  . ja v  a  2s  .  c om*/
 * 
 * @param url Login URL to perform authentification to.
 */
private void authenticate(final String url) {
    log.info("Registration URL = {}", url);
    final WebDriver driver = createDriver();
    driver.get(url);
    // TODO : Consider adding sleep to ensure page loading.
    authenticate(driver);
    log.info("Authentification done, check for agreemennt validation");
    // TODO : Consider adding sleep to ensure page loading.
    validateAgreement(driver);
    log.info(driver.getPageSource());
    log.info("Waiting for authentification callback to be triggered");
    // TODO : Consider adding sleep to ensure page loading.
    driver.quit();
}

From source file:com.asimihsan.handytrowel.network.HTMLFetcher.java

License:Open Source License

public String getPageSource(final String url) throws TimeoutException {

    // Make the Selenium WebDriver logs be quiet
    phantomJsLogger.setLevel(Level.OFF);

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.phantomjs();
    // What other CLI args there are: http://phantomjs.org/api/command-line.html
    // Where the cache goes on Mac OS X: ~/Library/Application\ Support/Ofi\ Labs/PhantomJS/
    // Other cache locations: https://groups.google.com/forum/#!topic/phantomjs/8GYaXKmowj0
    desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
            new String[] { "--ignore-ssl-errors=yes", "--load-images=no", "--disk-cache=true",
                    "--max-disk-cache-size=size=51200" });
    final WebDriver driver = new PhantomJSDriver(desiredCapabilities);

    // doesn't work, keep as reference.
    //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    try {/* w w w.  j a  v  a2s.co m*/
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                driver.get(url);
            }
        });
        t.start();
        try {
            t.join(timeoutMillis);
        } catch (InterruptedException e) {
        }
        if (t.isAlive()) {
            System.out.println("Timeout for HTTP GET to: " + url);
            t.interrupt();
            throw new TimeoutException();
        }
        String pageSource = driver.getPageSource();
        return pageSource;
    } finally {
        driver.quit();
    }
}

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

License:Open Source License

/**
 * Method to log screenshot to log file.
 * // w  w w  .ja  v a  2  s.c o m
 * @param webDriver
 *            (web driver object)
 * @param linkText
 *            (text to log)
 */
public void logScreenShot(final WebDriver webDriver, final String linkText) {
    if (screenShotsDirectory != null) {
        File screenShotFile = new File(screenShotsDirectory, getUniqueString() + ".html");
        try {
            FileUtils.writeStringToFile(screenShotFile, webDriver.getPageSource());
            Reporter.log(
                    "<a href=\"" + screenShotFile.getName() + "\" target=\"_blank\">" + linkText + "</a><br>");
        } catch (IOException e) {
            Reporter.log("Unable to log screenshot");
        }
    } else {
        Reporter.log("Screenshots directory not set. Not logging screenshot");
    }
}