Example usage for org.openqa.selenium WebElement findElements

List of usage examples for org.openqa.selenium WebElement findElements

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement findElements.

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current context using the given mechanism.

Usage

From source file:com.osbitools.ws.shared.prj.xui.GenericPrjMgrGuiWebTest.java

License:LGPL

private void checkContextMenu(String lang, WebElement menu, String[][] mlist) throws InterruptedException {

    List<WebElement> menus = menu.findElements(By.tagName("li"));
    assertEquals(mlist.length, menus.size());

    // Check each menu item
    for (int i = 0; i < mlist.length; i++) {
        String[] mitem = mlist[i];

        WebElement mi = menus.get(i);// w w  w.  j a va2 s  .  c  o m
        if (mitem == null)
            // Check for divider
            assertEquals("divider", mi.getAttribute("class"));
        else
            // Check for menu item
            checkContextMenuItem(lang, mi, TestConstants.GUI_SRV_URL_BASE + mitem[1], mitem[0]);
    }

    // Cancel context menu
    driver.findElement(By.className("contextMenuPluginCtrl")).click();

    // Check menu disappear
    try {
        driver.findElement(By.className("contextMenuPlugin"));
        Thread.sleep(2000);
        fail("Context menu is still visible");
    } catch (NoSuchElementException e) {
    }

    Thread.sleep(500);
}

From source file:com.osbitools.ws.shared.prj.xui.GenericPrjMgrGuiWebTest.java

License:LGPL

public void checkSelList(WebElement sel, String[][] list) {
    assertNotNull(sel);/* w  w w  .  ja  va2  s. com*/
    List<WebElement> ops = sel.findElements(By.tagName("option"));
    assertNotNull(ops);
    assertEquals(list.length, ops.size());
    for (int i = 0; i < list.length; i++) {
        WebElement op = ops.get(i);
        String[] el = list[i];

        assertEquals(el[0], op.getText());
        assertEquals(el[1], op.getAttribute("value"));
    }
}

From source file:com.osbitools.ws.shared.prj.xui.GenericPrjMgrGuiWebTest.java

License:LGPL

public void checkComponentList(String lang, boolean visible) {
    HashMap<String, ArrayList<String>> clist = getComponentList();
    // Count total number of elements
    int clen = 0;
    for (ArrayList<String> ar : clist.values())
        clen += ar.size() + 1;/*from   ww w .j  a v a  2  s  .c om*/

    WebElement icons = driver.findElement(By.id("icon_list"));
    checkElementVisible(icons, "icon_list", visible);

    List<WebElement> components = icons.findElements(By.cssSelector("h4,img"));
    assertNotNull(components);

    assertEquals(clen, components.size());

    int idx = 0;
    for (String cname : clist.keySet()) {
        // Invisible element doesn't return text
        if (visible)
            assertEquals(getLabelText(lang, cname), components.get(idx).getText());
        idx++;

        for (String src : clist.get(cname)) {
            assertEquals(TestConstants.GUI_SRV_URL_BASE + src, components.get(idx).getAttribute("src"));
            idx++;
        }
    }
}

From source file:com.pentaho.ctools.cdf.require.SchedulePrptComponent.java

License:Apache License

/**
 * ############################### Test Case 2 ###############################
 *
 * Test Case Name://from   w  w  w  .j  a  v a 2  s .c o m
 *    Create a Schedule
 * Description:
 *    It is supposed to create a schedule and validate it was created with
 *    specify data and date.
 * Steps:
 *    1. Click to create a schedule prpt.
 *    2. Fill the form and submit
 *    3. Check for alert.
 *    4. On Schedule Manager, it is set the schedule.
 * @throws InterruptedException
 */
