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.OAuthFederationIntegrationTest.java

License:Apache License

/**
 * testOauth03().// ww  w .j ava 2s . com
 * add oauth federation, domain only
 *
 * @throws Exception Exception
 */
@Test
public void testOauth03() throws Exception {
    // given

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

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

    findElementBy("input", "data-valuekey", "domain").sendKeys("222");
    findElementBy("input", "data-valuekey", "host").sendKeys("444");

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

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

    assertEquals(1, getTableRowCount("results"));
    List<WebElement> tablecells = findElements(By.tagName("td"));
    assertRowEquals(tablecells, Arrays.asList("222", "444", ""));

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

    // then
    assertNoOAuthSetup();
}

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

License:Apache License

/**
 *
 * @param email {@link String}/*  w  ww  .ja v a2 s . c om*/
 */
@Override
public String login(final String email) {

    String loginURL = getDefaultHostAndPort() + "/login";
    getDriver().get(loginURL);

    if (driver.getCurrentUrl().endsWith("/login")) {

        WebElement element = findElementBy(By.name("username"));
        element.sendKeys(email);

        element = findElementBy(By.name("password"));
        element.sendKeys(getDefaultPass());

        element.submit();
    }

    return null;
}

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

License:Apache License

/**
 * testLostPassword01()./*w  w  w  .jav  a 2s  . c  o  m*/
 * valid email
 */
@Test
public void testLostPassword01() {
    // given
    String email = "test@formkiq.com";
    logout();

    // when
    click(By.id("lilostpasswordhref"));

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

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

    // then
    verifyEmailSent(email);
}

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

License:Apache License

/**
 * testLostPassword02().//from  www.  ja v  a  2s. co m
 * invalid email
 */
@Test
public void testLostPassword02() {
    // given
    String email = "nouser@formkiq.com";
    logout();

    // when
    click(By.id("lilostpasswordhref"));

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

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

    // then
    assertEquals(getDefaultHostAndPort() + "/lostpassword?execution=s1e2", getCurrentUrl());

    waitUntilPageSourceText("A Reset Password link has been sent to your email address.");
    LoggerMailSender l = (LoggerMailSender) this.mail.getMailSender();
    assertEquals(0, l.getMessages().size());
    assertEquals(0, l.getMimeMessages().size());
}

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

License:Apache License

/**
 * testUsers01()./*from   w  ww  .  jav a  2s .  com*/
 * Add User - missing values
 *
 * @throws Exception Exception
 */
@Test
public void testUsers01() throws Exception {
    // given

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

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

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

    // then
    waitUntilPageSourceText("Field required");
}

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

License:Apache License

/**
 * testUsers02().//from www . j  a  v a  2s .  c  om
 * 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.UserSeleniumTest.java

License:Apache License

/**
 * testUsers03().//www.  j a  v  a 2 s. c o  m
 * duplicate email address
 *
 * @throws Exception Exception
 */
@Test
public void testUsers03() throws Exception {
    // given
    String email = getDefaultEmail();

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

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

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

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

    // then
    waitUntilPageSourceText("Email is already registered");
    assertFalse(getPageSource().contains("Field required"));
}

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

License:Apache License

/**
 * Fill Docsign Form.// w w  w.jav  a  2  s  .  c  o  m
 */
private void fillDocsign() {
    findElementBy(By.name("2")).sendKeys("jacksmith@formkiq.com");
    findElementBy(By.name("3")).sendKeys("Jack Smith");
    findElementBy(By.name("4")).sendKeys("sign this");
    findElementBy(By.name("5")).sendKeys("John Smith");
}

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

License:Apache License

/**
 * fill Schedule B.//from   w w  w  .j a va 2  s.c  o  m
 */
private void fillScheduleB() {
    findElementBy(By.name("2")).sendKeys("10");
    findElementBy(By.name("3")).sendKeys("111");
    findElementBy(By.name("4")).sendKeys("2222222");
    findElementBy(By.name("5")).sendKeys("33333");
    findElementBy(By.name("6")).sendKeys("123 Main St.");
}

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

License:Apache License

/**
 * testWorkflow01()./*from w  ww .  j  a v a2 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());
}