aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWidthIncreaseTest.java
blob: 1bd13837f3e1418d1bacc9cf49fea686279ada70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.vaadin.v7.tests.components.grid;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.parallel.BrowserUtil;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;

@TestCategory("grid")
public class GridWidthIncreaseTest extends MultiBrowserTest {

    private static int INCREASE_COUNT = 3;

    @Test
    public void testColumnsExpandWithGrid() throws IOException {
        openTestURL();

        GridElement grid = $(GridElement.class).first();

        double accuracy = 1.0d;
        DesiredCapabilities cap = getDesiredCapabilities();
        if (BrowserUtil.isIE(cap, 8) || BrowserUtil.isIE(cap, 9)
                || BrowserUtil.isPhantomJS(cap)) {
            accuracy = 2.0d;
        }

        for (int i = 0; i < INCREASE_COUNT; ++i) {
            $(ButtonElement.class).first().click();
            int prevWidth = 0;
            for (int c = 0; c < GridWidthIncrease.COLUMN_COUNT; ++c) {
                int width = grid.getCell(0, c).getSize().getWidth();
                if (c > 0) {
                    // check that columns are roughly the same width.
                    assertEquals("Difference in column widths", prevWidth,
                            width, accuracy);
                }
                prevWidth = width;
            }
            /*
             * Column widths should be the same as table wrapper size. Since
             * Selenium doesn't support subpixels correctly, we use a rough
             * estimation.
             */
            assertEquals(grid.getRow(0).getSize().getWidth(),
                    grid.getTableWrapper().getSize().getWidth(), accuracy);
        }
    }
}