@Test
public void tc3_SchedulePrpt_ScheduleCreatedSuccessful() {
    this.log.info("tc3_SchedulePrpt_ScheduleCreatedSuccessful");
    this.bRemoveSchedule = true;
    String schLocation = "/public";

    //Initialize some data
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    SimpleDateFormat sdfDay = new SimpleDateFormat("d");
    Date dNow = new Date();
    Calendar c = Calendar.getInstance();
    c.setTime(dNow);
    c.add(Calendar.DATE, 1);
    Date dTomorrow = c.getTime();
    c.add(Calendar.DATE, 40); //30th days from today
    Date d40days = c.getTime();

    /*
     * ## Step 1
     */
    this.elemHelper.FindElement(driver, By.xpath("//div[@id='sampleObject']/button")).click();

    /*
     * ## Step 2
     */
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("jqistate_basicState")));
    //Set schedule name
    this.elemHelper.FindElement(driver, By.id("nameIn")).clear();
    this.elemHelper.FindElement(driver, By.id("nameIn")).sendKeys(this.schNameTc3);
    //Set schedule location
    this.elemHelper.FindElement(driver, By.id("locationIn")).clear();
    this.elemHelper.FindElement(driver, By.id("locationIn")).sendKeys(schLocation);
    //Select Monthly
    Select slRecurrence = new Select(this.elemHelper.FindElement(driver, By.id("recurrId")));
    slRecurrence.selectByValue("monthly");
    //Select Hour
    Select slHours = new Select(this.elemHelper.FindElement(driver, By.id("hours")));
    slHours.selectByValue("9");
    //Select Minutes
    Select slMinutes = new Select(this.elemHelper.FindElement(driver, By.id("minutes")));
    slMinutes.selectByValue("17");
    //Select AM/FM
    Select slAMFM = new Select(this.elemHelper.FindElement(driver, By.id("amPm")));
    slAMFM.selectByValue("pm");
    //Select Option 'The x y of every month
    this.elemHelper.Click(driver, By.xpath("//div[@id='patternMonth']/input[2]"));
    //Select Month
    Select slOccDay = new Select(this.elemHelper.FindElement(driver, By.id("monthOpt1Select")));
    slOccDay.selectByValue("1");
    //Select Wednesday
    Select slWeekday = new Select(this.elemHelper.FindElement(driver, By.id("monthOpt2Select")));
    slWeekday.selectByValue("3");
    //Select Range Of Recurrence
    //Start - tomorrow
    this.elemHelper.FindElement(driver, By.id("rangeStartIn")).clear();
    this.elemHelper.FindElement(driver, By.id("rangeStartIn")).sendKeys(sdf.format(dTomorrow));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//table[@class='ui-datepicker-calendar']")));
    WebElement dateCalendar = this.elemHelper.FindElement(driver,
            By.xpath("//table[@class='ui-datepicker-calendar']"));
    List<WebElement> columns = dateCalendar.findElements(By.tagName("td"));
    String tomorrowDay = sdfDay.format(dTomorrow);
    for (WebElement cell : columns) {
        String strCell = cell.getText();
        if (strCell.equals(tomorrowDay)) {
            cell.findElement(By.linkText(tomorrowDay)).click();
            break;
        }
    }
    //End
    //Select End Date
    wait.until(ExpectedConditions.elementToBeClickable(By.id("endByRadio")));
    this.elemHelper.FindElement(driver, By.id("endByRadio")).click();
    this.elemHelper.FindElement(driver, By.id("endByIn")).sendKeys(sdf.format(d40days));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//table[@class='ui-datepicker-calendar']")));
    WebElement dateCalendar2 = this.elemHelper.FindElement(driver,
            By.xpath("//table[@class='ui-datepicker-calendar']"));
    List<WebElement> columns2 = dateCalendar2.findElements(By.tagName("td"));
    String day = sdfDay.format(d40days);
    for (WebElement cell2 : columns2) {
        String strCell2 = cell2.getText();
        if (strCell2.equals(day)) {
            cell2.findElement(By.linkText(day)).click();
            break;
        }
    }

    //Submit Form
    wait.until(ExpectedConditions.elementToBeClickable(By.id("jqi_basicState_buttonOk")));
    this.elemHelper.FindElement(driver, By.id("jqi_basicState_buttonOk")).click();
    //Wait for the new window.
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("jqistate_mailState")));
    wait.until(ExpectedConditions.elementToBeClickable(By.id("jqi_mailState_buttonOk")));
    this.elemHelper.FindElement(driver, By.id("jqi_mailState_buttonOk")).click();

    // ## Step 3
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals(confirmationMsg, "Successfully scheduled.");

    /*
     * ## Step 4
     */
    //-->Need to check if the schedule was created
    //Go to home page
    driver.get(PageUrl.PUC);

    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

    //Click in Schedule
    wait.until(ExpectedConditions.titleContains("Pentaho User Console"));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div[@id='pucUserDropDown']/table/tbody/tr/td/div")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[@id='home.perspective']")));
    wait.until(ExpectedConditions
            .elementToBeClickable(By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]")));
    this.elemHelper
            .FindElement(driver, By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]"))
            .click();
    WebElement listMenyTr = this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='customDropdownPopupMajor']/div/div/table/tbody"));
    List<WebElement> listMenuElementsTrs = listMenyTr.findElements(By.xpath("//td[@class='gwt-MenuItem']"));
    for (int i = 0; i < listMenuElementsTrs.size(); i++) {
        WebElement element = listMenuElementsTrs.get(i);
        if (element.getText().equals("Schedules")) {
            element.click();
            break;
        }
    }
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.workspaceHeading")));
    // Now we are in Schedule page
    List<WebElement> listScheduleTrs = this.elemHelper
            .FindElement(driver, By.xpath("//table[@id='schedule-table']/tbody"))
            .findElements(By.tagName("tr"));
    String scheduleName = "";
    String scheduleRepeats = "";
    String scheduleSourceFile = "";
    String scheduleOuputLocation = "";
    String scheduleLastRun = "";
    String scheduleNextRun = "";
    String scheduleCreatedBy = "";
    String scheduleStatus = "";
    for (int j = 1; j <= listScheduleTrs.size(); j++) {
        WebElement elementFirstDiv = this.elemHelper.FindElement(driver,
                By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td/div"));
        scheduleName = elementFirstDiv.getText();
        if (scheduleName.equals(this.schNameTc3)) {

            scheduleRepeats = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[2]/div"));
            scheduleSourceFile = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[3]/div"));
            scheduleOuputLocation = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[4]/div"));
            scheduleLastRun = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[5]/div"));
            scheduleNextRun = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[6]/div"));
            scheduleCreatedBy = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[7]/div"));
            scheduleStatus = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[8]/div"));
            break;
        }
    }

    //Getting the week day of next run
    String dayOfWeek = "";
    if (!scheduleNextRun.isEmpty()) {
        try {
            Date dateNextRun = new SimpleDateFormat("yyyy MMM dd HH:mm:ss", Locale.US).parse(scheduleNextRun);
            dayOfWeek = new SimpleDateFormat("EE", Locale.US).format(dateNextRun);
        } catch (ParseException pe) {
            this.log.error(pe.getMessage());
        }
    }

    assertEquals(this.schNameTc3, scheduleName);
    assertEquals("The second Wednesday of every month at 21:17:00", scheduleRepeats);
    assertEquals("/public/Steel Wheels/Widget Library/Report Snippets/InventorybyLine", scheduleSourceFile);
    assertEquals(schLocation, scheduleOuputLocation);
    assertEquals("-", scheduleLastRun);
    assertEquals("Wed", dayOfWeek);
    assertEquals("admin", scheduleCreatedBy);
    assertEquals("Normal", scheduleStatus);
}

