aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupFocusBlurTest.java
blob: 142f029424000a88de10bf7d04f4336d0b580dc6 (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
package com.vaadin.tests.components.checkboxgroup;

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.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.vaadin.testbench.elements.CheckBoxGroupElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
 * @author Vaadin Ltd
 *
 */
public class CheckBoxGroupFocusBlurTest extends MultiBrowserTest {

    @Test
    public void focusBlurEvents() {
        openTestURL();

        List<WebElement> checkBoxes = $(CheckBoxGroupElement.class).first()
                .findElements(By.tagName("input"));
        $(CheckBoxGroupElement.class).first().selectByText("1");

        // Focus event is fired
        assertTrue(logContainsText("1. Focus Event"));

        $(CheckBoxGroupElement.class).first().selectByText("2");
        // click on the second checkbox doesn't fire anything
        assertFalse(logContainsText("2."));

        // move the cursor to the middle of the first element,
        // offset to the middle of the two and perform click
        new Actions(getDriver()).moveToElement(checkBoxes.get(0))
                .moveByOffset(0,
                        (checkBoxes.get(1).getLocation().y
                                - checkBoxes.get(0).getLocation().y) / 2)
                .click().build().perform();

        // no new events
        assertFalse(logContainsText("2."));

        // click to label of a checkbox
        $(CheckBoxGroupElement.class).first().findElements(By.tagName("label"))
                .get(2).click();
        // no new events
        assertFalse(logContainsText("2."));

        // click on log label => blur
        $(LabelElement.class).first().click();
        // blur event is fired
        assertTrue(logContainsText("2. Blur Event"));

        $(CheckBoxGroupElement.class).first().selectByText("4");
        // Focus event is fired
        assertTrue(logContainsText("3. Focus Event"));

        // move keyboard focus to the next checkbox
        checkBoxes.get(3).sendKeys(Keys.TAB);
        // no new events
        assertFalse(logContainsText("4."));

        // select the next checkbox
        checkBoxes.get(4).sendKeys(Keys.SPACE);
        // no new events
        assertFalse(logContainsText("4."));
    }

    @Override
    public List<DesiredCapabilities> getBrowsersToTest() {
        // Focus does not move when expected with Selenium/TB and Firefox 45
        return getBrowsersExcludingFirefox();
    }
}