Example usage for org.openqa.selenium WebElement getText

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

Introduction

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

Prototype

String getText();

Source Link

Document

Get the visible (i.e.

Usage

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

License:Apache License

/**
 * testUsers02()./*from   w w  w  .  j  a v a2s .  c o  m*/
 * Add User
 *
 * @throws Exception Exception
 */
@Test
public void testUsers02() throws Exception {
    // given
    String email = "test2@formkiq.com";

    // when
    findElementBy(By.id("user_add_button")).click();

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("form-modal")));

    findElementBy("input", "data-valuekey", "email").sendKeys(email);

    // then
    assertEquals("ROLE_USER", getSelectedValue(findElementBy("select", "data-valuekey", "role")));
    assertEquals("ACTIVE", getSelectedValue(findElementBy("select", "data-valuekey", "status")));
    WebElement el = findElementBy(By.name("_eventId_next"));
    assertEquals("Add User", el.getText());

    // when
    el.click();

    // then
    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("form-modal")));

    assertEquals(2, getTableRowCount("results"));
    List<WebElement> cells = findElements(By.tagName("td"));
    WebElement e = cells.stream().filter(s -> s.getText().contains(email)).findFirst().get();
    int index = cells.indexOf(e);
    assertEquals("test2@formkiq.com", e.getText());
    assertEquals("ROLE_USER", cells.get(index + 1).getText());
    assertEquals("INVITE", cells.get(index + 2).getText());

    // when
    click(By.id("edit_" + getDefaultEmail()));

    // then
    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("form-modal")));

    el = findElementBy(By.name("_eventId_next"));
    assertEquals("Update User", el.getText());

    assertEquals(getDefaultEmail(), findElementBy("input", "data-valuekey", "email").getAttribute("value"));
    assertFalse(getDriver().findElement(getBy("input", "data-valuekey", "password")).isDisplayed());
    assertFalse(getDriver().findElement(getBy("input", "data-valuekey", "confirmpassword")).isDisplayed());

    assertEquals("ROLE_ADMIN", getSelectedValue(findElementBy("select", "data-valuekey", "role")));
    assertEquals("ACTIVE", getSelectedValue(findElementBy("select", "data-valuekey", "status")));

    LoggerMailSender l = (LoggerMailSender) this.mail.getMailSender();
    assertEquals(0, l.getMessages().size());
    assertEquals(1, l.getMimeMessages().size());

    MimeMessage m = l.getMimeMessages().get(0);
    Multipart mp = (Multipart) m.getContent();
    assertEquals(2, mp.getCount());

    MimeBodyPart part = (MimeBodyPart) mp.getBodyPart(0);
    assertNull(m.getFrom());
    assertEquals(email, String.join(",", Arrays.asList(m.getRecipients(Message.RecipientType.TO)).stream()
            .map(s -> s.toString()).collect(Collectors.toList())));

    assertEquals("Welcome to FormKiQ", m.getSubject());
    assertTrue(part.getContent().toString()
            .contains(getDefaultHostAndPort() + "/register?email=" + email + "&resettoken="));

    // given
    logout();
    String url = extractUrl(part.getContent().toString());

    // when
    getDriver().navigate().to(url);

    // then
    assertEquals("FormKiQ Server - User Registration", getTitle());

    // given
    // when
    findElementBy(By.name("password")).sendKeys(getDefaultPass());
    findElementBy(By.name("confirmpassword")).sendKeys(getDefaultEmail());
    click(By.name("_eventId_next"));

    // then
    waitUntilPageSourceText("Passwords do not match");

    // given
    // when
    findElementBy(By.name("password")).clear();
    findElementBy(By.name("confirmpassword")).clear();

    findElementBy(By.name("password")).sendKeys(getDefaultPass());
    findElementBy(By.name("confirmpassword")).sendKeys(getDefaultPass());

    click(By.name("_eventId_next"));

    // then
    waitUntilPageSourceText("Registration is complete");

    // when
    login(email);

    // then
    assertEquals("FormKiQ Server - Dashboard", getTitle());
}

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

License:Apache License

/**
 * Click Submit Button by name.//www .  java 2s . c om
 * @param name {@link String}
 * @param text {@link String}
 * @param timeout long
 */
private void submitByName(final String name, final String text, final long timeout) {

    List<WebElement> elements = getSubmitButtons();
    for (WebElement element : elements) {
        if (name.equals(element.getAttribute("name"))) {
            assertEquals(text, element.getText());
            element.click();
            break;
        }
    }
}

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

License:Apache License

/**
 * testAddWorkflow04()./*from www. jav a2s. c  o  m*/
 * add static text and then edit..
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow04() throws Exception {
    // given
    FormJSONFieldType type = FormJSONFieldType.STATIC_TEXT;
    ImmutableMap<String, String> values = ImmutableMap.of("70", STATIC_TEXT_DEFAULT);

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

    menuDragAndDrop("menu-statictext");

    // then
    WebElement e = findElementBy("div", "data-fieldid", "1");
    assertEquals(STATIC_TEXT_DEFAULT, e.getText());
    assertTrue(getPageSource().contains(STATIC_TEXT_DEFAULT));

    checkEditField("1", type, values);
}

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

License:Apache License

/**
 * testAddWorkflow11()./*from ww  w .  j  a  v  a 2 s  .  co m*/
 * add Signature and then edit..
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow11() throws Exception {
    // given
    FormJSONFieldType typeSelect = FormJSONFieldType.SIGNATURE;
    ImmutableMap<String, String> values = ImmutableMap.of("20", "new field", "40", "Immediate[immediate]");

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

    menuDragAndDrop("menu-signature");

    // then
    WebElement element = findElementBy(By.className("signature-pad"));
    assertTrue(element.isDisplayed());
    assertEquals("", element.getText());

    checkEditField("1", typeSelect, values);
}

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

License:Apache License

/**
 * testAddWorkflow13().//from   w  ww. ja v a 2  s .  c om
 * add textbox and then edit..
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow13() throws Exception {
    // given
    FormJSONFieldType typeSelect = FormJSONFieldType.TEXTBOX;
    ImmutableMap<String, String> values = ImmutableMap.of("20", "new label", "40", "Immediate[immediate]", "44",
            "Numbers[DecimalPad]", "61", "tvariable", "25", "Currency");

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

    menuDragAndDrop("menu-textbox");
    editField("1", values);

    // then
    WebElement element = findElementBy("input", "data-fieldid", "1");
    assertTrue(element.isDisplayed());
    assertEquals("", element.getText());

    checkEditField("1", typeSelect, values);
}

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

License:Apache License

/**
 * testAddWorkflow15()./*ww w.  j  a v  a  2s  . c  o  m*/
 * add formula and then edit.
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow15() throws Exception {
    // given
    FormJSONFieldType typeSelect = FormJSONFieldType.FORMULA;
    ImmutableMap<String, String> values = ImmutableMap.of("20", "Sample Label", "61", "tvariable", "78",
            "12*13");

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

    menuDragAndDrop("menu-formula");
    editField("1", values);

    // then
    WebElement element = findElementBy("input", "data-fieldid", "1");
    assertTrue(element.isDisplayed());
    assertEquals("", element.getText());

    checkEditField("1", typeSelect, values);
}

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

License:Apache License