From source file:com.pentaho.ctools.cdf.require.SchedulePrptComponent.java

License:Apache License

/**
 * This method will remove all created schedules on the tests.
 * Note - for a new schedule update code.
 *//*from w w  w  .  jav a  2 s  .c  om*/
private void removeAllCreatedSchedules() {
    this.log.info("removeAllCreatedSchedules");
    //Go to home page
    driver.get(PageUrl.PUC);
    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

    //Click in Schedule
    wait.until(ExpectedConditions.titleContains("Pentaho User Console"));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div[@id='pucUserDropDown']/table/tbody/tr/td/div")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[@id='home.perspective']")));
    wait.until(ExpectedConditions
            .elementToBeClickable(By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]")));
    this.elemHelper
            .FindElement(driver, By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]"))
            .click();
    WebElement listMenyTr = this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='customDropdownPopupMajor']/div/div/table/tbody"));
    List<WebElement> listMenuElementsTrs = listMenyTr.findElements(By.xpath("//td[@class='gwt-MenuItem']"));
    for (int i = 0; i < listMenuElementsTrs.size(); i++) {
        WebElement element = listMenuElementsTrs.get(i);
        if (element.getText().equals("Schedules")) {
            element.click();
            break;
        }
    }

    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.workspaceHeading")));

    // Now we are in Schedule page
    Boolean someThingToDelete = true;
    int listElements = 0;
    int listElementsPrevious = -1;
    while (someThingToDelete) {
        someThingToDelete = false;
        List<WebElement> listScheduleTrs = this.elemHelper
                .FindElement(driver, By.xpath("//table[@id='schedule-table']/tbody"))
                .findElements(By.tagName("tr"));
        listElements = listScheduleTrs.size();

        //The new list must be different from previous list
        while (listElements == listElementsPrevious) {
            listScheduleTrs = this.elemHelper
                    .FindElement(driver, By.xpath("//table[@id='schedule-table']/tbody"))
                    .findElements(By.tagName("tr"));
            listElements = listScheduleTrs.size();
        }

        for (int j = 1; j <= listElements; j++) {
            WebElement elementFirstDiv = this.elemHelper.FindElement(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td/div"));

            if (elementFirstDiv.getText().equals(this.schNameTc3)) {
                elementFirstDiv.click(); //Select the row

                //Wait for row to be selected
                for (int t = 0; t < 100; t++) {
                    WebElement elementRow = this.elemHelper.FindElement(driver,
                            By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]"));

                    if (elementRow.getAttribute("class").contains("cellTableSelectedRow")) {
                        break;
                    }
                }

                //Click to remove the schedule item (the selected row)
                this.elemHelper.Click(driver, By.cssSelector("img.gwt-Image.pentaho-deletebutton"));
                this.elemHelper.WaitForElementPresenceAndVisible(driver,
                        By.xpath("//div[@class='pentaho-dialog']"));
                this.elemHelper.Click(driver, By.id("okButton"));

                this.elemHelper.WaitForElementInvisibility(driver, By.xpath("//div[@class='pentaho-dialog']"));

                someThingToDelete = true; //Continue checking if there is something to delete
                break;
            }
        }
        listElementsPrevious = listElements;
    }
}

