From f3eb2fc8e3817db807ae0ca96fc6815ed5715232 Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Fri, 17 Feb 2023 22:49:50 +0100 Subject: [PATCH] Adjust Selenium test --- .../java/org/kitodo/selenium/MetadataST.java | 40 +++++++++---------- .../testframework/pages/ProcessesPage.java | 20 ++-------- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java b/Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java index c355e8dbb2e..2af68367747 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java @@ -53,30 +53,39 @@ public class MetadataST extends BaseTestSelenium { private static final String TEST_METADATA_LOCK_FILE = "testMetadataLockMeta.xml"; private static int mediaReferencesProcessId = -1; private static int metadataLockProcessId = -1; + private static int parentProcessId = -1; + private static List dummyProcessIds = new LinkedList<>(); private static final String PARENT_PROCESS_TITLE = "Parent process"; private static final String FIRST_CHILD_PROCESS_TITLE = "First child process"; private static final String SECOND_CHILD_PROCESS_TITLE = "Second child process"; - private static final String DUMMY_PROCESS_TITLE = "Dummy process"; private static final String TEST_PARENT_PROCESS_METADATA_FILE = "testParentProcessMeta.xml"; private static final String FIRST_CHILD_ID = "FIRST_CHILD_ID"; private static final String SECOND_CHILD_ID = "SECOND_CHILD_ID"; private static final String META_XML = "/meta.xml"; private static List processHierarchyTestProcessIds = new LinkedList<>(); - private static int parentProcessId = -1; private static final int TEST_PROJECT_ID = 1; private static final int TEST_TEMPLATE_ID = 1; - private static void prepareMediaReferenceProcesses() throws DAOException, DataException, IOException { + private static void prepareMediaReferenceProcess() throws DAOException, DataException, IOException { + insertDummyProcesses(); insertTestProcessForMediaReferencesTest(); copyTestFilesForMediaReferences(); } private static void prepareMetadataLockProcess() throws DAOException, DataException, IOException { + insertDummyProcesses(); insertTestProcessForMetadataLockTest(); copyTestMetadataFile(metadataLockProcessId, TEST_METADATA_LOCK_FILE); } + private static void prepareProcessHierarchyProcesses() throws DAOException, IOException, DataException { + insertDummyProcesses(); + processHierarchyTestProcessIds = linkProcesses(); + copyTestParentProcessMetadataFile(); + updateChildProcessIdsInParentProcessMetadataFile(); + } + /** * Prepare tests by inserting dummy processes into database and index for sub-folders of test metadata resources. * @throws DAOException when saving of dummy or test processes fails. @@ -86,10 +95,9 @@ private static void prepareMetadataLockProcess() throws DAOException, DataExcept @BeforeClass public static void prepare() throws DAOException, DataException, IOException { MockDatabase.insertFoldersForSecondProject(); - insertDummyProcesses(); prepareMetadataLockProcess(); - insertDummyProcesses(); - prepareMediaReferenceProcesses(); + prepareMediaReferenceProcess(); + prepareProcessHierarchyProcesses(); } /** @@ -110,8 +118,6 @@ public void hideStructureDataTest() throws Exception { */ @Test public void removeMetadataLockTest() throws Exception { - User metadataUser = ServiceManager.getUserService().getByLogin("verylast"); - Pages.getLoginPage().goTo().performLogin(metadataUser); // Open process in metadata editor by default user to set metadata lock for this process and user login("kowal"); Pages.getProcessesPage().goTo().editMetadata(MockDatabase.METADATA_LOCK_TEST_PROCESS_TITLE); @@ -132,25 +138,19 @@ public void removeMetadataLockTest() throws Exception { */ @Test public void changeProcessLinkOrderTest() throws Exception { - processHierarchyTestProcessIds = linkProcesses(); - copyTestParentProcessMetadataFile(); - updateChildProcessIdsInParentProcessMetadataFile(); - User metadataUser = ServiceManager.getUserService().getByLogin("kowal"); - Pages.getLoginPage().goTo().performLogin(metadataUser); - Pages.getProcessesPage().goTo().editThirdProcessMetadata(); + login("kowal"); + Pages.getProcessesPage().goTo().editParentProcessMetadata(); Assert.assertTrue("Wrong initial order of linked child processes", Pages.getMetadataEditorPage().getNameOfFirstLinkedChildProcess().endsWith(FIRST_CHILD_PROCESS_TITLE)); Assert.assertTrue("Wrong initial order of linked child processes", Pages.getMetadataEditorPage().getNameOfSecondLinkedChildProcess().endsWith(SECOND_CHILD_PROCESS_TITLE)); Pages.getMetadataEditorPage().changeOrderOfLinkedChildProcesses(); Pages.getMetadataEditorPage().saveAndExit(); - Pages.getProcessesPage().goTo().editThirdProcessMetadata(); + Pages.getProcessesPage().goTo().editParentProcessMetadata(); Assert.assertTrue("Wrong resulting order of linked child processes", Pages.getMetadataEditorPage().getNameOfFirstLinkedChildProcess().endsWith(SECOND_CHILD_PROCESS_TITLE)); Assert.assertTrue("Wrong resulting order of linked child processes", Pages.getMetadataEditorPage().getNameOfSecondLinkedChildProcess().endsWith(FIRST_CHILD_PROCESS_TITLE)); - Pages.getMetadataEditorPage().closeEditor(); - cleanup(); } /** @@ -162,7 +162,6 @@ public void totalNumberOfScansTest() throws Exception { Pages.getProcessesPage().goTo().editMetadata(); assertEquals("Total number of scans is not correct", "(Anzahl von Scans: 1)", Pages.getMetadataEditorPage().getNumberOfScans()); - Pages.getMetadataEditorPage().closeEditor(); } /** @@ -178,7 +177,6 @@ public void showPaginationByDefaultTest() throws Exception { Pages.getUserEditPage().setPaginationToShowByDefault(); Pages.getProcessesPage().goTo().editMetadata(); assertTrue(Pages.getMetadataEditorPage().isPaginationPanelVisible()); - Pages.getMetadataEditorPage().closeEditor(); } /** @@ -292,7 +290,7 @@ private static void copyTestFilesForMediaReferences() throws IOException { + "/images/").toUri(); try { if (!ServiceManager.getFileService().isDirectory(targetImages)) { - ServiceManager.getFileService().createDirectory(processDir, "images"); + ServiceManager.getFileService().createDirectory(processDir, TEST_IMAGES_DIR); } ServiceManager.getFileService().copyDirectory(testImagesUri, targetImages); } catch (IOException e) { @@ -305,7 +303,7 @@ private static void copyTestMetadataFile(int processId, String filename) throws URI processDir = Paths.get(ConfigCore.getKitodoDataDirectory(), String.valueOf(processId)) .toUri(); URI processDirTargetFile = Paths.get(ConfigCore.getKitodoDataDirectory(), processId - + "/meta.xml").toUri(); + + META_XML).toUri(); URI metaFileUri = Paths.get(ConfigCore.getKitodoDataDirectory(), filename).toUri(); if (!ServiceManager.getFileService().isDirectory(processDir)) { ServiceManager.getFileService().createDirectory(Paths.get(ConfigCore.getKitodoDataDirectory()).toUri(), diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessesPage.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessesPage.java index 4cad2160883..75c86cb5102 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessesPage.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/ProcessesPage.java @@ -41,7 +41,7 @@ public class ProcessesPage extends Page { private static final String FILTER_FORM = "filterMenu"; private static final String FILTER_INPUT = "filterMenu:filterfield"; private static final String SECOND_PROCESS_TITLE = "Second process"; - private static final String THIRD_PROCESS_TITLE = "Parent process"; + private static final String PARENT_PROCESS_TITLE = "Parent process"; private static final String WAIT_FOR_ACTIONS_BUTTON = "Wait for actions menu button"; private static final String WAIT_FOR_ACTIONS_MENU = "Wait for actions menu to open"; private static final String WAIT_FOR_COLUMN_SORT = "Wait for column sorting"; @@ -331,13 +331,13 @@ public void editSecondProcessMetadata() throws IllegalAccessException, Instantia } /** - * Open third process in metadata editor. + * Open parent process in metadata editor. * @throws IllegalAccessException when navigating to metadata editor page fails * @throws InstantiationException when navigating to metadata editor page fails */ - public void editThirdProcessMetadata() throws InstantiationException, IllegalAccessException { + public void editParentProcessMetadata() throws InstantiationException, IllegalAccessException { try { - setEditMetadataLink(THIRD_PROCESS_TITLE); + setEditMetadataLink(PARENT_PROCESS_TITLE); clickButtonAndWaitForRedirect(editMetadataLink, Pages.getMetadataEditorPage().getUrl()); } catch (StaleElementReferenceException e) { e.printStackTrace(); @@ -383,18 +383,6 @@ private void setEditMetadataLink(String processTitle) { editMetadataLink = Browser.getDriver().findElementById(PROCESSES_TABLE + ":" + index + ":editMetadata"); } - /* - private void setEditMetadataLink(String processTitle) throws StaleElementReferenceException { - await("Wait for processes table to become visible").pollDelay(1, TimeUnit.SECONDS).atMost(5, TimeUnit.SECONDS) - .ignoreExceptions().until(() -> processesTable.isDisplayed()); - int index = getRowIndex(processesTable, processTitle, 3); - await("Wait for 'edit metadata' link to become enabled").pollDelay(1, TimeUnit.SECONDS).atMost(5, TimeUnit.SECONDS) - .ignoreExceptions().until(() -> Browser.getDriver().findElementById(PROCESSES_TABLE + ":" + index + ":editMetadata") - .isEnabled()); - editMetadataLink = Browser.getDriver().findElementById(PROCESSES_TABLE + ":" + index + ":editMetadata"); - } - */ - private void setDownloadLogLink() { int index = getRowIndex(processesTable, SECOND_PROCESS_TITLE, 3); downloadLogLink = Browser.getDriver().findElementById(PROCESSES_TABLE + ":" + index + ":exportLogXml");