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 org.junit.Assert.assertEquals;
20 import java.util.List;
22 import org.junit.Test;
23 import org.openqa.selenium.WebElement;
25 import com.vaadin.testbench.By;
26 import com.vaadin.tests.tb3.MultiBrowserTest;
27 import com.vaadin.v7.testbench.customelements.TableElement;
30 * Test for a Table with a customised BeanItemContainer.
34 public class TableWithContainerRequiringEqualsForItemIdTest
35 extends MultiBrowserTest {
38 public void testSorting() {
41 TableElement table = $(TableElement.class).first();
42 List<WebElement> rows = table.findElement(By.className("v-table-body"))
43 .findElements(By.tagName("tr"));
44 assertEquals("unexpect amount of rows", 46, rows.size());
46 // click the button on the first visible row
47 clickButton(table, 0, 3, "1. Button Button999 clicked");
49 // click the button on the last visible row
50 clickButton(table, 14, 3, "2. Button Button985 clicked");
52 clickTableHeaderToSort(table);
54 // check the first cell of the new first visible row
55 checkFirstCell(table, "0");
57 // click the button on the first visible row
58 clickButton(table, 0, 3, "3. Button Button0 clicked");
60 // sort by the first column (descending)
61 clickTableHeaderToSort(table);
63 // check the first cell of the new first visible row
64 checkFirstCell(table, "999");
66 // click the button on the first visible row
67 clickButton(table, 0, 3, "4. Button Button999 clicked");
70 private void checkFirstCell(TableElement table, String expected) {
71 assertEquals("unexpected contents", expected,
72 table.getCell(0, 0).getText());
75 private void clickTableHeaderToSort(TableElement table) {
76 table.findElement(By.className("v-table-header"))
77 .findElement(By.tagName("tr"))
78 .findElement(By.className("v-table-caption-container")).click();
81 private void clickButton(TableElement table, int row, int column,
83 table.getCell(row, column).findElement(By.className("v-button"))
86 // check the new log row
87 assertEquals("unexpected log row", expectedLog,
88 findElement(By.id("Log_row_0")).getText());