/**
 * testAddWorkflow18()./*  w  ww .j a  v a 2  s .c om*/
 * add 2 textbox and change order
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow18() throws Exception {
    // given
    ImmutableMap<String, String> values0 = ImmutableMap.of("20", "Sample Label", "40", "Immediate[immediate]",
            "44", "Numbers[DecimalPad]", "61", "tvariable", "25", "Currency");

    ImmutableMap<String, String> values1 = ImmutableMap.of("20", "Sample Label2", "40", "Immediate[immediate]",
            "44", "Numbers[DecimalPad]", "61", "tvariable", "25", "Currency");

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

    menuDragAndDrop("menu-textbox");
    editField("1", values0);

    addField(FormJSONFieldType.TEXTBOX);
    editField("2", values1);

    // then
    WebElement element = findElementBy("label", "data-fieldid", "1");
    assertTrue(element.isDisplayed());
    assertEquals("Sample Label", element.getText());

    element = findElementBy("label", "data-fieldid", "2");
    assertTrue(element.isDisplayed());
    assertEquals("Sample Label2", element.getText());

    // when - swap field positions
    moveField("1", "2");

    // then
    assertRowEquals(findElementsWithText(By.xpath("//label[@data-fieldid]")),
            Arrays.asList("Sample Label", "Sample Label2"));
}

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

License:Apache License

