2 * Copyright 2000-2016 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.tests.components.table;
18 import static com.vaadin.tests.components.table.ExpandingContainerVisibleRowRaceCondition.TABLE;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.fail;
23 import java.util.List;
25 import org.junit.Test;
26 import org.openqa.selenium.By;
27 import org.openqa.selenium.WebElement;
29 import com.vaadin.tests.tb3.MultiBrowserTest;
31 public class ExpandingContainerVisibleRowRaceConditionTest
32 extends MultiBrowserTest {
34 private static final int ROW_HEIGHT = 20;
37 public void testScrollingWorksWithoutJumpingWhenItemSetChangeOccurs() {
41 WebElement table = vaadinElementById(TABLE);
42 assertFirstRowIdIs("ROW #120");
44 testBenchElement(table.findElement(By.className("v-scrollable")))
45 .scroll(320 * ROW_HEIGHT);
48 assertRowIdIsInThePage("ROW #330");
49 assertScrollPositionIsNotVisible();
53 protected void sleep(int milliseconds) {
55 super.sleep(milliseconds);
56 } catch (InterruptedException e) {
61 private void assertFirstRowIdIs(String expected) {
62 List<WebElement> cellsOfFirstColumn = getCellsOfFirstColumn();
63 WebElement first = cellsOfFirstColumn.get(0);
64 assertEquals(expected, first.getText());
67 private void assertRowIdIsInThePage(String expected) {
68 List<WebElement> cellsOfFirstColumn = getCellsOfFirstColumn();
69 for (WebElement rowId : cellsOfFirstColumn) {
70 if (expected.equals(rowId.getText())) {
74 fail("Expected row was not found");
77 private void assertScrollPositionIsNotVisible() {
78 WebElement table = vaadinElementById(TABLE);
79 WebElement scrollPosition = table
80 .findElement(By.className("v-table-scrollposition"));
81 assertFalse(scrollPosition.isDisplayed());
84 private List<WebElement> getCellsOfFirstColumn() {
85 WebElement table = vaadinElementById(TABLE);
86 List<WebElement> firstCellOfRows = table
87 .findElements(By.cssSelector(".v-table-table tr > td"));
88 return firstCellOfRows;