Exemple #1
0
  /**
   * Create a file document and manipulate coverage and subjects fields based on select2 attributes.
   *
   * @throws Exception
   * @since 5.7.3
   */
  @Test
  public void testSelect2Edit() throws Exception {
    login(TEST_USERNAME, TEST_PASSWORD);
    open(String.format(NXDOC_URL_FORMAT, fileId));

    FileDocumentBasePage filePage = asPage(FileDocumentBasePage.class);
    EditTabSubPage editTabSubPage = filePage.getEditTab();

    Select2WidgetElement subjectsWidget =
        new Select2WidgetElement(
            driver,
            driver.findElement(
                By.xpath("//*[@id='s2id_document_edit:nxl_dublincore:nxw_subjects_1_select2']")),
            true);
    subjectsWidget.selectValues(SUBJECTS);

    Select2WidgetElement coverageWidget =
        new Select2WidgetElement(
            driver,
            driver.findElement(
                By.xpath("//*[@id='s2id_document_edit:nxl_dublincore:nxw_coverage_1_select2']")),
            false);
    coverageWidget.selectValue(COVERAGE);

    editTabSubPage.save();

    editTabSubPage = filePage.getEditTab();

    WebElement savedCoverage = driver.findElement(By.xpath(S2_COVERAGE_FIELD_XPATH));
    final String text = savedCoverage.getText();
    assertNotNull(text);
    assertTrue(text.endsWith(COVERAGE));

    List<WebElement> savedSubjects =
        driver.findElements(
            By.xpath(
                "//*[@id='s2id_document_edit:nxl_dublincore:nxw_subjects_1_select2']/ul/li/div"));
    assertEquals(savedSubjects.size(), SUBJECTS.length);

    // Remove the second subject
    Locator.findElementWaitUntilEnabledAndClick(
        By.xpath("//*[@id='s2id_document_edit:nxl_dublincore:nxw_subjects_1_select2']/ul/li[2]/a"));

    // We need to do this because select2 take a little while to write in
    // the form that an entry has been deleted
    Thread.sleep(250);

    editTabSubPage.save();

    filePage.getEditTab();

    // Make sure we have one subject removed
    savedSubjects =
        driver.findElements(
            By.xpath(
                "//*[@id='s2id_document_edit:nxl_dublincore:nxw_subjects_1_select2']/ul/li/div"));
    assertEquals(savedSubjects.size(), SUBJECTS.length - 1);

    logout();
  }
Exemple #2
0
 /** @since 5.9.1 */
 public void delegateTask(String taskDirective, String user) {
   TaskFancyBoxFragment taskBox = showTaskFancyBox("Delegate Task");
   taskBox.waitForTextToBePresent(taskDirective);
   Select2WidgetElement particpants =
       new Select2WidgetElement(
           driver,
           driver.findElement(
               By.xpath(
                   "//div[contains(@id, 'nxl_workflowTaskReassignmentLayout:nxw_task_reassignment_actors_select2')]")),
           true);
   particpants.selectValue(user);
   taskBox.submit();
 }
  public RelationTabSubPage setRelationWithDocument(String documentName, String predicateUri) {

    org.junit.Assert.assertFalse(isObjectDocumentChecked());

    Select predicateSelect = new Select(predicate);
    predicateSelect.selectByValue(predicateUri);

    Select2WidgetElement documentSuggestionWidget =
        new Select2WidgetElement(driver, driver.findElement(By.xpath(SELECT2_DOCUMENT_XPATH)));

    documentSuggestionWidget.selectValue(documentName);

    Function<WebDriver, Boolean> isDocumentSelected =
        new Function<WebDriver, Boolean>() {
          @Override
          public Boolean apply(WebDriver driver) {
            WebElement selectedDocument = driver.findElement(By.id(OBJECT_DOCUMENT_UID_ID));
            String value = selectedDocument.getAttribute("value");
            boolean result = StringUtils.isNotBlank(value);
            if (!result) {
              log.debug("Waiting for select2 ajaxReRender");
            }
            return result;
          }
        };

    org.junit.Assert.assertTrue(isObjectDocumentChecked());

    Wait<WebDriver> wait =
        new FluentWait<WebDriver>(driver)
            .withTimeout(SELECT2_CHANGE_TIMEOUT, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS)
            .ignoring(StaleElementReferenceException.class);

    wait.until(isDocumentSelected);

    if (log.isDebugEnabled()) {
      WebElement selectedDocument = driver.findElement(By.id(OBJECT_DOCUMENT_UID_ID));
      log.debug("Submitting relation on document: " + selectedDocument.getAttribute("value"));
    }

    addButton.click();

    return asPage(RelationTabSubPage.class);
  }
Exemple #4
0
  /** @since 8.3 */
  public PermissionsSubPage grantPermission(String permission, String userOrGroupName) {

    waitUntilEnabledAndClick(newPermission);

    WebElement addPermissionH2 =
        findElementWithTimeout(By.xpath("//h2[text()='Add a Permission']"));
    WebElement popup = addPermissionH2.findElement(By.xpath(".."));

    Select2WidgetElement userSelection =
        new Select2WidgetElement(
            driver, popup.findElement(By.className("select2-container")), false);
    userSelection.selectValue(userOrGroupName);

    // select the permission
    popup.findElement(By.tagName("iron-icon")).click();
    Locator.waitUntilGivenFunction(
        input -> {
          try {
            WebElement el = popup.findElement(By.tagName("paper-item"));
            return el.isDisplayed();
          } catch (NoSuchElementException e) {
            return false;
          }
        });
    List<WebElement> elements = popup.findElements(By.tagName("paper-item"));
    for (WebElement element : elements) {
      if (permission.equalsIgnoreCase(element.getText())) {
        element.click();
        break;
      }
    }

    // NXP-19932: take screenshot to help understanding potential randoms on click
    ScreenshotTaker taker = new ScreenshotTaker();
    File screenShot = taker.takeScreenshot(driver, "PermissionSubPage-add-permission-");
    log.warn("Screenshot taken : " + screenShot.getAbsolutePath());
    // click on Create
    Locator.findElementWaitUntilEnabledAndClick(
        popup, By.xpath(".//paper-button[text()='Create']"));
    waitForPermissionAdded(permission, userOrGroupName);

    return asPage(PermissionsSubPage.class);
  }