Example usage for org.openqa.selenium By name

List of usage examples for org.openqa.selenium By name

Introduction

In this page you can find the example usage for org.openqa.selenium By name.

Prototype

public static By name(String name) 

Source Link

Usage

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

License:Apache License

/**
 * testWorkflow03()./*from   w w w  .ja  v  a 2  s .  c  o  m*/
 * Fill Form, Press Next then change URL to previous form
 * @throws Exception Exception
 */
@Test
public void testCreateWorkflow03() throws Exception {
    // given
    FormJSON form0 = TestDataBuilder.createStoreReceipt();
    FormJSON form1 = TestDataBuilder.createSimpleForm();
    Workflow workflow = TestDataBuilder.createWorkflow(form0, form1);

    String token = login();
    String folder = createFolder(token, getDefaultEmail());

    addFileToFolder(token, folder, workflow, form0, form1);

    // when
    login(getDefaultEmail());
    getDriver().navigate().to(getDefaultHostAndPort() + "/user/dashboard");
    waitForJSandJQueryToLoad();

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

    findElementBy(By.className("add_0")).click();

    // then (verify on correct page)
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Store Receipt", getTitle());

    // when (enter data)
    WebElement element = findElementBy(By.name("1"));
    element.sendKeys("10");
    findElementBy(By.id("nextbutton")).click();

    // then verify summary
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e2", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Simple Form", getTitle());

    // when move to previous page
    findElementBy(By.id("previousbutton")).click();

    // then verify summary
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Store Receipt", getTitle());
}

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

License:Apache License

/**
 * testCreateWorkflow11()./*  w w  w  .j a  v a 2s  . c  o m*/
 * fillout and generate and sign fillable PDF
 * @throws Exception Exception
 */
@Test
public void testCreateWorkflow11() throws Exception {
    // given
    String pdfname = "sample-form2.pdf";
    byte[] data = Resources.getResourceAsBytes("/" + pdfname);
    ArchiveDTO archive = buildArchiveDTO(pdfname);
    this.pdfEditorService.generate(archive, pdfname, data);

    String token = login();
    String folder = createFolder(token, getDefaultEmail());
    addFileToFolder(token, folder, archive);

    // when
    login(getDefaultEmail());
    getDriver().navigate().to(getDefaultHostAndPort() + "/user/dashboard");
    waitForJSandJQueryToLoad();

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

    findElementBy(By.className("add_0")).click();

    // then (verify on correct page)
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals(SAMPLE_FORM_2_HTML_TITLE, getTitle());

    fillSampleForm2();

    // when (submit)
    submitByName("_eventId_next", "Next");

    // then verify summary
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e2", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Signature", getTitle());
    assertEquals(1, findElements(getBy("button", "data-fieldid", "55")).size());
    assertEquals(0, getDriver().findElements(getBy("img", "data-fieldid", "55")).size());

    // when (go back
    submitByName("_eventId_prev", "Previous");

    // then
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals(SAMPLE_FORM_2_HTML_TITLE, getTitle());

    // when
    findElementBy(By.name("1")).sendKeys("Smith123");
    submitByName("_eventId_next", "Next");

    // then
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e2", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Signature", getTitle());

    // when (signature)
    click(By.className("button-sig"));

    JavascriptExecutor jsExecutor = (JavascriptExecutor) getDriver();
    jsExecutor.executeScript("signaturemetadata('555','999');");

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

    // when
    click(By.className("form-modal-close-button"));

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

    // when (signature)
    click(By.className("button-sig"));

    // then
    fillSignature("55");

    // when
    click(By.className("form-modal-update-button"));

    // then
    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("form-modal")));
    assertEquals(0, getDriver().findElements(getBy("button", "data-fieldid", "55")).size());
    assertEquals(1, findElements(getBy("img", "data-fieldid", "55")).size());

    // when
    submitByName("_eventId_next", " Submit", TIMEOUT * 2);

    // then complete page
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e3", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - sample-form2.pdf Complete", getTitle());

    Workflow workflow = archive.getWorkflow();

    Pair<Workflow, Map<String, byte[]>> pwf = verifyFolderFileList(token, folder, workflow, "ACTIVE",
            "sample-form2.pdf");
    workflow = pwf.getLeft();
    Map<String, byte[]> map = pwf.getRight();

    assertEquals(getDefaultHostAndPort() + "/api/folders/files/" + folder + "/" + workflow.getUUID() + ".pdf",
            findElementBy(By.id("pdflink")).getAttribute("href"));

    assertEquals(SAMPLE_FORM2 + ".pdf",
            map.keySet().stream().filter(s -> s.endsWith(".pdf")).collect(Collectors.joining(", ")));

    assertEquals(1, map.keySet().stream().filter(s -> s.endsWith(".pdf")).count());

    assertEquals(1, map.keySet().stream().filter(s -> s.endsWith(".signature")).count());

    FormJSON f1 = this.jsonService.readValue(map.get(workflow.getSteps().get(1) + ".form"), FormJSON.class);

    assertTrue(f1.getAssetData().containsKey(f1.getSections().get(0).getFields().get(0).getValue()));
    assertEquals("555", findValueByKey(f1, "latitude").get().getValue());
    assertEquals("999", findValueByKey(f1, "longitude").get().getValue());
    assertEquals("0:0:0:0:0:0:0:1", findValueByKey(f1, "ipaddress").get().getValue());
    assertEquals("", findValueByKey(f1, "xforwardedfor").get().getValue());

    assertNotNull(this.jsonService.stringToDate(findValueByKey(f1, "inserteddate").get().getValue()));

    byte[] pdf = map.get(SAMPLE_FORM2 + ".pdf");

    PDDocument document = PDDocument.load(pdf);
    try {
        PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
        assertEquals("SmithSmith123", acroForm.getField("lastName").getValueAsString());
        assertEquals("John", acroForm.getField("firstName").getValueAsString());
        assertEquals(1, document.getSignatureDictionaries().size());
    } finally {
        document.close();
    }

    // TODO verify audit
}

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

