Example usage for org.openqa.selenium By className

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

Introduction

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

Prototype

public static By className(String className) 

Source Link

Document

Find elements based on the value of the "class" attribute.

Usage

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

License:Apache License

/**
 * testDashboard01()./* ww  w.ja  v  a2s  . c o  m*/
 * Designer button is displayed
 *
 * @throws Exception Exception
 */
@Test
public void testDashboard01() throws Exception {
    // given
    String token = login();
    FormJSON form = TestDataBuilder.createSimpleForm();
    Workflow workflow = TestDataBuilder.createWorkflow(form);

    String folder = createFolder(token, "test");
    addFileToFolder(token, folder, workflow, form);

    // when
    login(getDefaultEmail());

    // then
    assertEquals("FormKiQ Server - Dashboard", getTitle());
    assertEquals(1, findElements(By.className("button-design")).size());

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

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

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

License:Apache License

/**
 * testDashboard02().//from w ww . ja v a 2 s.c  o m
 * Non Admin User with Design permission
 *
 * @throws Exception Exception
 */
@Test
public void testDashboard02() throws Exception {
    // given
    String email = "test2@formkiq.com";
    String token = login();
    FormJSON form = TestDataBuilder.createSimpleForm();
    Workflow workflow = TestDataBuilder.createWorkflow(form);

    createUser(token, email, getDefaultPass());
    String folder = createFolder(token, "test");
    addFileToFolder(token, folder, workflow, form);
    inviteToFolder(token, email, folder, Arrays.asList(FolderPermission.PERM_FORM_DESIGN));

    // when
    login(email);

    // then
    assertEquals("FormKiQ Server - Dashboard", getTitle());
    assertEquals(1, findElements(By.className("button-add-workflow")).size());

    // when
    click(By.className("button-add-workflow"));

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

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

License:Apache License

/**
 * testDashboard02().//ww w  . ja va  2  s  . co m
 * Non Admin User without Design permission
 *
 * @throws Exception Exception
 */
@Test
public void testDashboard03() throws Exception {
    // given
    String email = "test3@formkiq.com";
    String token = login();
    FormJSON form = TestDataBuilder.createSimpleForm();
    Workflow workflow = TestDataBuilder.createWorkflow(form);

    createUser(token, email, getDefaultPass());
    String folder = createFolder(token, "test");
    addFileToFolder(token, folder, workflow, form);
    inviteToFolder(token, email, folder, Arrays.asList(FolderPermission.PERM_FORM_ENTRY));

    // when
    login(email);

    // then
    assertEquals("FormKiQ Server - Dashboard", getTitle());
    assertEquals(0, getDriver().findElements(By.className("button-design")).size());
}

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

License:Apache License

/**
 * invalid license.//from  ww w .  j  a  va 2  s  . c  om
 */
@Test
public void testLicense01() {
    // given
    String license = "adsaadad";

    // when
    findElementBy("textarea", "data-valuekey", "license").sendKeys(license);
    click(By.name("_eventId_next"));

    // then
    assertEquals("Unregistered Server", findElementBy(By.className("form-section-label")).getText());
    assertTrue(getPageSource().contains("Invalid License Key"));
}

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

License:Apache License

/**
 * valid license./*ww w .  j  a v a  2  s .c  o  m*/
 * @throws Exception Exception
 */
@Test
public void testLicense02() throws Exception {
    // given
    String license = Resources.getResourceAsString("/TestCompany.lic");

    // when
    findElementBy("textarea", "data-valuekey", "license").sendKeys(license);
    click(By.name("_eventId_next"));

    // then
    assertEquals("Registered Server", findElementBy(By.className("form-section-label")).getText());
    assertEquals(license, findElementBy(getBy("textarea", "data-valuekey", "license")).getText());

    String info = findElementBy(getBy("div", "data-valuekey", "info")).getText();
    assertTrue(info.contains("Company: Test Company"));
    assertTrue(info.contains("Issue Date: Sun Jun 25 21:27:33 CDT 2017"));
    assertTrue(info.contains("Expiry Date: Sun Jun 25 21:27:33 CDT 2017"));
    assertTrue(info.contains("Issued By: FormKiQ Inc."));

    String token = login("testapp", "testapp", getDefaultEmail(), getDefaultPass());

    String url = getDefaultHostAndPort() + API_CLIENT_LIST + "?access_token=" + token;

    final int clientCount = 3;
    ResponseEntity<String> entity = exchangeRest(HttpMethod.GET, url);
    assertEquals(SC_OK, entity.getStatusCode().value());
    ClientListDTO dto = this.jsonService.readValue(entity.getBody(), ClientListDTO.class);

    List<ClientDTO> clients = dto.getClients();
    Collections.sort(clients, new Comparator<ClientDTO>() {

        @Override
        public int compare(final ClientDTO o1, final ClientDTO o2) {
            return o1.getClientname().compareTo(o2.getClientname());
        }
    });

    assertEquals(clientCount, dto.getClients().size());
    assertEquals("testapp", dto.getClients().get(0).getClient());
    assertEquals("Test App", dto.getClients().get(0).getClientname());
    assertEquals("password", dto.getClients().get(0).getGranttypesasstring());

    assertEquals("TestCompany", dto.getClients().get(1).getClient());
    assertEquals("Test Company", dto.getClients().get(1).getClientname());
    assertEquals("password", dto.getClients().get(1).getGranttypesasstring());

    assertEquals(getClientId(), dto.getClients().get(2).getClient());
    assertEquals(getClientId(), dto.getClients().get(2).getClientname());
    assertEquals("authorization_code,password,refresh_token", dto.getClients().get(2).getGranttypesasstring());
}

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

License:Apache License

/**
 * testWorkflow01()./*  w  w w . j a v  a 2 s  .c o m*/
 * get workflow as ADMIN
 * @throws Exception Exception
 */
@Test
public void testCreateWorkflow01() throws Exception {
    // given
    final long sleep = 250L;
    FormJSON form = TestDataBuilder.createStoreReceipt();
    Workflow workflow = TestDataBuilder.createWorkflow(form);

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

    addFileToFolder(token, folder, workflow, form);

    // 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");

    element = findElementBy(By.name("1"));
    assertEquals("10", element.getAttribute("value"));

    JavascriptExecutor jsExecutor = (JavascriptExecutor) getDriver();
    jsExecutor.executeScript("calculate();", element);

    Thread.sleep(sleep);

    getDriver().navigate().refresh();

    // then (verify data calculations)
    element = findElementBy(By.name("2"));
    assertEquals("$0.70", element.getAttribute("value"));

    element = findElementBy(By.name("3"));
    assertEquals("$7.99", element.getAttribute("value"));

    element = findElementBy(By.name("4"));
    assertEquals("$18.69", element.getAttribute("value"));

    List<WebElement> elements = getSubmitButtons();
    assertEquals(1, elements.size());

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

    // then verify complete
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e2", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Sample WF Complete", getTitle());

    assertTrue(getDriver().getPageSource().contains("end-of-document"));

    String pageSource = getDriver().getPageSource();
    assertTrue(pageSource.contains("The workflow has been saved."));

    FolderFormsListDTO formlist = getFolderFileList(token, folder, workflow.getUUID());

    assertEquals(1, formlist.getForms().size());
    FormDTO fdto = formlist.getForms().get(0);
    assertNotEquals(workflow.getUUID(), fdto.getUUID());

    byte[] data = getFolderFile(token, folder, fdto.getUUID(), MediaType.valueOf(ACCEPT_HEADER_V1 + "+zip"),
            false).getBody();
    ArchiveDTO archive = this.archiveService.extractJSONFromZipFile(data);
    workflow = archive.getWorkflow();

    assertNotNull(workflow);
    assertEquals(1, archive.getForms().size());
    form = archive.getForms().values().iterator().next();

    assertTrue(workflow.getSteps().contains(form.getUUID()));
    assertEquals(workflow.getParentUUID(), form.getParentUUID());

    int i = 1;
    assertEquals("$10.00", findField(form, i++).get().getValue());
    assertEquals("$0.70", findField(form, i++).get().getValue());
    assertEquals("$7.99", findField(form, i++).get().getValue());
    assertEquals("$18.69", findField(form, i++).get().getValue());
}

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

License:Apache License

/**
 * testWorkflow03().//  w  ww  .j a va2s . 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

/**
 * TODO route testCreateWorkflow11 to email to signature.
 * testCreateWorkflow08().//from   ww  w  .j  av  a  2 s.  c o  m
 * test Docsign workflow
 * @throws Exception Exception
 */
@Test
@Ignore
public void testCreateWorkflow08() throws Exception {
    //given
    FormJSON f0 = TestDataBuilder.createScheduleB();
    FormJSON f1 = TestDataBuilder.createDocSign();
    Workflow workflow = TestDataBuilder.createWorkflow(f0, f1);
    workflow.setPrintsteps(Arrays.asList(f0.getUUID()));

    String token = login();
    String folder = createFolder(token, getDefaultEmail());
    UserDTO user = getUserDTO(token, null);
    String userid = user.getUUID().toString();

    addFileToFolder(token, folder, workflow, f0, f1);

    // when
    clickCreateWorkflow();

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

    assertEquals(f0.getSections().get(1).getFields().size(),
            getDriver().findElements(By.className("col-xs-12")).size());
    assertEquals(2, getDriver().findElements(By.className("col-xs-6")).size());

    // when
    fillScheduleB();

    submitByName("_eventId_next", "Next");

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

    // when
    fillDocsign();

    submitByName("_eventId_next", "Next");

    // then
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e3", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Sample WF Complete", getTitle());

    // when (goto summary -> complete)
    submitByName("_eventId_next", " Submit for Signature");

    // then
    String pageSource = getDriver().getPageSource();
    assertTrue(pageSource.contains("The workflow has been saved."));
    assertNotNull(findElementBy(By.id("pdfbutton")));

    // verify email is sent for signing
    verifyFolderFileList(token, folder, workflow, "ROUTED", "Sample WF");
    Pair<QueueDTO, DocSignQueueMessage> pair = verifyQueueMessage(token, userid, folder);

    String signUrl = verifyDocsignEmail();
    assertEquals(
            "https://www.formkiq.com/flow/sign/" + pair.getRight().getFormid() + "/" + pair.getLeft().getUUID(),
            signUrl);

    logout();

    // given
    signUrl = signUrl.replaceAll("https://www.formkiq.com", getDefaultHostAndPort());

    // when (sign document)
    getDriver().navigate().to(signUrl);

    // then
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Sample WF Summary", getTitle());
    assertEquals(2, getDriver().findElements(By.className("col-xs-6")).size());

    // when (submit missing signtures)
    submitByName("_eventId_next", " Sign Document");

    // then
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Sample WF Summary", getTitle());
    assertEquals(2, getDriver().findElements(By.className("has-error")).stream().filter(s -> s.isDisplayed())
            .collect(Collectors.toList()).size());

    // when (add signature to document)
    fillSignature("7");
    fillSignature("8");

    JavascriptExecutor js = (JavascriptExecutor) getDriver();
    js.executeScript("document.getElementById('latitude').value = '111'");
    js.executeScript("document.getElementById('longitude').value = '222'");

    submitByName("_eventId_next", " Sign Document");

    // then
    final int stepCount = 3;
    Pair<Workflow, Map<String, byte[]>> pwf = verifyFolderFileList(token, folder, workflow, "ACTIVE",
            "Sample WF");

    Workflow cworkflow = pwf.getLeft();
    Map<String, byte[]> map = pwf.getRight();
    verifyDocsignResult(map);

    assertNotEquals(workflow.getUUID(), cworkflow.getUUID());

    int i = 0;
    assertEquals(stepCount, cworkflow.getSteps().size());
    assertTrue(map.containsKey(cworkflow.getSteps().get(i++) + ".form"));
    assertTrue(map.containsKey(cworkflow.getSteps().get(i++) + ".form"));
    assertTrue(map.containsKey(cworkflow.getSteps().get(i++) + ".form"));
    assertEquals(2, map.keySet().stream().filter(s -> s.endsWith(".signature")).count());
    assertEquals(cworkflow.getUUID() + ".pdf",
            map.keySet().stream().filter(s -> s.endsWith(".pdf")).collect(Collectors.joining(", ")));

    // verify token is deleted once signed.
    QueueListDTO msgs = getQueueMessages(token, userid);
    assertEquals(0, msgs.getMessages().size());

    verifyCompleteEmail();
}

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

License:Apache License

/**
 * testCreateWorkflow11()./*from  w  w w.j  a v  a  2s . co  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.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * Add Field to Form.//from  w  w  w  .ja  va 2 s.c o m
 * @param type {@link FormJSONFieldType}
 */
private void addField(final FormJSONFieldType type) {
    WebElement el = findElementBy(By.className("form-section"));
    JavascriptExecutor executor = (JavascriptExecutor) getDriver();
    executor.executeScript("postJSON('/api/flow?execution=' + getExecution() + " + "'&_eventId_fieldadd="
            + el.getAttribute("data-uuid") + ",1&type=" + type + "', null);");
    getDriver().navigate().refresh();
}