aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxPasteWithDisabledTest.java
blob: 10d0db5d3d130fe98a9a13961dc5a5fd9a82ca4d (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
package com.vaadin.tests.components.combobox;

import static org.junit.Assert.assertFalse;

import org.junit.Test;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;

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

public class ComboBoxPasteWithDisabledTest extends MultiBrowserTest {

    @Test
    public void pasteWithDisabled() throws InterruptedException {
        openTestURL();
        ComboBoxElement cb = $(ComboBoxElement.class).first();

        cb.click();

        WebElement input = cb.getInputField();
        JavascriptExecutor js = (JavascriptExecutor) getDriver();

        // .sendKeys() doesn't allow sending to a disabled element
        js.executeScript("arguments[0].removeAttribute('disabled')", input);

        String os = System.getProperty("os.name").toLowerCase();
        String paste;
        if (os.contains("windows")) {
            paste = Keys.chord(Keys.CONTROL, "v");
        } else if (os.contains("linux")) {
            paste = Keys.chord(Keys.CONTROL, Keys.SHIFT, "v");
        } else {
            // mac
            paste = Keys.chord(Keys.COMMAND, "v");
        }

        input.sendKeys(paste);

        assertFalse(cb.isPopupOpen());
    }

}