/**
 * testAddWorkflow25().//ww w  . ja  v a 2 s  .  co  m
 * add static text, then add field
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow25() throws Exception {
    // given
    ImmutableMap<String, String> values = ImmutableMap.of("70", "this is sample text");

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

    menuDragAndDrop("menu-statictext");
    editField("1", values);

    // then
    WebElement e = findElementBy("div", "data-uuid", "1");
    assertEquals("this is sample text", e.getText());

    // when - add field
    addField(FormJSONFieldType.TEXTBOX);

    // then
    e = findElementBy("label", "data-fieldid", "2");
    assertEquals("new field", e.getText());
}

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

License:Apache License

/**
 * testAddWorkflow27().//from w  w w.ja  va2 s .c om
 * edit DOCX Workflow Output
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow27() throws Exception {
    // given
    String docname = "sample1.docx";
    byte[] dat = Resources.getResourceAsBytes("/" + docname);

    // when - add step
    clickAddNewWorkflow();
    findElementBy(By.id("button_add_step")).click();

    JavascriptExecutor executor = (JavascriptExecutor) getDriver();
    executor.executeScript("var myZone, blob, base64Image;\n" + "base64Image = '" + Strings.encode(dat) + "'\n"
            + "myZone = Dropzone.forElement(document.body);\n"
            + "function base64toBlob(r,e,n){e=e||\"\",n=n||512;for"
            + "(var t=atob(r),a=[],o=0;o<t.length;o+=n){for" + "(var l=t.slice(o,o+n),h=new Array(l.length),"
            + "b=0;b<l.length;b++)h[b]=l.charCodeAt(b);" + "var v=new Uint8Array(h);a.push(v)}"
            + "var c=new Blob(a,{type:e});return c}" + "blob = base64toBlob(base64Image, 'application/pdf');"
            + "blob.name = '" + docname + "';" + "myZone.addFile(blob);");

    // then
    assertEquals("sample1", findElementBy(By.id("tab_s1e2")).getText().trim());

    // when
    findElementBy(By.id("tab_s1e1")).click();
    findElementBy(By.id("output_0")).click();

    // then
    assertTrue(getPageSource().contains("sample"));
    WebElement select = findElementBy(By.name("outputDocumentType"));
    assertEquals("DOCX,PDF", select.getText().trim().replaceAll("[\\s]+", ","));
    assertEquals("DOCX", new Select(select).getFirstSelectedOption().getText());

    // given
    final int index = 5;

    // when
    new Select(select).selectByValue("PDF");
    new Select(findElementBy(By.name("field_1"))).selectByIndex(index);
    findElementBy(By.id("button_save")).click();

    // then
    assertEquals("FormKiQ Server - Dashboard", getTitle());

    // given
    String ttoken = login();
    UserDTO user = getUserDTO(ttoken, null);
    String folder = user.getFolders().get(0).getUUID().toString();

    // when
    FolderFormsListDTO dto = getFolderFileList(ttoken, folder, null);

    // then
    assertFalse(dto.getForms().isEmpty());

    // given
    FormDTO fdto = Collections.max(dto.getForms(), Comparator.comparing(s -> s.getInserteddate()));

    String uuid = fdto.getUUID();

    // when
    byte[] data = getFolderFile(ttoken, folder, uuid, MediaType.valueOf(ACCEPT_HEADER_V1 + "+zip"), false)
            .getBody();
    ArchiveDTO archive = this.archiveService.extractJSONFromZipFile(data);

    // then
    WorkflowOutputDocx o = (WorkflowOutputDocx) archive.getWorkflow().getOutputs().get(0);
    List<WorkflowOutputFormField> pfields = o.getFields();
    String formname = "sample1[" + archive.getForms().values().iterator().next().getUUID() + "]";

    int i = 0;
    assertWorkflowOutputFormField(pfields.get(i++), formname, "DAY[1]", "DAY");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Trade Name[5]", "Month");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Year[3]", "Year");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "LegalName[4]", "LegalName");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Trade Name[5]", "Trade Name");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "ADDRESS[6]", "ADDRESS");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "SUITE[7]", "SUITE");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "CITY[8]", "CITY");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "PROVINCE[9]", "PROVINCE");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "POSTALCODE[10]", "POSTALCODE");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "FAX NUMBER[11]", "FAX NUMBER");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "CONTACT NAME[12]", "CONTACT NAME");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "CONTACT TITLE[13]", "CONTACT TITLE");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "EMAIL[14]", "EMAIL");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Lease Date[15]", "Lease Date");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Driver's License[16]", "Driver's License");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Passport[17]", "Passport");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "Checkbox[18]", "Checkbox");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "SIG[19]", "SIG");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "PRINT NAME[20]", "PRINT NAME");
    assertWorkflowOutputFormField(pfields.get(i++), formname, "TITLE[21]", "TITLE");
}

From source file:com.fpt.datht.iap.AutoIAP.java

public static void getDataFromServer(String className) {
    int c = 0;/* w  ww  .  jav  a 2 s  . c om*/
    slots = new String[10];
    students = new LinkedList<>();
    new WebDriverWait(driver, 360).until(ExpectedConditions.titleIs("IAP"));
    driver.get("http://iap.fpt.edu.vn/activity");

    new WebDriverWait(driver, 360).until(ExpectedConditions.urlToBe("http://iap.fpt.edu.vn/activity/"));

    List<WebElement> els = driver.findElements(By.tagName("a"));
    System.out.println("Size a:" + els.size());
    for (WebElement e : els) {
        //  System.out.println(e.getText());
        if (e.getText().contains(className)) {

            slots[c] = e.getAttribute("href").replaceAll("http://iap.fpt.edu.vn/activity/index.php",
                    "http://iap.fpt.edu.vn/attendance/add.php");
            c++;
            count = c;
            // System.out.println(main);

        }
    }
    if (slots.length == 0)
        return;
    driver.get(slots[0]);

    try {
        new WebDriverWait(driver, 5)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));

    } catch (TimeoutException ex) {
        driver.get(slots[0].replaceAll("add.php", "edit.php"));

    }
    //Auto Check Slot 1
    if (autoCheckSlot1) {
        List<WebElement> elsInput = driver.findElements(By.xpath(".//input[@type='radio' and @value='1' ]"));
        autoCheckAll(elsInput);
    }

    //Wating for submit
    new WebDriverWait(driver, 5000)
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//font[@color='green']")));
    driver.get(slots[0].replaceAll("add.php", "edit.php"));
    //GET All checked
    List<WebElement> elsInputChecked = driver
            .findElements(By.xpath(".//input[@type='radio' and @value='1' and @checked]"));

    System.out.println("Size input checked:" + elsInputChecked.size());

    elsInputChecked.stream().map((e) -> {
        Student student = new Student();
        student.name = e.getAttribute("name");
        return student;
    }).forEach(students::add);

}