aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/textfield/TextFieldsValueChangeModeTest.java
blob: 887c675b69796d9d067be1dc485bdc23a00eec5d (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
package com.vaadin.tests.components.textfield;

import static org.junit.Assert.assertEquals;

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

import com.vaadin.tests.tb3.MultiBrowserTest;

public class TextFieldsValueChangeModeTest extends MultiBrowserTest {

    @Test
    public void textFieldEager() {
        testEager("textfield-eager");
    }

    @Test
    public void textAreaEager() {
        testEager("textarea-eager");
    }

    @Test
    @Ignore("No support for typing in a RichTextArea in TestBench")
    public void richTextAreaEager() {
        testEager("richtextarea-eager");
    }

    @Test
    public void textFieldDefault() {
        testDefault("textfield-default");
    }

    @Test
    public void textAreaDefault() {
        testDefault("textarea-default");
    }

    @Test
    @Ignore("No support for typing in a RichTextArea in TestBench")
    public void richTextAreaDefault() {
        testEager("richtextarea-default");
    }

    @Test
    public void textFieldTimeout() {
        testTimeout("textfield-timeout");
    }

    @Test
    public void textAreaTimeout() {
        testTimeout("textarea-timeout");
    }

    @Test
    @Ignore("No support for typing in a RichTextArea in TestBench")
    public void richTextAreaTimeout() {
        testEager("richtextarea-timeout");
    }

    private void testEager(String id) {
        openTestURL();
        WebElement eagerTextField = findElement(By.id(id));
        eagerTextField.sendKeys("f");
        eagerTextField.sendKeys("o");
        eagerTextField.sendKeys("o");
        assertLog(id, "f", "fo", "foo");
    }

    private void testDefault(String id) {
        openTestURL();
        WebElement eagerTextField = findElement(By.id(id));
        eagerTextField.sendKeys("f");
        eagerTextField.sendKeys("o");
        eagerTextField.sendKeys("o");
        sleep(400); // Default timeout is 400ms
        assertLog(id, "foo");

    }

    private void testTimeout(String id) {
        openTestURL();
        WebElement eagerTextField = findElement(By.id(id));
        eagerTextField.sendKeys("foo");
        sleep(1000); // Timer set to 1000ms
        eagerTextField.sendKeys("baa");
        sleep(1000); // Timer set to 1000ms
        assertLog(id, "foo", "foobaa");
    }

    private void assertLog(String id, String... messages) {
        for (int i = 0; i < messages.length; i++) {
            String expected = "Value change event for " + id + ", new value: '"
                    + messages[i] + "'";

            String log = getLogRow(messages.length - 1 - i);
            int tail = log.indexOf(" Cursor at");
            if (tail != -1) {
                log = log.substring(0, tail);
            }
            assertEquals(expected, log);
        }

    }
}