Skip to content

Commit

Permalink
Adjust Selenium test
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Feb 17, 2023
1 parent 27109e1 commit f3eb2fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 37 deletions.
40 changes: 19 additions & 21 deletions Kitodo/src/test/java/org/kitodo/selenium/MetadataST.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> 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<Integer> 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.
Expand All @@ -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();
}

/**
Expand All @@ -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);
Expand All @@ -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();
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -178,7 +177,6 @@ public void showPaginationByDefaultTest() throws Exception {
Pages.getUserEditPage().setPaginationToShowByDefault();
Pages.getProcessesPage().goTo().editMetadata();
assertTrue(Pages.getMetadataEditorPage().isPaginationPanelVisible());
Pages.getMetadataEditorPage().closeEditor();
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ProcessesPage extends Page<ProcessesPage> {
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";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit f3eb2fc

Please sign in to comment.