/** Qmetry ID: 102084 Check the same name when accessed via WEBDAV */
  @Test
  public void test02_CheckTheSameNameWhenAccessedViaWEBDAV() {
    String filePath = "TestData/test.txt";
    By eFile = By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", "test.txt"));
    String newFileName = "rename02";
    By editFile =
        By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", newFileName + ".txt"));

    info("-- Test case: Check the same name when accessed via WEBDAV --");

    // Go to Personal Drive
    navToolBar.goToPersonalDocuments();
    magDrv.addView2Drive("Web", "Personal Documents");
    navToolBar.goToSiteExplorer();
    actBar.chooseDrive(ecms.ELEMENT_PERSONAL_DRIVE);

    // Test Data > Upload a file: filename.txt
    // ecms.uploadFile(filePath);
    if (waitForAndGetElement(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN, DEFAULT_TIMEOUT, 2000, 0)
        == null) {
      info("click on More link");
      click(ecms.ELEMENT_MORE_LINK_WITHOUT_BLOCK);
      info("click upload button");
      click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    } else click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    uploadFileUsingRobot(filePath);

    // Rename a file
    // cMenu.contextMenuAction(eFile, cMenu.ELEMENT_MENU_RENAME_NODE, newFileName);
    // right click on eFile
    rightClickOnElement(eFile);

    // Rename a file and click [Cancel Button]
    waitForAndGetElement(cMenu.ELEMENT_MENU_RENAME_NODE, 3000);
    click(cMenu.ELEMENT_MENU_RENAME_NODE, 3000);
    type(cMenu.ELEMENT_INPUT_RENAME_NODE, newFileName, true);
    button.rename();
    waitForAndGetElement(editFile);

    // View information
    cMenu.contextMenuAction(editFile, cMenu.ELEMENT_VIEW_INFORMATION);
    waitForAndGetElement(
        cMenu.ELEMENT_POPUP_VIEW_INFORMATION_NAME.replace("${fileName}", newFileName + ".txt"));
    button.close();

    // Download and Allow Edition
    cMenu.contextMenuAction(editFile, cMenu.ELEMENT_MENU_DOWNLOAD);
    switchToNewWindow();

    // The url of the browser should end by rename02.txt
    String fileName = Utils.getFileNameFromCurrentUrl(driver);
    assert fileName.equals(newFileName + ".txt")
        : "Failed: check the same name when accessed via WEBDAV";

    // Restore data
    switchToParentWindow();
    cMenu.deleteDocument(editFile);
  }
  @BeforeMethod
  public void setUpBeforeTest() {
    initSeleniumTest();
    driver.get(baseUrl);
    navToolBar = new NavigationToolbar(driver, this.plfVersion);
    magAcc = new ManageAccount(driver, this.plfVersion);
    magAcc.signIn(DATA_USER1, DATA_PASS);
    ecms = new EcmsBase(driver, this.plfVersion);
    actBar = new ActionBar(driver, this.plfVersion);
    conTemp = new ContentTemplate(driver, this.plfVersion);

    info("Config New Content on action bar for admin view if it is not available on action bar");
    navToolBar.goToPersonalDocuments();
    actBar.addItem2ActionBar("addDocument", actBar.ELEMENT_NEW_CONTENT_LINK, "Admin", "Admin");
    actBar.chooseDrive(ecms.ELEMENT_PERSONAL_DRIVE);
  }
  /** Qmetry ID: 102083 Rename on Rename button */
  @Test
  public void test13_RenameOnRenameButton() {
    String filePath = "TestData/test.txt";
    By eFile = By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", "test.txt"));
    String newFileName = "rename13";
    By editFile =
        By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", newFileName + ".txt"));

    info("-- Test case: Rename on Rename button --");

    // Go to Personal Drive
    navToolBar.goToPersonalDocuments();
    magDrv.addView2Drive("Web", "Personal Documents");
    navToolBar.goToSiteExplorer();
    actBar.chooseDrive(ecms.ELEMENT_PERSONAL_DRIVE);

    // Test Data > Upload a file: filename.txt
    // ecms.uploadFile(filePath);
    if (waitForAndGetElement(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN, DEFAULT_TIMEOUT, 2000, 0)
        == null) {
      info("click on More link");
      click(ecms.ELEMENT_MORE_LINK_WITHOUT_BLOCK);
      info("click upload button");
      click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    } else click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    uploadFileUsingRobot(filePath);

    // Rename a file
    /*cMenu.contextMenuAction(eFile, cMenu.ELEMENT_MENU_RENAME_NODE, newFileName);
    waitForAndGetElement(editFile);*/
    // right click on file
    rightClickOnElement(eFile);

    // Rename a file and click [Cancel Button]
    waitForAndGetElement(cMenu.ELEMENT_MENU_RENAME_NODE, 3000);
    click(cMenu.ELEMENT_MENU_RENAME_NODE, 3000);
    type(cMenu.ELEMENT_INPUT_RENAME_NODE, newFileName, true);
    button.rename();
    waitForAndGetElement(editFile);

    // Restore data
    cMenu.deleteDocument(editFile);
  }
  /** Qmetry ID: 102077 Focus is set in rename field */
  @Test
  public void test07_FocusIsSetInRenameField() {
    String filePath = "TestData/test.txt";
    By eFile = By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", "test.txt"));
    String newFileName = "rename07";
    By editFile =
        By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", newFileName + ".txt"));

    info("-- Test case: Focus is set in rename field --");

    // Go to Personal Drive
    navToolBar.goToPersonalDocuments();
    magDrv.addView2Drive("Web", "Personal Documents");
    navToolBar.goToSiteExplorer();
    actBar.chooseDrive(ecms.ELEMENT_PERSONAL_DRIVE);

    // Test Data > Upload a file: filename.txt
    // ecms.uploadFile(filePath);
    if (waitForAndGetElement(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN, DEFAULT_TIMEOUT, 2000, 0)
        == null) {
      info("click on More link");
      click(ecms.ELEMENT_MORE_LINK_WITHOUT_BLOCK);
      info("click upload button");
      click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    } else click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    uploadFileUsingRobot(filePath);

    // right click on eFile
    rightClickOnElement(eFile);

    // Focus is set in rename field
    click(cMenu.ELEMENT_MENU_RENAME_NODE);
    type(cMenu.ELEMENT_INPUT_RENAME_NODE, newFileName, true);
    WebElement element = waitForAndGetElement(cMenu.ELEMENT_INPUT_RENAME_NODE);
    String fileName = element.getAttribute("value");
    assert fileName.equals(newFileName) : "Failed: Focus is set in rename field";
    element.sendKeys(Keys.RETURN);
    waitForAndGetElement(editFile);

    // Restore data
    cMenu.deleteDocument(editFile);
  }
  /**
   * Qmetry ID: 102075 File name is updated after the rename operation is finished ================
   * Qmetry ID: 102082 Rename on Enter key
   */
  @Test
  public void test05_FileNameIsUpdatedAfterTheRenameOperationIsFinished() {
    String filePath = "TestData/test.txt";
    By eFile = By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", "test.txt"));
    String newFileName = "rename05";
    By editFile =
        By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", newFileName + ".txt"));

    info("-- Test case: Rename on Enter key --");

    // Go to Personal Drive
    navToolBar.goToPersonalDocuments();
    magDrv.addView2Drive("Web", "Personal Documents");
    navToolBar.goToSiteExplorer();
    actBar.chooseDrive(ecms.ELEMENT_PERSONAL_DRIVE);

    // Test Data > Upload a file: filename.txt
    // ecms.uploadFile(filePath);
    if (waitForAndGetElement(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN, DEFAULT_TIMEOUT, 2000, 0)
        == null) {
      info("click on More link");
      click(ecms.ELEMENT_MORE_LINK_WITHOUT_BLOCK);
      info("click upload button");
      click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    } else click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    uploadFileUsingRobot(filePath);

    // right click on eFile
    rightClickOnElement(eFile);

    // Rename on Enter key
    click(cMenu.ELEMENT_MENU_RENAME_NODE);
    type(cMenu.ELEMENT_INPUT_RENAME_NODE, newFileName, true);
    WebElement element = waitForAndGetElement(cMenu.ELEMENT_INPUT_RENAME_NODE);
    element.sendKeys(Keys.RETURN);
    waitForAndGetElement(editFile);

    // Restore data
    cMenu.deleteDocument(editFile);
  }
  /** Qmetry ID: 102073 File extension not shown in rename form */
  @Test
  public void test03_FileExtensionNotShownInRenameForm() {
    String filePath = "TestData/ECMS_Undo_Delete_1.txt";
    By eFile =
        By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", "ECMS_Undo_Delete_1.txt"));

    info("-- Test case: File extension not shown in rename form --");

    // Go to Personal Drive
    navToolBar.goToPersonalDocuments();
    magDrv.addView2Drive("Web", "Personal Documents");
    navToolBar.goToSiteExplorer();
    actBar.chooseDrive(ecms.ELEMENT_PERSONAL_DRIVE);

    // Test Data > Upload a file: filename.txt
    // ecms.uploadFile(filePath);
    if (waitForAndGetElement(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN, DEFAULT_TIMEOUT, 2000, 0)
        == null) {
      info("click on More link");
      click(ecms.ELEMENT_MORE_LINK_WITHOUT_BLOCK);
      info("click upload button");
      click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    } else click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    uploadFileUsingRobot(filePath);

    // right click on eFile
    rightClickOnElement(eFile);

    // Verify that File extension is not shown
    click(cMenu.ELEMENT_MENU_RENAME_NODE);
    WebElement element = waitForAndGetElement(cMenu.ELEMENT_INPUT_RENAME_NODE);
    String fileName = element.getAttribute("value");
    assert fileName.equals("ECMS_Undo_Delete_1") : "Failed: check File extension is not shown";
    button.cancel();

    // Restore data
    cMenu.deleteDocument(eFile);
  }
  /** Qmetry ID: 102072 Cancel button should dismiss the form without renaming */
  @Test
  public void test01_CancelButtonShouldDismissTheFormWithoutRenaming() {
    String filePath = "TestData/test.txt";
    By eFile = By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", "test.txt"));
    String newFileName = "rename01";

    info("-- Test case: Cancel button should dismiss the form without renaming --");

    // Go to Personal Drive
    navToolBar.goToPersonalDocuments();
    magDrv.addView2Drive("Web", "Personal Documents");
    navToolBar.goToSiteExplorer();
    actBar.chooseDrive(ecms.ELEMENT_PERSONAL_DRIVE);

    // Test Data > Upload a file: filename.txt
    if (waitForAndGetElement(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN, DEFAULT_TIMEOUT, 2000, 0)
        == null) {
      info("click on More link");
      click(ecms.ELEMENT_MORE_LINK_WITHOUT_BLOCK);
      info("click upload button");
      click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    } else click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    uploadFileUsingRobot(filePath);

    // right click on eFile
    rightClickOnElement(eFile);

    // Rename a file and click [Cancel Button]
    waitForAndGetElement(cMenu.ELEMENT_MENU_RENAME_NODE, 3000);
    click(cMenu.ELEMENT_MENU_RENAME_NODE, 3000);
    type(cMenu.ELEMENT_INPUT_RENAME_NODE, newFileName, true);
    button.cancel();
    waitForAndGetElement(eFile);

    // Restore data
    cMenu.deleteDocument(eFile);
  }
  /** Qmetry ID: 102074 File name is restored if leaving name blank while renaming */
  @Test
  public void test04_FileNameIsRestoredIfLeavingNameBlankWhileRenaming() {
    String filePath = "TestData/test.txt";
    By eFile = By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", "test.txt"));

    info("-- Test case: File name is restored if leaving name blank while renaming --");

    // Go to Personal Drive
    navToolBar.goToPersonalDocuments();
    magDrv.addView2Drive("Web", "Personal Documents");
    navToolBar.goToSiteExplorer();
    actBar.chooseDrive(ecms.ELEMENT_PERSONAL_DRIVE);

    // Test Data > Upload a file: filename.txt
    // ecms.uploadFile(filePath);
    if (waitForAndGetElement(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN, DEFAULT_TIMEOUT, 2000, 0)
        == null) {
      info("click on More link");
      click(ecms.ELEMENT_MORE_LINK_WITHOUT_BLOCK);
      info("click upload button");
      click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    } else click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    uploadFileUsingRobot(filePath);

    // right click on eFile
    rightClickOnElement(eFile);

    // leaving name blank while renaming and hit [Enter] key
    click(cMenu.ELEMENT_MENU_RENAME_NODE);
    type(cMenu.ELEMENT_INPUT_RENAME_NODE, "", true);
    WebElement element = waitForAndGetElement(cMenu.ELEMENT_INPUT_RENAME_NODE);
    element.sendKeys(Keys.RETURN);
    waitForAndGetElement(eFile);

    // Restore data
    cMenu.deleteDocument(eFile);
  }
  /** Qmetry ID: 102085 Should add title on the fly */
  @Test
  public void test14_ShouldAddTitleOnTheFly() {
    String filePath = "TestData/test.txt";
    By eFile = By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", "test.txt"));
    String newFileName = "rename14";
    By editFile =
        By.xpath(siteExp.ELEMENT_DOCUMENT_TITLE.replace("${title}", newFileName + ".txt"));
    String property = "exo:title";

    info("-- Test case: Should add title on the fly --");

    // Go to Personal Drive
    navToolBar.goToPersonalDocuments();
    magDrv.addView2Drive("Web", "Personal Documents");

    actBar.goToViewMode("Web");
    actBar.addItem2ActionBar("viewProperties", actBar.ELEMENT_VIEW_PROPERTIES_ICON);
    // navToolBar.goToPersonalDocuments();
    Utils.pause(500);
    click(ELEMENT_PERSONAL_DOCUMENTS);
    actBar.goToViewMode("Web");

    // Test Data > Upload a file: filename.txt
    // ecms.uploadFile(filePath);
    if (waitForAndGetElement(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN, DEFAULT_TIMEOUT, 2000, 0)
        == null) {
      info("click on More link");
      click(ecms.ELEMENT_MORE_LINK_WITHOUT_BLOCK);
      info("click upload button");
      click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    } else click(ecms.ELEMENT_ACTION_BAR_UPLOAD_BTN);
    uploadFileUsingRobot(filePath);

    // Go to properties tab
    doubleClickOnElement(eFile);
    actBar.goToPropertiesTab();

    // Remove property [exo:title]
    actBar.actionsOnSelectedProperty(property, "Delete");
    click(ecms.ELEMENT_BACK_PREVIOUS_NODE);

    // Rename a file
    /*cMenu.contextMenuAction(eFile, cMenu.ELEMENT_MENU_RENAME_NODE, newFileName);
    waitForAndGetElement(editFile);*/
    // right click on file
    rightClickOnElement(eFile);

    // Rename a file and click [Cancel Button]
    waitForAndGetElement(cMenu.ELEMENT_MENU_RENAME_NODE, 3000);
    click(cMenu.ELEMENT_MENU_RENAME_NODE, 3000);
    type(cMenu.ELEMENT_INPUT_RENAME_NODE, newFileName, true);
    button.rename();
    waitForAndGetElement(editFile);

    // Go to properties tab
    doubleClickOnElement(editFile);
    actBar.goToPropertiesTab();
    waitForAndGetElement(
        actBar
            .ELEMENT_PROPERTY
            .replace("{$property}", property)
            .replace("{$value}", newFileName + ".txt"));
    button.close();

    // Restore data
    click(ecms.ELEMENT_BACK_PREVIOUS_NODE);
    cMenu.deleteDocument(editFile);
  }