From 9d66d6d569afdfeb39f9c5018b37dedbdbba101e Mon Sep 17 00:00:00 2001 From: Thomas Low Date: Thu, 14 Nov 2024 10:01:05 +0000 Subject: [PATCH] Identify context menu item by class name instead of occurance order to fix selenium test. --- .../includes/metadataEditor/gallery.xhtml | 6 +++--- .../metadataEditor/logicalStructure.xhtml | 6 +++--- .../metadataEditor/physicalStructure.xhtml | 4 ++-- .../java/org/kitodo/selenium/MetadataST.java | 19 +++++-------------- .../pages/MetadataEditorPage.java | 8 +++----- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml index 60086fd5895..47b37d05888 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/metadataEditor/gallery.xhtml @@ -206,7 +206,7 @@ DataEditorForm.structurePanel.selectedLogicalNode.type eq StructurePanel.VIEW_NODE_TYPE and mediaProvider.hasPreviewVariant(DataEditorForm.galleryPanel.getGalleryMediaContent(DataEditorForm.galleryPanel.lastSelection.key))}" icon="fa fa-external-link fa-sm" - styleClass="plain" + styleClass="plain viewPageInNewWindow" outcome="externalView" target="_blank"> @@ -216,7 +216,7 @@ @@ -196,7 +196,7 @@ update="dialogEditDocStrucTypeDialog"/> Browser.getDriver().findElement(By.id("logicalTree")).isDisplayed()); - // right click on first tree node representing image 2 - WebElement firstTreeNode = Browser.getDriver().findElement( - By.cssSelector("#logicalTree\\:0_0 .ui-treenode-content") - ); - new Actions(Browser.getDriver()).contextClick(firstTreeNode).build().perform(); - - // wait until menu is visible - await().ignoreExceptions().pollDelay(100, TimeUnit.MILLISECONDS).atMost(5, TimeUnit.SECONDS) - .until(() -> Browser.getDriver().findElement(By.id("contextMenuLogicalTree")).isDisplayed()); + // open context menu for linked page "2" + Pages.getMetadataEditorPage().openContextMenuForStructureTreeNode("0_0"); // click second menu entry to open new tab - Browser.getDriver().findElement(By.cssSelector( - "#contextMenuLogicalTree .ui-menuitem:nth-child(2) .ui-menuitem-link" - )).click(); + Browser.getDriver().findElement(By.cssSelector("#contextMenuLogicalTree .viewPageInNewWindow")).click(); // find handle of new tab window String newWindowHandle = Browser.getDriver().getWindowHandles().stream() diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/MetadataEditorPage.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/MetadataEditorPage.java index 9bb7819ff62..a87dea1d367 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/MetadataEditorPage.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/MetadataEditorPage.java @@ -251,13 +251,11 @@ public void openContextMenuForStructureTreeNode(String nodeId) { /** * Click on a menu entry in the structure tree context menu. * - * @param menuEntry the menu entry index (starting with 1) + * @param menuItemClassName the class name of the menu entry */ - public void clickStructureTreeContextMenuEntry(int menuEntry) { + public void clickStructureTreeContextMenuEntry(String menuItemClassName) { // click on menu entry - contextMenuLogicalTree.findElement(By.cssSelector( - ".ui-menuitem:nth-child(" + menuEntry + ") .ui-menuitem-link" - )).click(); + contextMenuLogicalTree.findElement(By.className(menuItemClassName)).click(); // wait for context menu to disappear await().ignoreExceptions().pollDelay(100, TimeUnit.MILLISECONDS).atMost(5, TimeUnit.SECONDS) .until(() -> !contextMenuLogicalTree.isDisplayed());