-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fast Grid Dump #1876
Comments
I think this is out of scope of TestBench browser tests and should be done with TestBench UI Unit Test instead. |
Perhaps... But then again, the point of Grid is to show the data, and the point of TestBench is to assert on the presence and state of components. In such a context, what sense has |
It is not a question is it possible or not. With current API it is possible already. It is just about performance regarding special cases. Here is one approach of producing two dimensional collection of the WebElements representing slotted content in the Grid. I compared the ten run average run time of the test code only excluding the test start and shutdown time.
The results were assessGridContentTest0: 0.1 sec So it looks like the execution time if the test is 1/3 of the current method. |
I don't think that asserting against the state of the grid is a special case: this is actually the most common case you use TestBench for. And, if the performance of that can be improved by a factor of 50, that is quite a significant improvement which turns "unusable/too slow" into "usable". |
This is basically the same thing as defending a program which runs n+1 SQL selects instead of one SQL with a TestBench API is broken by design - it forces you to run n+1 queries for anything more complex than the most basic stuff. |
As it turns out, we'll need the HTML contents of the Grid cell, so the grid dump functionality should return both. The best solution would be an
A prototype of such iterator follows. Note that this iterator has a bad performance of making O(nm) requests to the browser, so it should serve only as a case study. public class PagedGridTRElementIterator implements Iterator<GridTRElement> {
@NotNull
private final GridElement grid;
private final int rows;
private int nextRowToBeReturned = 0;
@NotNull
private List<GridTRElement> rowsToBeReturned = new ArrayList<>();
public PagedGridTRElementIterator(@NotNull GridElement grid) {
this.grid = grid;
rows = grid.getRowCount();
}
@NotNull
public static Iterable<GridTRElement> iterable(@NotNull final GridElement grid) {
return new Iterable<>() {
@NotNull
@Override
public Iterator<GridTRElement> iterator() {
return new PagedGridTRElementIterator(grid);
}
};
}
@Override
public boolean hasNext() {
return nextRowToBeReturned < rows;
}
@Override
public GridTRElement next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
if (rowsToBeReturned.isEmpty()) {
grid.scrollToRow(nextRowToBeReturned);
int firstVisibleRowIndex = grid.getFirstVisibleRowIndex();
final int lastVisibleRowIndex = grid.getLastVisibleRowIndex();
if (nextRowToBeReturned < firstVisibleRowIndex || nextRowToBeReturned > lastVisibleRowIndex) {
throw new IllegalStateException("Invalid state: the grid scrolled unexpectedly: expected " + nextRowToBeReturned + " but got " + firstVisibleRowIndex + ".." + lastVisibleRowIndex);
}
firstVisibleRowIndex = nextRowToBeReturned;
rowsToBeReturned = grid.getRows(firstVisibleRowIndex, lastVisibleRowIndex);
if (rowsToBeReturned.isEmpty()) {
throw new IllegalStateException("Invalid state: grid returned zero rows");
}
}
final GridTRElement result = rowsToBeReturned.get(0);
Objects.requireNonNull(result);
rowsToBeReturned.remove(0);
nextRowToBeReturned++;
return result;
}
} Let me try to prototype an interator which uses these ideas and the solution mentioned by Tatu above. |
Feature request: I need to test whether the Grid is showing correct data, and for that I need to capture the contents which the Grid is showing, and compare the result against the expected Grid contents, which is just a two-dimensional array of Strings.
Currently what I can do is to call
GridElement.getRows()
, then grab all cells for each row, then callGridTHTDElement.getText()
. However this generates one browser request per every cell, which is hopelessly slow.It would be great if
GridElement
offered a faster way to dump the cells into a 2-dimensional array of Strings: perhaps by dumping/calling the DataProvider directly, or by capturing currently shown data from its HTML structure - can be done page-by-page way.We need this for Vaadin 23/TestBench 23 please.
The text was updated successfully, but these errors were encountered: