jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
487 stars 112 forks source link

Support for Accessing and Verifying Notifications for UI Testing #3409

Open mariodavid opened 1 week ago

mariodavid commented 1 week ago

In UI tests, it is common to encounter scenarios where production code displays notifications to the user. Currently, there is no straightforward way to programmatically access these notifications to verify their content, type (e.g., Error, Success), or presence. This issue aims to address this limitation by providing the necessary support to access and verify notifications during UI tests.

Proposed Solution

Based on the discussion with @Flaurite, the solution should involve:

  1. Internal Events for Notifications: Implement internal events that signal when a notification is shown or hidden. Use application properties to enable these events during testing by default.
  2. Test Bean for Managing Notifications: Create a test-specific bean in the UI test assist module that listens to these internal events. This bean will collect references to shown notifications and provide methods to access their content and type. Ensure the bean clears all notifications before each test to maintain a clean state.
  3. Static Methods in UiTestUtils: Provide convenient static methods in UiTestUtils to access the test bean and interact with the collected notifications.
  4. Manual Cleanup Methods: Provide methods for manually closing or clearing notifications, as they might remain open in a test environment without client-side interaction.

Example Usage

I created an example from a forum request: https://forum.jmix.io/t/checking-notifications-in-ui-test/5034/2. The implementation is different compare to the proposed solution, but it gives a good understanding on how to potentially use it: https://github.com/mariodavid/jmix-example-test-notifications