License:Apache License

/**
 * testCreateWorkflow11.//  w  ww  .  ja va  2s  .com
 * @param j int
 * @return int
 */
private int fillAuthorizationAndSignatures(final int j) {
    int i = j;
    i++;
    findElementBy(By.name("" + i++)).sendKeys("2018");
    findElementBy(By.name("" + i++)).sendKeys("01");
    findElementBy(By.name("" + i++)).sendKeys("30");
    return i;
}

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

License:Apache License

/**
 * testCreateWorkflow11./*from   www .j a  v  a  2  s  .  c o  m*/
 * @param j int
 * @return int
 */
private int fillClaimInformation(final int j) {
    int i = j;
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Yes'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'No'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Yes'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'No'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Yes'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'No'")).click();
    findElementBy(By.name("" + i++)).sendKeys("2018");
    findElementBy(By.name("" + i++)).sendKeys("12");
    findElementBy(By.name("" + i++)).sendKeys("28");
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Yes'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'No'")).click();
    findElementBy(By.name("" + i++)).sendKeys("1015"); // submitted
    return i;
}

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

License:Apache License

/**
 * testCreateWorkflow11./*from  w  ww . j  av a2 s. c  o m*/
 * @param j int
 * @return int
 */
private int fillSpouseDependentExpenses(final int j) {
    int i = j;
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Spouse'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Son'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Daughter'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'Other'")).click();
    findElementBy(By.name("" + i++)).sendKeys("Jack");
    findElementBy(By.name("" + i++)).sendKeys("Smith");
    findElementBy(By.name("" + i++)).sendKeys("2010"); // birthdate 1
    findElementBy(By.name("" + i++)).sendKeys("03"); // birthdate 2
    findElementBy(By.name("" + i++)).sendKeys("22"); // birthdate 3
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Spouse'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Son'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Daughter'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'Other'")).click();
    findElementBy(By.name("" + i++)).sendKeys("Jane"); // Spouse first
    findElementBy(By.name("" + i++)).sendKeys("Smith"); // Spouse last
    findElementBy(By.name("" + i++)).sendKeys("1969"); // birthdate 1
    findElementBy(By.name("" + i++)).sendKeys("05"); // birthdate 2
    findElementBy(By.name("" + i++)).sendKeys("27"); // birthdate 3
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Spouse'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Son'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Daughter'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'Other'")).click();
    findElementBy(By.name("" + i++)).sendKeys("Suze"); // Spouse first
    findElementBy(By.name("" + i++)).sendKeys("Smith"); // Spouse last
    findElementBy(By.name("" + i++)).sendKeys("2012"); // birthdate 1
    findElementBy(By.name("" + i++)).sendKeys("06"); // birthdate 2
    findElementBy(By.name("" + i++)).sendKeys("28"); // birthdate 3
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Spouse'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Son'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Daughter'")).click();
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'Other'")).click();
    findElementBy(By.name("" + i++)).sendKeys("Frank"); // Spouse first
    findElementBy(By.name("" + i++)).sendKeys("Smith"); // Spouse last
    findElementBy(By.name("" + i++)).sendKeys("2014"); // birthdate 1
    findElementBy(By.name("" + i++)).sendKeys("07"); // birthdate 2
    findElementBy(By.name("" + i++)).sendKeys("30"); // birthdate 3
    return i;
}

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

License:Apache License

/**
 * testCreateWorkflow11.//from  w  w w .  j av  a  2s.c  o m
 * @param j int
 * @return int
 */
