blob: 8a432962975a6016dc6c24080fd257600fc4b490 (
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
|
package com.vaadin.tests.components.window;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
/**
* Tests that a modal window is focused on creation and that on closing a window
* focus is given to underlying modal window
*
* @author Vaadin Ltd
*/
public class ModalWindowRefocusTest extends MultiBrowserTest {
@Override
protected Class<?> getUIClass() {
return ModalWindowFocus.class;
}
/**
* Open modal window -> click modality curtain to remove focus from Window
* -> press tab thrice so that focus goes into Window again and focuses the
* text field so that the focus event is fired.
*/
@Test
public void testFocusOutsideModal() {
openTestURL();
waitForElementPresent(By.id("modalWindowButton"));
WebElement button = findElement(By.id("modalWindowButton"));
button.click();
waitForElementPresent(By.id("focusfield"));
TextFieldElement tfe = $(TextFieldElement.class).id("focusfield");
assertFalse("First TextField should not have focus",
"this has been focused".equals(tfe.getValue()));
WebElement curtain = findElement(
org.openqa.selenium.By.className("v-window-modalitycurtain"));
testBenchElement(curtain).click(getXOffset(curtain, 20),
getYOffset(curtain, 20));
pressKeyAndWait(Keys.TAB);
pressKeyAndWait(Keys.TAB);
pressKeyAndWait(Keys.TAB);
assertTrue("First TextField should have received focus",
"this has been focused".equals(tfe.getValue()));
}
protected void pressKeyAndWait(Keys key) {
new Actions(driver).sendKeys(key).build().perform();
sleep(100);
}
}
|