aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/elements/combobox/SelectByTextTest.java
blob: 36820e27f28d8d2983da9cbe50ed2968787955b3 (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
package com.vaadin.tests.elements.combobox;

import static org.junit.Assert.assertEquals;

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

import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ComboBoxElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
 * Validates ComboBox.selectByText(String s) works properly if input String s
 * contains parentheses
 */
public class SelectByTextTest extends MultiBrowserTest {

    @Before
    public void init() {
        openTestURL();
    }

    private void selectAndAssertValue(String text) {
        ComboBoxElement comboBox = $(ComboBoxElement.class).first();
        comboBox.selectByText(text);

        assertEquals(text, getComboBoxValue());
        assertEquals("Value is now '" + text + "'",
                $(LabelElement.class).last().getText());
    }

    @Test
    public void selectByParenthesesOnly() {
        selectAndAssertValue("(");
    }

    @Test
    public void selectByStartingParentheses() {
        selectAndAssertValue("(Value");
    }

    @Test
    public void selectByFinishingParentheses() {
        selectAndAssertValue("Value(");
    }

    @Test
    public void selectByRegularParentheses() {
        selectAndAssertValue("Value(i)");
    }

    @Test
    public void selectByComplexParenthesesCase() {
        selectAndAssertValue(
                "((Test ) selectByTest() method(with' parentheses)((");
    }

    private String getComboBoxValue() {
        ComboBoxElement comboBox = $(ComboBoxElement.class).first();
        WebElement textbox = comboBox.findElement(By.vaadin("#textbox"));
        return textbox.getAttribute("value");
    }

    @Test
    public void selectSharedPrefixOption() {
        for (String text : new String[] { "Value 2", "Value 22",
                "Value 222" }) {
            selectAndAssertValue(text);
        }
    }

}