private int fillCorrdinationOfBenefits(final int j) {
    int i = j;
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'No'")).click(); // Spouse Another plan
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'Yes'")).click(); // Spouse Another plan
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'No'")).click(); // Spouse Another plan
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'Yes'")).click(); // Spouse Another plan
    findElementBy(By.name("" + i++)).sendKeys("Smith"); // Spouse diff plan
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Male'")).click(); // Gender
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'female'")).click(); // Gender
    findElementBy(By.name("" + i++)).sendKeys("5551234"); // Spouse Contract
    findElementBy(By.name("" + i++)).sendKeys("55554321"); // Spouse Cert No
    return i;
}

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

License:Apache License

/**
 * testCreateWorkflow11.//from  w w  w.ja v  a2s . co  m
 * @param j int
 * @return int
 */
private int fillMemberInformation(final int j) {
    int i = j;
    findElementBy(By.name("" + i++)).sendKeys("Smith"); // last name
    findElementBy(By.name("" + i++)).sendKeys("John"); // first name
    findElementBy(By.name("" + i++)).sendKeys("John"); // certificate
    findElementBy(By.name("" + i++)).sendKeys("555"); // phone number 1
    findElementBy(By.name("" + i++)).sendKeys("555"); // phone number 2
    findElementBy(By.name("" + i++)).sendKeys("1212"); // phone number 3
    findElementBy(By.name("" + i++)).sendKeys("2000"); // birthdate 1
    findElementBy(By.name("" + i++)).sendKeys("01"); // birthdate 2
    findElementBy(By.name("" + i++)).sendKeys("19"); // birthdate 3

    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Eng'")).click(); // Language Required
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'Fr'")).click(); // Language Required
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i + "!'Male'")).click(); // Gender
    findElementBy(By.id("'Public Service Health Care Plan (PSHCP) Claim Form'!" + i++ + "!'Female'")).click(); // Gender
    findElementBy(By.name("" + i++)).sendKeys("123 Main"); // Street
    findElementBy(By.name("" + i++)).sendKeys("708"); // Apartment
    findElementBy(By.name("" + i++)).sendKeys("New York"); // City
    findElementBy(By.name("" + i++)).sendKeys("NY"); // Province
    findElementBy(By.name("" + i++)).sendKeys("90210"); // Postal Code
    return i;
}

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

License:Apache License

/**
 * Add New Step./*from   w  ww  .  ja v a  2s  .  c  o  m*/
 * @param event int
 * @param title {@link String}
 */
private void addNewStep(final int event, final String title) {

    addBlankForm();

    click(By.id("tab_s1e" + event));

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    findElementBy(getBy("input", "data-fieldid", "20")).sendKeys(title);
    //click(By.className("form-modal-update-button"));
    click(By.name("_eventId_next"));

    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("fieldeditorform")));

    assertTrue(findElementBy(By.id("tab_s1e" + event)).getText().endsWith(title));
}

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

License:Apache License

/**
 * Edits Field.//w w w.j  a va2 s .c  o m
 *
 * @param fieldid {@link String}
 * @param values {@link Map}
 * @throws InterruptedException InterruptedException
 */
private void editField(final String fieldid, final Map<String, String> values) throws InterruptedException {

    clickEditFieldButton(fieldid);

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    for (Map.Entry<String, String> e : values.entrySet()) {
        String field = e.getKey();
        String value = e.getValue();

        By by = By.xpath("//*[self::textarea|self::input|self::select|self::button]" + "[@data-fieldid='"
                + field + "']");

        WebElement element = findElementBy(by);

        assertTrue(element.isDisplayed());
        String tagname = element.getTagName();

        switch (tagname) {
        case "select":
            Select select = new Select(element);
            waitUntilSelectOptionsPopulated(select);
            select.selectByVisibleText(extractLabelAndValue(value).getLeft());
            break;

        case "button":
            element.click();
            break;
        default:
            element.clear();
            element.sendKeys(value);
            break;
        }
    }

    //findElementBy(By.className("form-modal-update-button")).click();
    click(By.name("_eventId_next"));

    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("fieldeditorform")));
}

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

License:Apache License

/**
 * testAddWorkflow12()./*ww w  . jav  a  2 s . com*/
 * verify has-error class
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow12() throws Exception {
    // given

    // when - add step
    clickAddNewWorkflow();
    addBlankForm();
    menuDragAndDrop("menu-textbox");

    clickEditFieldButton("1");

    // then
    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    // when
    findElementBy(By.id("'FormJSONField'!20")).clear();
    //findElementBy(By.className("form-modal-update-button")).click();
    click(By.name("_eventId_next"));

    // then
    waitUntilClassName(getBy("div", "data-uuid", "20"), "form-group col-xs-12 has-error");
}