aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxNullValueTest.java
blob: 12ed650c19ede1c6502aa425cfe5950ac7f22c66 (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.components.checkbox;

import java.util.List;

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

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

public class CheckBoxNullValueTest extends MultiBrowserTest {
    @Test
    public void testValidation() throws Exception {
        openTestURL();
        CheckBoxElement checkbox = $(CheckBoxElement.class).first();
        CheckBoxElement requiredCheckbox = $(CheckBoxElement.class).caption(
                "A required checkbox").first();

        assertValid(checkbox, true);
        assertValid(requiredCheckbox, true);
        ButtonElement validate = $(ButtonElement.class).caption("Validate")
                .first();
        validate.click();

        assertValid(checkbox, true);
        assertValid(requiredCheckbox, false);

        click(checkbox);
        click(requiredCheckbox);
        validate.click();

        assertValid(checkbox, true);
        assertValid(requiredCheckbox, true);

        click(checkbox);
        click(requiredCheckbox);
        validate.click();
        assertValid(checkbox, true);
        assertValid(requiredCheckbox, false);

    }

    private void assertValid(CheckBoxElement checkbox, boolean valid) {
        boolean hasIndicator = false;
        List<WebElement> e = checkbox.findElements(By
                .className("v-errorindicator"));
        if (e.size() != 0) {
            hasIndicator = e.get(0).isDisplayed();
        }

        Assert.assertEquals("Checkbox state should be "
                + (valid ? "valid" : "invalid"), valid, !hasIndicator);

    }

}