diff --git a/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java b/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java index 73b671a3154..cc089f9356a 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/CalendarST.java @@ -75,6 +75,7 @@ public void createProcessFromCalendar() throws Exception { calendarPage.addBlock(); calendarPage.addIssue("Morning issue"); calendarPage.addIssue("Evening issue"); + assertEquals("Number of issues in the calendar does not match", 4, calendarPage.countIssues()); calendarPage.addMetadataToThis(); calendarPage.addMetadataToAll(); List morningIssueMetadata = calendarPage.getMetadata("Morning issue"); diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/CalendarPage.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/CalendarPage.java index 32475a38dfb..b726147de99 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/CalendarPage.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/CalendarPage.java @@ -22,15 +22,12 @@ import org.kitodo.selenium.testframework.Browser; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; public class CalendarPage extends Page { private static final String BUTTON_CANCEL = "editForm:cancel"; private static final String BUTTON_ADD_BLOCK = "editForm:calendarTabView:addBlock"; private static final String DATEPICKER_FROM = "#editForm\\:calendarTabView\\:blockList td:first-child .p-datepicker input"; - private static final String DATEPICKER_FROM_LINK = "//div[@id='editForm:calendarTabView:blockList:0:blockFirstAppearance_panel']//" - + "a[text()='1']"; private static final String DATEPICKER_TO_LINK = "(//div[@id='editForm:calendarTabView:blockList:0:blockLastAppearance_panel']//" + "a[text()='7'])[last()]"; private static final String DATEPICKER_TO = "#editForm\\:calendarTabView\\:blockList td:last-child .p-datepicker input"; @@ -50,84 +47,10 @@ public class CalendarPage extends Page { private static final String METADATA_TYPE_PANEL = METADATA_TYPE + "_panel"; private static final String METADATA_VALUE = "calendarDayForm:issuesAccordion:0:metadataDataView:0:startValue"; private static final String CALENDAR_DIALOG_CLOSE_BUTTON = "calendarDayForm:close"; + private static final String CALENDAR = "editForm:calendarTabView:calendarTable"; + private static final String CALENDAR_ISSUES = ".issue.match"; - @SuppressWarnings("unused") - @FindBy(id = BUTTON_ADD_BLOCK) - private WebElement buttonAddBlock; - - @SuppressWarnings("unused") - @FindBy(id = BUTTON_CANCEL) - private WebElement buttonCancel; - - @SuppressWarnings("unused") - @FindBy(css = DATEPICKER_FROM) - private WebElement datepickerFrom; - - @SuppressWarnings("unused") - @FindBy(xpath = DATEPICKER_FROM_LINK) - private WebElement datepickerFromLink; - - @SuppressWarnings("unused") - @FindBy(css = DATEPICKER_TO) - private WebElement datepickerTo; - - @SuppressWarnings("unused") - @FindBy(xpath = DATEPICKER_TO_LINK) - private WebElement datepickerToLink; - - @SuppressWarnings("unused") - @FindBy(css = BUTTON_ADD_ISSUE) - private WebElement buttonAddIssue; - - @SuppressWarnings("unused") - @FindBy(css = INPUT_ISSUE) - private WebElement inputIssueName; - - @SuppressWarnings("unused") - @FindBy(id = HEADER_TEXT) - private WebElement headerText; - - @SuppressWarnings("unused") - @FindBy(css = CHECKBOX_MONDAY) - private WebElement checkboxMonday; - - @SuppressWarnings("unused") - @FindBy(css = CHECKBOX_TUESDAY) - private WebElement checkboxTuesday; - - @SuppressWarnings("unused") - @FindBy(xpath = CALENDAR_ENTRY) - private WebElement calendarEntry; - - @SuppressWarnings("unused") - @FindBy(xpath = CALENDAR_ENTRY_BUTTON) - private WebElement calendarEntryButton; - - @SuppressWarnings("unused") - @FindBy(id = BUTTON_ADD_METADATA_TO_THIS) - private WebElement buttonAddMetadataToThis; - - @SuppressWarnings("unused") - @FindBy(id = BUTTON_ADD_METADATA_TO_ALL) - private WebElement buttonAddMetadataToAll; - - @SuppressWarnings("unused") - @FindBy(id = METADATA_TYPE) - private WebElement metadataType; - - @SuppressWarnings("unused") - @FindBy(id = METADATA_TYPE_PANEL) - private WebElement metadataTypePanel; - - @SuppressWarnings("unused") - @FindBy(id = METADATA_VALUE) - private WebElement metadataValue; - - @SuppressWarnings("unused") - @FindBy(id = CALENDAR_DIALOG_CLOSE_BUTTON) - private WebElement calendarDialogCloseButton; - public CalendarPage() { super("pages/calendar.jsf"); } @@ -142,26 +65,35 @@ public CalendarPage goTo() { */ public void addBlock() { await("Wait for button to be displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(buttonAddBlock.isEnabled())); - buttonAddBlock.click(); + .untilAsserted(() -> assertTrue(getById(BUTTON_ADD_BLOCK).isEnabled())); + getById(BUTTON_ADD_BLOCK).click(); await("Wait for datepicker from being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(datepickerFrom.isEnabled())); - datepickerFrom.click(); - datepickerFromLink.click(); + .untilAsserted(() -> assertTrue(getByCSS(DATEPICKER_FROM).isEnabled())); + getByCSS(DATEPICKER_FROM).click(); + getByCSS(DATEPICKER_FROM).sendKeys("01.02.2023"); + getPageHeader().click(); await("Wait for datepicker to being displayed") - .pollDelay(3, TimeUnit.SECONDS) + .pollDelay(2, TimeUnit.SECONDS) + .pollInterval(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(datepickerToLink.isEnabled())); - datepickerToLink.click(); + .untilAsserted(() -> assertTrue(getByXPath(DATEPICKER_TO_LINK).isEnabled())); + getByCSS(DATEPICKER_TO).click(); + await("Wait for datepicker to being displayed") + .pollDelay(2, TimeUnit.SECONDS) + .pollInterval(400, TimeUnit.MILLISECONDS) + .atMost(10, TimeUnit.SECONDS) + .ignoreExceptions() + .untilAsserted(() -> assertTrue(getByXPath(DATEPICKER_TO_LINK).isEnabled())); + getByXPath(DATEPICKER_TO_LINK).click(); } /** @@ -170,47 +102,47 @@ public void addBlock() { */ public void addIssue(String title) { await("Wait for issue button being displayed") - .pollDelay(3, TimeUnit.SECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(buttonAddIssue.isEnabled())); - buttonAddIssue.click(); + .untilAsserted(() -> assertTrue(getByCSS(BUTTON_ADD_ISSUE).isEnabled())); + getByCSS(BUTTON_ADD_ISSUE).click(); await("Wait for issue input being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(inputIssueName.isEnabled())); - inputIssueName.click(); - inputIssueName.sendKeys(title); - headerText.click(); + .untilAsserted(() -> assertTrue(getByCSS(INPUT_ISSUE).isEnabled())); + getByCSS(INPUT_ISSUE).click(); + getByCSS(INPUT_ISSUE).sendKeys(title); + getById(HEADER_TEXT).click(); await("Wait for checkbox being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(checkboxMonday.isDisplayed())); - checkboxMonday.click(); + .untilAsserted(() -> assertTrue(getByCSS(CHECKBOX_MONDAY).isDisplayed())); + getByCSS(CHECKBOX_MONDAY).click(); await("Wait for checkbox being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(checkboxMonday.isDisplayed())); - checkboxTuesday.click(); + .untilAsserted(() -> assertTrue(getByCSS(CHECKBOX_MONDAY).isDisplayed())); + getByCSS(CHECKBOX_TUESDAY).click(); } /** * Add metadata to this issue. Type "Process title" and value "Test" will be inserted. */ public void addMetadataToThis() { - addMetadata("Process title", "Test", buttonAddMetadataToThis); + addMetadata("Process title", "Test", BUTTON_ADD_METADATA_TO_THIS); } /** * Add metadata to this and all following issues. Type "Signatur" and value "1234" will be used. */ public void addMetadataToAll() { - addMetadata("Signatur", "1234", buttonAddMetadataToAll); + addMetadata("Signatur", "1234", BUTTON_ADD_METADATA_TO_ALL); } /** @@ -220,21 +152,22 @@ public void addMetadataToAll() { */ public List getMetadata(String issueName) { await("Wait for calendar entry being displayed") - .pollDelay(3, TimeUnit.SECONDS) + .pollDelay(2, TimeUnit.SECONDS) + .pollInterval(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue( calendarEntry.isDisplayed())); - calendarEntryButton.click(); + .untilAsserted(() -> assertTrue(getByXPath(CALENDAR_ENTRY).isDisplayed())); + getByXPath(CALENDAR_ENTRY_BUTTON).click(); await("Wait for issue '" + issueName + "' being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() .untilAsserted(() -> assertTrue(getIssue(issueName).isDisplayed())); if (Objects.equals(getIssue(issueName).getAttribute("aria-expanded"), "false")) { - Browser.getDriver().findElementByXPath("//div[@aria-expanded='true']").click(); + getByXPath("//div[@aria-expanded='true']").click(); await("Wait for issue '" + issueName + "' being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() .untilAsserted(() -> assertTrue(getIssue(issueName).isDisplayed())); @@ -242,13 +175,13 @@ public List getMetadata(String issueName) { } await("Wait for issue content for '" + issueName + "' being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() .untilAsserted(() -> assertTrue(getIssueContent(issueName).isDisplayed())); List metadataList = readMetadataTypes(issueName); - calendarDialogCloseButton.click(); + getById(CALENDAR_DIALOG_CLOSE_BUTTON).click(); return metadataList; } @@ -257,46 +190,52 @@ public List getMetadata(String issueName) { * Click cancel button and leave calendar. */ public void closePage() { - buttonCancel.click(); + getById(BUTTON_CANCEL).click(); } - private void addMetadata(String type, String value, WebElement addButton) { + public int countIssues() { + await("Wait for calendar issues to be displayed") + .untilAsserted(() -> assertTrue(getById(CALENDAR).isDisplayed())); + return getById(CALENDAR).findElements(By.cssSelector(CALENDAR_ISSUES)).size(); + } + + private void addMetadata(String type, String value, String addButton) { await("Wait for calendar entry being displayed") - .pollDelay(3, TimeUnit.SECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue( calendarEntry.isDisplayed())); - calendarEntryButton.click(); + .untilAsserted(() -> assertTrue(getByXPath(CALENDAR_ENTRY).isDisplayed())); + getByXPath(CALENDAR_ENTRY_BUTTON).click(); await("Wait for button to add metadata to this issue being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(addButton.isEnabled())); - addButton.click(); + .untilAsserted(() -> assertTrue(getById(addButton).isEnabled())); + getById(addButton).click(); await("Wait for button to add metadata to this issue being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(metadataType.isEnabled())); - metadataType.click(); - metadataTypePanel.findElement(By.xpath("//li[text()='" + type + "']")).click(); + .untilAsserted(() -> assertTrue(getById(METADATA_TYPE).isEnabled())); + getById(METADATA_TYPE).click(); + getById(METADATA_TYPE_PANEL).findElement(By.xpath("//li[text()='" + type + "']")).click(); await("Wait for metadata input being displayed") - .pollDelay(700, TimeUnit.MILLISECONDS) + .pollDelay(400, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .ignoreExceptions() - .untilAsserted(() -> assertTrue(metadataValue.isEnabled())); - metadataValue.sendKeys(value); - calendarDialogCloseButton.click(); + .untilAsserted(() -> assertTrue(getById(METADATA_VALUE).isEnabled())); + getById(METADATA_VALUE).sendKeys(value); + getById(CALENDAR_DIALOG_CLOSE_BUTTON).click(); } private WebElement getIssue(String name) { - return Browser.getDriver().findElementByXPath( "//div[text()='" + name + " erschien']"); + return getByXPath( "//div[text()='" + name + " erschien']"); } private WebElement getIssueContent(String name) { - return Browser.getDriver().findElementByXPath("//div[text()='" + name + " erschien']/following-sibling::div"); + return getByXPath("//div[text()='" + name + " erschien']/following-sibling::div"); } private List readMetadataTypes(String issueName) { @@ -304,4 +243,16 @@ private List readMetadataTypes(String issueName) { + " erschien']/following-sibling::div[@aria-hidden='false']//div[@title='Art']/label"); return metadataTypeLabels.stream().map(WebElement::getText).collect(Collectors.toList()); } + + private WebElement getById(String id) { + return Browser.getDriver().findElementById(id); + } + + private WebElement getByCSS(String cssSelector) { + return Browser.getDriver().findElementByCssSelector(cssSelector); + } + + private WebElement getByXPath(String xpath) { + return Browser.getDriver().findElementByXPath(xpath); + } } diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/Page.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/Page.java index f729b38f3eb..e018516f0e4 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/Page.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/pages/Page.java @@ -70,6 +70,10 @@ public abstract class Page { @FindBy(id = "search-form:search") private WebElement searchButton; + @SuppressWarnings("unused") + @FindBy(id = "portal-header") + private WebElement pageHeader; + private String URL; Page(String URL) { @@ -212,6 +216,10 @@ protected void clickElement(WebElement element) { .ignoreExceptions().until(() -> isButtonClicked.test(element)); } + public WebElement getPageHeader() { + return pageHeader; + } + /** * Get header text. *