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
|
package com.vaadin.tests.components.button;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
/**
* Test for availability (x,y) coordinates for button activated via keyboard.
*
* @author Vaadin Ltd
*/
public class ButtonKeyboardClickTest extends MultiBrowserTest {
@Test
public void testCoordinatesForClickedButtonViaSpace() {
openTestURL();
WebElement button = getDriver().findElement(By.className("v-button"));
button.sendKeys(Keys.SPACE);
checkCoordinates(button);
}
@Test
public void testCoordinatesForClickedButtonViaEnter() {
openTestURL();
WebElement button = getDriver().findElement(By.className("v-button"));
button.sendKeys(Keys.ENTER);
checkCoordinates(button);
}
private void checkCoordinates(WebElement button) {
int xRelative = getValue("xRelative");
assertTrue(
"X relative click coordinate is greater than middle of the button",
button.getSize().getWidth() / 2 >= xRelative - 1);
assertTrue(
"X relative click coordinate is lower than middle of the button",
button.getSize().getWidth() / 2 <= xRelative + 1);
int yRelative = getValue("yRelative");
assertTrue(
"Y relative click coordinate is greater than middle of the button",
button.getSize().getHeight() / 2 >= yRelative - 1);
assertTrue(
"Y relative click coordinate is lower than middle of the button",
button.getSize().getHeight() / 2 <= yRelative + 1);
assertTrue(
"Client X click cooridnate is lower than X button coordinate",
getValue("x") > button.getLocation().getX());
assertTrue(
"Client X click cooridnate is greater than right button "
+ "border coordinate",
getValue("x") < button.getLocation().getX()
+ button.getSize().getWidth());
assertTrue(
"Client Y click cooridnate is lower than Y button coordinate",
getValue("y") > button.getLocation().getY());
assertTrue(
"Client Y click cooridnate is greater than bottom button "
+ "border coordinate",
getValue("y") < button.getLocation().getY()
+ button.getSize().getHeight());
assertTrue(
"Client X click cooridnate is greater than X middle button "
+ "coordinate",
button.getLocation().getX()
+ button.getSize().getWidth() / 2 >= getValue("x") - 1);
assertTrue(
"Client Y click cooridnate is greater than Y middle button coordinate",
button.getLocation().getY()
+ button.getSize().getHeight() / 2 >= getValue("y")
- 1);
assertTrue(
"Client X click cooridnate is lower than X middle button "
+ "coordinate",
button.getLocation().getX()
+ button.getSize().getWidth() / 2 <= getValue("x") + 1);
assertTrue(
"Client Y click cooridnate is lower than Y middle button coordinate",
button.getLocation().getY()
+ button.getSize().getHeight() / 2 <= getValue("y")
+ 1);
}
private int getValue(String style) {
return Integer.parseInt(getDriver()
.findElement(By.className("v-label-" + style)).getText());
}
}
|