aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/window/WindowCaptionTest.java
blob: 1077ce2b64e0c8ac69f50bc5354dedf790454adc (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.vaadin.tests.components.window;

import static org.junit.Assert.assertEquals;

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

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.WindowElement;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class WindowCaptionTest extends SingleBrowserTest {

    private WindowElement htmlWindow;
    private WindowElement textWindow;

    @Override
    public void setup() throws Exception {
        super.setup();
        openTestURL();
        waitForElementPresent(By.className("v-window"));
        htmlWindow = $(WindowElement.class).id("htmlWindow");
        textWindow = $(WindowElement.class).id("textWindow");
    }

    @Test
    public void htmlCaption() {
        assertEquals("HtmlWindow's caption didn't match,",
                "This may or may not be red", htmlWindow.getCaption());
        assertEquals("TextWindow's caption didn't match,",
                "<font style='color: red;'>This may or may not be red</font>",
                textWindow.getCaption());
    }

    @Test
    public void textCaption() {
        clickButton("Plain text");
        ensureCaptionsEqual("This is just text");
    }

    @Test
    public void nullCaption() {
        clickButton("Null");
        ensureCaptionsEqual("");
    }

    @Test
    public void emptyCaption() {
        clickButton("Empty");
        ensureCaptionsEqual("");
    }

    private void clickButton(String caption) {
        $(ButtonElement.class).caption(caption).first().click();
    }

    private void ensureCaptionsEqual(final String expectedCaption) {
        waitUntil(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver input) {
                return expectedCaption.equals(htmlWindow.getCaption());
            }

            @Override
            public String toString() {
                // Timed out after 10 seconds waiting for ...
                return "htmlWindow's caption to be '" + expectedCaption
                        + "' (was: '" + htmlWindow.getCaption() + "')";
            }

        });

        assertEquals("TextWindow's caption didn't match,", expectedCaption,
                textWindow.getCaption());
    }
}