mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
111 stars 14 forks source link

RichTextEditor selecting Buttons in toolbar #141

Closed nbabb closed 1 year ago

nbabb commented 1 year ago

In the RichTextEditor component I don't seem to be able to find the Button for Bold (i.e. id = btn-bold) using Locator._get(). Is this possible?

mvysny commented 1 year ago

It is easily possible. The RichTextEditor component is most probably creating those buttons on the client-side only (in the browser via javascript). That means that they do not really exist on the server-side, and that means that Karibu-Testing is not able to see/manipulate them.

I assume here that your use-case is to fill in a text and select a part of it as bold, then assert that the value has been changed. If this is the case, then perhaps you are trying to test the RichTextEditor component itself, opposed to your app. Karibu is not really suited for testing components (unless they are purely server-only).

However, it's true that Karibu-Testing should perhaps introduce utility methods to "pretend" that the bold button was pressed, and set the appropriate value to the RichTextEditor component, which will allow you to test how your code would respond to such values.

Please let me know more about your use-case and we'll figure something out.

mvysny commented 1 year ago

Closing as inactive, please reopen if you'd like this ticket to receive more attention.

However, the recommended way is to simply set a new html contents to the RichTextEditor, since pressing those buttons would effectively test the RichTextEditor component itself, instead of the functionality of your app.