Closed avdhootu27 closed 3 months ago
The dialog should append itself as a child to the UI upon open, therefore _get(Dialog.class)
should be able to locate it. Can you observe this behavior?
The dialog should append itself as a child to which component? Since dialog is shown on the top of all things who can be its parent?
The UI itself.
Can you please elaborate what do you mean by "Can you observe this behavior?", The dialog opens and I can see it when the app is running, but in tests it doesn't get append to UI, and I am not getting any errors
Sure thing. Say you have this kind of a test:
@Test
public void testGreeting() {
MockVaadin.setup();
new Dialog().open();
MockVaadin.clientRoundtrip();
System.out.println(PrettyPrintTreeKt.toPrettyTree(UI.getCurrent()));
}
It should print the following tree:
└── MockedUI[]
└── Dialog[]
Note that the Dialog component attaches itself as the direct child of the UI (represented by the MockedUI component). Also note the clientRoundtrip() function - dialog attaches itself lazily by default, and clientRoundtrip() forces eager attachment.
In your case, can you see the Dialog component in the component dump?
If not, that might be a bug in Karibu-Testing. I'll need ideally a very simple project which reproduces the issue.
Thanks. It worked. I just added MockVaadin.clientRoundtrip()
and _get(Dialog.class)
was able to locate it.
I didn't know about MockVaadin.clientRoundtrip()
. I am closing this issue now.
What's strange is that _get()
should call MockVaadin.clientRoundtrip()
automatically - you should not have to worry about it. I'll rather reopen this ticket and investigate.
Ok.
FYI, while closing the dialog I needed to use MockVaadin.clientRoundtrip()
I've upgraded Karibu-Testing testing suite to Vaadin 14.11.5 and ran the test suite. The test suite is really extensive and tests all sorts of scenarios, including the Dialogs. The tests seem to pass and I don't have to call MockVaadin.clientRoundtrip()
manually. In other words, I can't reproduce the issue. I'll need the simplest possible app/test case which reproduces the issue.
Side question: Maybe you have hooked into TestingLifecycleHook
and removed the call to clientRoundtrip()?
Right, I have hooked into TestingLifecycleHook, I didn't know that caused it. Thanks
Alrighty, no worries. I've updated the docs to stress out the importance of calling the original hook.
Is there any case in which we get NullPointerException on MockVaadin.clientRoundtrip()
?
I am testing a method which opens a dialog by
myDialog.open()
and I am checking it as_get(Dialog.class)
But getting `java.lang.AssertionError: /my-view: No visible Dialog in UI[] matching DialogIs there any different way to test Dialog? I am using karibu-testing-v10-spring with vaadin 14.