From source file:com.pentaho.ctools.cdf.SchedulePrptComponent.java

License:Apache License

/**
 * ############################### Test Case 2 ###############################
 *
 * Test Case Name:/*from   w  w w .j a v a2 s .  c o m*/
 *    Create a Schedule
 * Description:
 *    It is supposed to create a schedule and validate it was created with
 *    specify data and date.
 * Steps:
 *    1. Click to create a schedule prpt.
 *    2. Fill the form and submit
 *    3. Check for alert.
 *    4. On Schedule Manager, it is set the schedule.
 * @throws InterruptedException
 */
@Test
public void tc3_SchedulePrpt_ScheduleCreatedSuccessful() {
    this.log.info("tc3_SchedulePrpt_ScheduleCreatedSuccessful");
    this.bRemoveSchedule = true;

    String schLocation = "/public";

    //Initialize some data
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    SimpleDateFormat sdfDay = new SimpleDateFormat("d");
    Date dNow = new Date();
    Calendar c = Calendar.getInstance();
    c.setTime(dNow);
    c.add(Calendar.DATE, 1);
    Date dTomorrow = c.getTime();
    c.add(Calendar.DATE, 40); //30th days from today
    Date d40days = c.getTime();

    // ## Step 1
    this.elemHelper.FindElement(driver, By.xpath("//span[@id='sampleObject']/button")).click();

    // ## Step 2
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("jqistate_basicState")));
    //Set schedule name
    this.elemHelper.FindElement(driver, By.id("nameIn")).clear();
    this.elemHelper.FindElement(driver, By.id("nameIn")).sendKeys(this.schNameTc3);
    //Set schedule location
    this.elemHelper.FindElement(driver, By.id("locationIn")).clear();
    this.elemHelper.FindElement(driver, By.id("locationIn")).sendKeys(schLocation);
    //Select Monthly
    Select slRecurrence = new Select(this.elemHelper.FindElement(driver, By.id("recurrId")));
    slRecurrence.selectByValue("monthly");
    //Select Hour
    Select slHours = new Select(this.elemHelper.FindElement(driver, By.id("hours")));
    slHours.selectByValue("9");
    //Select Minutes
    Select slMinutes = new Select(this.elemHelper.FindElement(driver, By.id("minutes")));
    slMinutes.selectByValue("17");
    //Select AM/FM
    Select slAMFM = new Select(this.elemHelper.FindElement(driver, By.id("amPm")));
    slAMFM.selectByValue("pm");
    //Select Option 'The x y of every month
    this.elemHelper.FindElement(driver, By.xpath("//div[@id='patternMonth']/input[2]")).click();
    //Select Month
    Select slOccDay = new Select(this.elemHelper.FindElement(driver, By.id("monthOpt1Select")));
    slOccDay.selectByValue("1");
    //Select Wednesday
    Select slWeekday = new Select(this.elemHelper.FindElement(driver, By.id("monthOpt2Select")));
    slWeekday.selectByValue("3");
    //Select Range Of Recurrence
    //Start - tomorrow
    this.elemHelper.FindElement(driver, By.id("rangeStartIn")).clear();
    this.elemHelper.FindElement(driver, By.id("rangeStartIn")).sendKeys(sdf.format(dTomorrow));
    this.elemHelper.Click(driver, By.id("rangeStartIn"));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//table[@class='ui-datepicker-calendar']")));
    WebElement dateCalendar = this.elemHelper.FindElement(driver,
            By.xpath("//table[@class='ui-datepicker-calendar']"));
    List<WebElement> columns = dateCalendar.findElements(By.tagName("td"));
    String tomorrowDay = sdfDay.format(dTomorrow);
    for (WebElement cell : columns) {
        String strCell = cell.getText();
        if (strCell.equals(tomorrowDay)) {
            cell.findElement(By.linkText(tomorrowDay)).click();
            break;
        }
    }
    //End
    //Select End Date
    wait.until(ExpectedConditions.elementToBeClickable(By.id("endByRadio")));
    this.elemHelper.FindElement(driver, By.id("endByRadio")).click();
    this.elemHelper.FindElement(driver, By.id("endByIn")).sendKeys(sdf.format(d40days));
    this.elemHelper.FindElement(driver, By.id("endByIn")).click();
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//table[@class='ui-datepicker-calendar']")));
    WebElement dateCalendar2 = this.elemHelper.FindElement(driver,
            By.xpath("//table[@class='ui-datepicker-calendar']"));
    List<WebElement> columns2 = dateCalendar2.findElements(By.tagName("td"));
    String day = sdfDay.format(d40days);
    for (WebElement cell2 : columns2) {
        String strCell2 = cell2.getText();
        if (strCell2.equals(day)) {
            cell2.findElement(By.linkText(day)).click();
            break;
        }
    }

    //Submit Form
    wait.until(ExpectedConditions.elementToBeClickable(By.id("jqi_basicState_buttonOk")));
    this.elemHelper.FindElement(driver, By.id("jqi_basicState_buttonOk")).click();
    //Wait for the new window.
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("jqistate_mailState")));
    wait.until(ExpectedConditions.elementToBeClickable(By.id("jqi_mailState_buttonOk")));
    this.elemHelper.FindElement(driver, By.id("jqi_mailState_buttonOk")).click();

    // ## Step 3
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();
    assertEquals(confirmationMsg, "Successfully scheduled.");

    // ## Step 4
    //-->Need to check if the schedule was created
    //Go to home page
    driver.get(PageUrl.PUC);

    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

    //Click in Schedule
    wait.until(ExpectedConditions.titleContains("Pentaho User Console"));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div[@id='pucUserDropDown']/table/tbody/tr/td/div")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[@id='home.perspective']")));
    wait.until(ExpectedConditions
            .elementToBeClickable(By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]")));
    this.elemHelper
            .FindElement(driver, By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]"))
            .click();
    WebElement listMenyTr = this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='customDropdownPopupMajor']/div/div/table/tbody"));
    List<WebElement> listMenuElementsTrs = listMenyTr.findElements(By.xpath("//td[@class='gwt-MenuItem']"));
    for (int i = 0; i < listMenuElementsTrs.size(); i++) {
        WebElement element = listMenuElementsTrs.get(i);
        if (element.getText().equals("Schedules")) {
            element.click();
            break;
        }
    }
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.workspaceHeading")));
    // Now we are in Schedule page
    List<WebElement> listScheduleTrs = this.elemHelper
            .FindElement(driver, By.xpath("//table[@id='schedule-table']/tbody"))
            .findElements(By.tagName("tr"));
    String scheduleName = "";
    String scheduleRepeats = "";
    String scheduleSourceFile = "";
    String scheduleOuputLocation = "";
    String scheduleLastRun = "";
    String scheduleNextRun = "";
    String scheduleCreatedBy = "";
    String scheduleStatus = "";
    for (int j = 1; j <= listScheduleTrs.size(); j++) {
        WebElement elementFirstDiv = this.elemHelper.FindElement(driver,
                By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td/div"));
        scheduleName = elementFirstDiv.getText();
        if (scheduleName.equals(this.schNameTc3)) {

            scheduleRepeats = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[2]/div"));
            scheduleSourceFile = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[3]/div"));
            scheduleOuputLocation = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[4]/div"));
            scheduleLastRun = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[5]/div"));
            scheduleNextRun = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[6]/div"));
            scheduleCreatedBy = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[7]/div"));
            scheduleStatus = this.elemHelper.WaitForElementPresentGetText(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td[8]/div"));
            break;
        }
    }

    //Getting the week day of next run
    String dayOfWeek = "";
    if (!scheduleNextRun.isEmpty()) {
        try {
            Date dateNextRun = new SimpleDateFormat("yyyy MMM dd HH:mm:ss", Locale.US).parse(scheduleNextRun);
            dayOfWeek = new SimpleDateFormat("EE", Locale.US).format(dateNextRun);
        } catch (ParseException pe) {
            this.log.error(pe.getMessage());
        }
    }

    assertEquals(this.schNameTc3, scheduleName);
    assertEquals("The second Wednesday of every month at 21:17:00", scheduleRepeats);
    assertEquals("/public/Steel Wheels/Widget Library/Report Snippets/InventorybyLine", scheduleSourceFile);
    assertEquals(schLocation, scheduleOuputLocation);
    assertEquals("-", scheduleLastRun);
    assertEquals("Wed", dayOfWeek);
    assertEquals("admin", scheduleCreatedBy);
    assertEquals("Normal", scheduleStatus);
}

From source file:com.pentaho.ctools.cdf.SchedulePrptComponent.java

License:Apache License

/**
 * This method will remove all created schedules on the tests.
 * Note - for a new schedule update code.
 *//*from  ww  w .  j ava 2 s  . c om*/
private void removeAllCreatedSchedules() {
    this.log.info("removeAllCreatedSchedules");

    //Go to home page
    driver.get(PageUrl.PUC);
    // NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver,
            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

    //Click in Schedule
    wait.until(ExpectedConditions.titleContains("Pentaho User Console"));
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div[@id='pucUserDropDown']/table/tbody/tr/td/div")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//iframe[@id='home.perspective']")));
    wait.until(ExpectedConditions
            .elementToBeClickable(By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]")));
    this.elemHelper
            .FindElement(driver, By.xpath("//div[@id='mantle-perspective-switcher']/table/tbody/tr/td[2]"))
            .click();
    WebElement listMenyTr = this.elemHelper.FindElement(driver,
            By.xpath("//div[@id='customDropdownPopupMajor']/div/div/table/tbody"));
    List<WebElement> listMenuElementsTrs = listMenyTr.findElements(By.xpath("//td[@class='gwt-MenuItem']"));
    for (int i = 0; i < listMenuElementsTrs.size(); i++) {
        WebElement element = listMenuElementsTrs.get(i);
        if (element.getText().equals("Schedules")) {
            element.click();
            break;
        }
    }

    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.workspaceHeading")));

    // Now we are in Schedule page
    Boolean someThingToDelete = true;
    int listElements = 0;
    int listElementsPrevious = -1;
    while (someThingToDelete) {
        someThingToDelete = false;
        List<WebElement> listScheduleTrs = this.elemHelper
                .FindElement(driver, By.xpath("//table[@id='schedule-table']/tbody"))
                .findElements(By.tagName("tr"));
        listElements = listScheduleTrs.size();

        //The new list must be different from previous list
        while (listElements == listElementsPrevious) {
            listScheduleTrs = this.elemHelper
                    .FindElement(driver, By.xpath("//table[@id='schedule-table']/tbody"))
                    .findElements(By.tagName("tr"));
            listElements = listScheduleTrs.size();
        }

        for (int j = 1; j <= listElements; j++) {
            WebElement elementFirstDiv = this.elemHelper.FindElement(driver,
                    By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]/td/div"));

            if (elementFirstDiv.getText().equals(this.schNameTc3)) {
                elementFirstDiv.click(); //Select the row

                //Wait for row to be selected
                for (int t = 0; t < 100; t++) {
                    WebElement elementRow = this.elemHelper.FindElement(driver,
                            By.xpath("//table[@id='schedule-table']/tbody/tr[" + j + "]"));

                    if (elementRow.getAttribute("class").contains("cellTableSelectedRow")) {
                        break;
                    }
                }

                //Click to remove the schedule item (the selected row)
                this.elemHelper.Click(driver, By.cssSelector("img.gwt-Image.pentaho-deletebutton"));
                this.elemHelper.WaitForElementPresenceAndVisible(driver,
                        By.xpath("//div[@class='pentaho-dialog']"));
                this.elemHelper.Click(driver, By.id("okButton"));

                this.elemHelper.WaitForElementInvisibility(driver, By.xpath("//div[@class='pentaho-dialog']"));

                someThingToDelete = true; //Continue checking if there is something to delete
                break;
            }
        }
        listElementsPrevious = listElements;
    }
}

