blob: 4902a27deeec280235d26945a1ade651294394c2 (
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
package com.vaadin.tests.elements.menubar;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
public class MenuBarUITest extends MultiBrowserTest {
@Override
protected boolean requireWindowFocusForIE() {
return true;
}
@Before
public void init() {
openTestURL();
}
// Tests against bug #14568
@Test
public void testClickTopLevelItemHavingSubmenuItemFocused() {
MenuBarElement menuBar = $(MenuBarElement.class).first();
menuBar.clickItem("File");
waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Export.."));
menuBar.clickItem("Export..");
sleep(100);
assertTrue(isItemVisible("As PDF..."));
menuBar.clickItem("File");
sleep(100);
assertFalse(isItemVisible("Export.."));
}
/**
* Validates clickItem(String) of MenuBarElement.
*/
@Test
public void testMenuBarClick() {
MenuBarElement menuBar = $(MenuBarElement.class).first();
menuBar.clickItem("File");
waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Save As.."));
menuBar.clickItem("Export..");
sleep(100);
assertTrue(isItemVisible("As PDF..."));
// The Edit menu will be opened by moving the mouse over the item (done
// by clickItem). The first click then actually closes the menu.
menuBar.clickItem("Edit");
waitForElementNotPresent(By.className("v-menubar-popup"));
menuBar.clickItem("Edit");
waitForElementPresent(By.className("v-menubar-popup"));
assertFalse(isItemVisible("Save As.."));
assertTrue(isItemVisible("Paste"));
menuBar.clickItem("Edit");
sleep(100);
assertFalse(isItemVisible("Save As.."));
assertFalse(isItemVisible("Paste"));
menuBar.clickItem("Edit");
sleep(100);
assertFalse(isItemVisible("Save As.."));
assertTrue(isItemVisible("Paste"));
// Menu does not contain a submenu, no need to click twice.
menuBar.clickItem("Help");
sleep(100);
assertFalse(isItemVisible("Save As.."));
assertFalse(isItemVisible("Paste"));
// No submenu is open, so click only once to open the File menu.
menuBar.clickItem("File");
sleep(100);
assertTrue(isItemVisible("Save As.."));
}
/**
* Validates menuBar.clickItem(String...) feature.
*/
@Test
public void testMenuBarClickPath() {
MenuBarElement menuBar = $(MenuBarElement.class).first();
menuBar.clickItem("File", "Export..");
waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("As Doc..."));
}
/**
* Tests whether the selected MenuBar and its items are the correct ones.
*/
@Test
public void testMenuBarSelector() {
MenuBarElement menuBar = $(MenuBarElement.class).get(2);
menuBar.clickItem("File");
waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Open2"));
// Close the menu item
menuBar.clickItem("File");
waitForElementNotPresent(By.className("v-menubar-popup"));
menuBar = $(MenuBarElement.class).get(1);
menuBar.clickItem("Edit2");
waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Cut"));
menuBar.clickItem("Edit2");
waitForElementNotPresent(By.className("v-menubar-popup"));
menuBar = $(MenuBarElement.class).first();
menuBar.clickItem("File");
waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Open"));
}
@Test
public void testMenuItemTooltips() {
MenuBarElement first = $(MenuBarElement.class).first();
first.clickItem("File");
waitForElementPresent(By.className("v-menubar-popup"));
assertTooltip("Open", "<b>Preformatted</b>\ndescription");
assertTooltip("Save", "plain description, <b>HTML</b> is visible");
assertTooltip("Exit", "HTML\ndescription");
}
private void assertTooltip(String menuItem, String expectedTooltipText) {
testBenchElement(getMenuElement(menuItem)).showTooltip();
assertEquals("Unexpected tooltip when hovering '" + menuItem + "'",
expectedTooltipText,
findElement(By.className("v-tooltip-text")).getText());
}
private boolean isItemVisible(String item) {
for (WebElement webElement : getItemCaptions()) {
try {
if (webElement.getText().equals(item)) {
return true;
}
} catch (WebDriverException e) {
// stale, detached element is not visible
return false;
}
}
return false;
}
private List<WebElement> getItemCaptions() {
return findElements(By.className("v-menubar-menuitem-caption"));
}
}
|