aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/fonticon/GridLayoutOnFontLoadTest.java
blob: edf3584ff443fb558a93514d92a9067687a8dea6 (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
56
57
58
59
package com.vaadin.tests.fonticon;

import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.CheckBoxElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.TextAreaElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class GridLayoutOnFontLoadTest extends MultiBrowserTest {

    ButtonElement button;
    CheckBoxElement checkbox;
    TextAreaElement textarea;
    GridElement grid;

    private ExpectedCondition<Boolean> checkNoOverlapping(String element1,
            int position1, String element2, int position2) {
        return new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver arg0) {
                return position1 <= position2;
            }

            @Override
            public String toString() {
                // waiting for ...
                return String
                        .format("the coordinates of the inspected elements ("
                                + element1 + ", " + element2
                                + ") to not overlap, the actual position for each "
                                + "element is " + position1 + ", "+ position2 + "respectively");
            }
        };
    }

    @Test
    public void testComponentsDontOverlap() throws Exception {
        openTestURL();
        // Make sure fonts are loaded.
        sleep(1000);

        button = $(ButtonElement.class).first();
        checkbox = $(CheckBoxElement.class).first();
        textarea = $(TextAreaElement.class).first();
        grid = $(GridElement.class).first();

        waitUntil(checkNoOverlapping("button",
                button.getLocation().getX() + button.getSize().width,
                "checkbox", checkbox.getLocation().getX()));
        waitUntil(checkNoOverlapping("textarea",
                textarea.getLocation().getY() + textarea.getSize().height + 10,
                "grid", grid.getLocation().getY()));
    }

}