From source file:com.pentaho.gui.web.puc.BrowseFiles.java

License:Apache License

/**
 * This method will empty a folder in the repository given the full path to it, including the folder name
 *
 * Ex. "/public/plugin-samples/pentaho-cdf-dd" the SelectFolder method will be called with the path provided, it it
 * returns false an info will be shown on the logs saying the file wasn't deleted for it wasn't found. If it returns
 * true, all files shown on the files table will be selected, Delete button will be clicked on File Actions, it will
 * wait for popup and confirm the delete action.
 *
 * @param path/*from w w  w  . j a  va2s  .  c  om*/
 */
public void EmptyFolder(String path) {
    if (SelectFolder(path)) {
        WebElement listFiles = this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                By.xpath("//div[@id='fileBrowserFiles']/div[2]"));
        List<WebElement> AllFolderFiles = listFiles.findElements(By.xpath("//div[@class='title']"));

        // Check if the widget named exist
        if (AllFolderFiles != null) {
            if (AllFolderFiles.size() > 0) {
                WebElement[] arrayAllFolderFiles = new WebElement[AllFolderFiles.size()];
                AllFolderFiles.toArray(arrayAllFolderFiles);

                // Where we want to select three files
                // <the widget>
                // <the widget>.cdfde
                // <the widget>.component.xml
                // To do that we select each file (using the CONTROL key) and delete them.
                Actions action = new Actions(this.DRIVER);
                action.keyDown(Keys.CONTROL);
                for (WebElement arrayAllFolderFile : arrayAllFolderFiles) {
                    action.click(arrayAllFolderFile);
                }
                action.keyUp(Keys.CONTROL);
                action.build().perform();

                // Here we still in the iframe
                assertNotNull(this.elemHelper.WaitForElementVisibility(this.DRIVER, By.id("deleteButton")));
                this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("deleteButton")).click();
                // Go back to root html
                this.DRIVER.switchTo().defaultContent();
                assertEquals(this.elemHelper
                        .WaitForElementPresenceAndVisible(this.DRIVER, By.cssSelector("div.gwt-HTML"))
                        .getText(), "Are you sure you want to move all selected items to the trash?");
                this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("okButton")).click();

                // wait for visibility of waiting pop-up
                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("//div[@class='busy-indicator-container waitPopup']"));

                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("//div[@class='spinner large-spinner']"));
                this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                        By.xpath("(//div[@class='spinner large-spinner'])[2]"));

            }
        }
    } else {
        LOG.info("folder not emptied for it was not found");
    }
}

