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.grid.basicfeatures.client;
18 import static org.junit.Assert.assertEquals;
20 import org.openqa.selenium.By;
21 import org.openqa.selenium.WebElement;
23 import com.vaadin.testbench.TestBenchElement;
24 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
25 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
28 * Abstract base class for header and footer tests.
33 public abstract class GridStaticSectionTest
34 extends GridBasicClientFeaturesTest {
36 protected void assertHeaderTexts(int headerId, int rowIndex) {
38 for (TestBenchElement cell : getGridElement()
39 .getHeaderCells(rowIndex)) {
40 WebElement content = cell.findElement(By.tagName("div"));
43 assertText(String.format("Header (%d,%d)", headerId, i),
45 } else if (i % 2 == 0) {
46 assertHTML(String.format("<b>Header (%d,%d)</b>", headerId, i),
49 assertHTML(String.format(
50 "<div class=\"gwt-HTML\">Header (%d,%d)</div>",
51 headerId, i), content);
56 assertEquals("number of header columns", GridBasicFeatures.COLUMNS, i);
59 protected void assertFooterTexts(int footerId, int rowIndex) {
61 for (TestBenchElement cell : getGridElement()
62 .getFooterCells(rowIndex)) {
63 WebElement content = cell.findElement(By.tagName("div"));
66 assertText(String.format("Footer (%d,%d)", footerId, i),
68 } else if (i % 2 == 0) {
69 assertHTML(String.format("<b>Footer (%d,%d)</b>", footerId, i),
72 assertHTML(String.format(
73 "<div class=\"gwt-HTML\">Footer (%d,%d)</div>",
74 footerId, i), content);
78 assertEquals("number of footer columns", GridBasicFeatures.COLUMNS, i);
81 protected static void assertText(String text, WebElement e) {
82 // TBE.getText returns "" if the element is scrolled out of view
83 assertEquals(text, e.getAttribute("innerHTML"));
86 protected static void assertHTML(String text, WebElement e) {
87 String html = e.getAttribute("innerHTML");
89 // IE 8 returns tags as upper case while other browsers do not, make the
90 // comparison non-casesensive
91 html = html.toLowerCase();
92 text = text.toLowerCase();
94 // IE 8 returns attributes without quotes, make the comparison without
96 html = html.replaceAll("\"", "");
97 text = html.replaceAll("\"", "");
99 assertEquals(text, html);