-
Notifications
You must be signed in to change notification settings - Fork 23
Closed
Description
Lets consider a following code in a test:
var component = grid_.getCellComponent(0, 5);
var button = $(Button.class).withCaption("Edit").first();
test(button).click();
While the view has something like this:
grid.addComponentColumn(address -> {
Button editButton = new Button("Edit");
editButton.addClickListener(event -> {
// Edit code here
});
Button deleteButton = new Button("Delete");
deleteButton.addClickListener(event -> {
// Delete code here
});
HorizontalLayout actions = new HorizontalLayout(editButton,
deleteButton);
return actions;
}).setHeader("Actions").setWidth("220px");
The test will fail in error "Button[caption=‘Edit’] is not usable"
See also: https://vaadin.com/forum/t/vaadintestbench-grid-componentrenderer-problem/164902/2
This happens because GridTester
just calls the component creator lambda, but does not attach the resulting component anywhere, hence the button.isAttached()
is false
, as the parent HorizontalLayout
is not attached.
The problem is possibly not limited to ButtonTester
failing, but anything in rendered components may fail in test, if the case requires the component to be attached, most importantly the onAttach
is not going to be triggered.
Workaround
Use button.click()
instead of test(button).click();
LudovicLemaire
Metadata
Metadata
Assignees
Labels
No labels