diff --git a/src/addons/calendar/tests/behat/create_events.feature b/src/addons/calendar/tests/behat/create_events.feature index afde42680..6f995d079 100755 --- a/src/addons/calendar/tests/behat/create_events.feature +++ b/src/addons/calendar/tests/behat/create_events.feature @@ -20,13 +20,14 @@ Feature: Test creation of calendar events in app | teacher1 | C1 | editingteacher | | student1 | C1 | student | - @ionic7_failure + # This test is flaky due to timestamp. Scenario: Create user event as student from monthly view Given I entered the app as "student1" When I press "More" in the app And I press "Calendar" in the app And I press "New event" in the app - Then the field "Date" matches value "## now ##%d/%m/%y, %H:%M##" in the app + # Flaky step, sometimes it fails due to minute change when checking. + Then the field "Date" matches value "## now ##%Y-%m-%dT%H:%M##" in the app And I should not be able to press "Save" in the app # Check that student can only create User events. @@ -36,7 +37,7 @@ Feature: Test creation of calendar events in app # Create the event. When I set the field "Event title" to "User Event 01" in the app - And I set the field "Date" to "2025-04-11T09:00+08:00" in the app + And I set the field "Date" to "2025-04-11T09:00" in the app And I press "Without duration" in the app And I set the field "Description" to "This is User Event 01 description." in the app And I set the field "Location" to "Barcelona" in the app diff --git a/src/testing/services/behat-dom.ts b/src/testing/services/behat-dom.ts index fe32cb01c..c199918ab 100644 --- a/src/testing/services/behat-dom.ts +++ b/src/testing/services/behat-dom.ts @@ -401,7 +401,7 @@ export class TestingBehatDomUtilsService { */ findField(field: string): HTMLElement | HTMLInputElement | undefined { const input = this.findElementBasedOnText( - { text: field, selector: 'input, textarea, [contenteditable="true"], ion-select, ion-datetime' }, + { text: field, selector: 'input, textarea, [contenteditable="true"], ion-select, ion-datetime-button, ion-datetime' }, { onlyClickable: false, containerName: '' }, ); diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index 0b938c175..fc32e4d50 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -508,12 +508,15 @@ export class TestingBehatRuntimeService { * @returns Value. */ protected getFieldValue(element: HTMLElement | HTMLInputElement): string { + if (element.tagName === 'ION-DATETIME-BUTTON' && element.shadowRoot) { + return Array.from(element.shadowRoot.querySelectorAll('button')).map(button => button.innerText).join(' '); + } + if (element.tagName === 'ION-DATETIME') { - // ion-datetime's value is a timestamp in ISO format. Use the text displayed to the user instead. - const dateTimeTextElement = element.shadowRoot?.querySelector('.datetime-text'); - if (dateTimeTextElement) { - return dateTimeTextElement.innerText; - } + const value = 'value' in element ? element.value : element.innerText; + + // Remove seconds from the value to ensure stability on tests. It could be improved using moment parsing if needed. + return value.substring(0, value.length - 3); } return 'value' in element ? element.value : element.innerText;