From source file:com.pentaho.gui.web.puc.BrowseFiles.java

License:Apache License

/**
 * Given the path to a folder this method will delete all files located in that folder that contain a specific string
 * in the name/*www  .  j  a va  2 s.c om*/
 *
 * Ex. "/public/plugin-samples/pentaho-cdf-dd" the SelectFolder method will be called with the path provided, it it
 * returns false an info will be shown on the logs saying the file wasn't deleted for it wasn't found.
 *
 * If it returns true, all files containing string "name" provided in the name will be selected, Delete button will be
 * clicked on File Actions, it will wait for popup and confirm the delete action.
 *
 * @param path
 * @param name
 */
public void DeleteMultipleFilesByName(String path, String name) {
    LOG.debug("DeleteMultipleFilesByName::Enter");
    if (SelectFolder(path)) {
        LOG.debug("Deleting [" + path + "] with name [" + name + "]");

        WebElement elemWidgetFile = this.elemHelper.WaitForElementPresence(this.DRIVER,
                By.cssSelector("div[title='" + name + ".wcdf']"), 1);
        if (elemWidgetFile != null) {
            WebElement listFiles = this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                    By.xpath("//div[@id='fileBrowserFiles']/div[2]"));
            List<WebElement> theNamedFiles = listFiles
                    .findElements(By.xpath("//div[@class='title' and contains(text(),'" + name + "')]"));

            // Check if the widget named exist
            if (theNamedFiles != null) {
                if (theNamedFiles.size() > 0) {
                    WebElement[] arraytheNamedFiles = new WebElement[theNamedFiles.size()];
                    theNamedFiles.toArray(arraytheNamedFiles);

                    // Where we want to select three files
                    // <the widget>
                    // <the widget>.cdfde
                    // <the widget>.component.xml
                    // To do that we select each file (using the CONTROL key) and delete them.
                    Actions action = new Actions(this.DRIVER);
                    action.keyDown(Keys.CONTROL);
                    for (WebElement arraytheNamedFile : arraytheNamedFiles) {
                        action.click(arraytheNamedFile);
                    }
                    action.keyUp(Keys.CONTROL);
                    action.build().perform();

                    // Here we still in the iframe
                    assertNotNull(this.elemHelper.WaitForElementVisibility(this.DRIVER, By.id("deleteButton")));
                    this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("deleteButton"))
                            .click();
                    // Go back to root html
                    this.DRIVER.switchTo().defaultContent();
                    assertEquals(
                            this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                                    By.cssSelector("div.gwt-HTML")).getText(),
                            "Are you sure you want to move all selected items to the trash?");
                    this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER, By.id("okButton")).click();

                    // wait for visibility of waiting pop-up
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='busy-indicator-container waitPopup']"));

                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.id("applicationShell")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//iframe[@id='browser.perspective']")));
                    this.DRIVER.switchTo().frame("browser.perspective");

                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.id("fileBrowser")));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='spinner large-spinner']"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("(//div[@class='spinner large-spinner'])[2]"));

                    this.elemHelper.Click(this.DRIVER, By.id("refreshBrowserIcon"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("//div[@class='spinner large-spinner']"));
                    this.elemHelper.WaitForElementInvisibility(this.DRIVER,
                            By.xpath("(//div[@class='spinner large-spinner'])[2]"));

                    // Assert Panels
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserFolders']")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserFiles']")));
                    assertNotNull(this.elemHelper.WaitForElementPresenceAndVisible(this.DRIVER,
                            By.xpath("//div[@id='fileBrowserButtons']")));
                    LOG.info("Exit: Assert browser perspective shown");
                } else {
                    LOG.debug("No file exist!");
                }
            } else {
                LOG.debug("Null - No file exist!");
            }
        } else {
            LOG.warn("The widget does not exist.");
        }
    } else {
        LOG.info("Files were not deleted or folder was not found!");
    }
}

From source file:com.perceptron.findjesus.WeightedBestFirstSearch.java

License:MIT License

private void getAllCurrentPageLinks(ArrayList<String> links) {
    // I'm only interested in links within the content
    WebElement content = browser.findElement(By.id("mw-content-text"));
    // I'm assuming for now that all links will be in <a> tags
    List<WebElement> tags = content.findElements(By.tagName("a"));
    for (WebElement current : tags) {
        String link = current.getAttribute("href");
        if (link != null) {
            // We only accept links that keep us on wikipedia
            if (link.contains(baseURL)) {
                links.add(link);/* w  w  w .  j a v a 2  s  . co  m*/
            }
        }
    }
    tags.clear();
}