mvysny / karibu-testing

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

Testing login via LoginOverlay #95

Closed SebastianDietrich closed 2 years ago

SebastianDietrich commented 2 years ago

The example applications have a LoginView that extends com.vaadin.flow.component.login.LoginOverlay. The LoginViewTest tests navigation to LoginView and (failed, since not logged in) navigation to another view. But it does not test the login-process (i.e. entering UN/PW) itself. Although this is not generally necessary (since it just tests a vaadin component) such a test would be nice since it shows how to acces fields of a component. I've tried _get(TextField.class, spec -> spec.withId("vaadinLoginUsername")).setValue(username); since this is how com.vaadin.flow.component.login.testbench.LoginFormElement does this. But that did not work:

java.lang.AssertionError: /login: No visible TextField in UI[] matching TextField and id='vaadinLoginUsername': []. Component tree:
└── UI[]
    └── LoginView[]

Now I am not sure if accessing fields of a component is even possible with karibu-testing, or if I did anything wrong.

mvysny commented 2 years ago

Hi, unfortunately those fields are only present in the browser - those fields are not present on the server-side. I think it's even mentioned in Karibu's documentation 🤔 let me check.

Unfortunately that makes testing of the actual login process Via Karibu testing impossible. The best you can do is to invoke the login listener.

mvysny commented 2 years ago

Yup, mentioned at https://github.com/mvysny/karibu-testing/tree/master/karibu-testing-v10#support-for-loginform-and-loginoverlay . Closing, please reopen if the documentation could be improved.

SebastianDietrich commented 2 years ago

Thanks for that superquick answer - and sorry for not having found that documentation myself. The reason for that is that I've just checked the README.md in https://github.com/mvysny/karibu-testing and was not aware of the much more extensive README.md documentation in https://github.com/mvysny/karibu-testing/tree/master/karibu-testing-v10. Totally my fault, since it is mentioned in the main README.md.

mvysny commented 2 years ago

No problem! I'll try to make the main page link more prominent; also I'll try to describe the login view issue in more detail in the documentation