aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAriaTest.java
blob: 4ec1dc5c98c17541046f5b7ae8f1c2a0b0c458f7 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Copyright 2000-2014 Vaadin Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.vaadin.tests.components.window;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.CheckBoxElement;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.testbench.elements.WindowElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
 * Tests dialogs with WAI-ARIA.
 * 
 * @since
 * @author Vaadin Ltd
 */
public class ExtraWindowShownWaiAriaTest extends MultiBrowserTest {

    @Test
    public void testDialogs() throws InterruptedException {
        openTestURL();

        List<ButtonElement> buttons = $(ButtonElement.class).all();
        assertFalse(buttons.isEmpty());

        // open alert dialog
        ButtonElement button = buttons.get(0);
        button.click();

        // ensure dialog opened
        waitForElementPresent(By.className("v-window"));
        WindowElement window = $(WindowElement.class).first();

        // ensure correct attributes
        assertEquals("alertdialog", window.getAttribute("role"));

        WebElement header = window.findElement(By.className("v-window-header"));
        assertEquals(header.getAttribute("id"),
                window.getAttribute("aria-labelledby"));

        WebElement label = window.findElement(By.className("v-label"));
        assertEquals(label.getAttribute("id"),
                window.getAttribute("aria-describedby"));

        List<WebElement> wButtons = window.findElements(By
                .className("v-button"));
        assertEquals("button", wButtons.get(0).getAttribute("role"));
        assertEquals("button", wButtons.get(1).getAttribute("role"));

        // close dialog
        wButtons.get(0).click();

        // ensure dialog closed
        List<WindowElement> windows = $(WindowElement.class).all();
        assertTrue(windows.isEmpty());

        // check additional description (second checkbox on the page)
        List<CheckBoxElement> checkBoxes = $(CheckBoxElement.class).all();
        WebElement input = checkBoxes.get(1).findElement(By.tagName("input"));
        // ensure that not checked yet
        assertEquals(null, input.getAttribute("checked"));
        input.click();
        // ensure that checked now
        assertEquals("true", input.getAttribute("checked"));

        // open alert dialog
        button = $(ButtonElement.class).first();
        button.click();

        waitForElementPresent(By.className("v-window"));

        // ensure correct attributes
        window = $(WindowElement.class).first();
        List<WebElement> labels = window.findElements(By.className("v-label"));
        assertEquals(labels.get(0).getAttribute("id") + " "
                + labels.get(1).getAttribute("id"),
                window.getAttribute("aria-describedby"));

        // close dialog
        wButtons = window.findElements(By.className("v-button"));
        wButtons.get(0).click();

        // ensure dialog closed
        windows = $(WindowElement.class).all();
        assertTrue(windows.isEmpty());

        // add prefix and postfix
        List<TextFieldElement> textFields = $(TextFieldElement.class).all();
        textFields.get(0).sendKeys("Important");
        textFields.get(1).sendKeys(" - do ASAP");

        // open alert dialog
        button = $(ButtonElement.class).first();
        button.click();

        waitForElementPresent(By.className("v-window"));

        // ensure the assistive spans have been added to the header
        window = $(WindowElement.class).first();
        header = window.findElement(By.className("v-window-header"));
        List<WebElement> assistiveElements = header.findElements(By
                .className("v-assistive-device-only"));
        assertEquals("Important",
                assistiveElements.get(0).getAttribute("innerHTML"));
        assertEquals(" - do ASAP",
                assistiveElements.get(1).getAttribute("innerHTML"));
    }
}