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
|
package com.vaadin.tests.components.combobox;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.openqa.selenium.Keys;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ComboBoxElement;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
@TestCategory("xvfb-test")
public class ComboBoxItemIconTest extends MultiBrowserTest {
@Test
public void testIconsInComboBox() throws Exception {
openTestURL();
ComboBoxElement firstCombo = $(ComboBoxElement.class).first();
firstCombo.openPopup();
compareScreen(firstCombo.getSuggestionPopup(), "first-combobox-open");
// null item not on the list, so use index 1
firstCombo.selectByText(firstCombo.getPopupSuggestions().get(1));
compareScreen(firstCombo, "fi-hu-selected");
ComboBoxElement secondCombo = $(ComboBoxElement.class).get(1);
secondCombo.openPopup();
compareScreen(secondCombo.getSuggestionPopup(), "second-combobox-open");
secondCombo.selectByText(secondCombo.getPopupSuggestions().get(2));
compareScreen(secondCombo, "fi-au-selected");
ComboBoxElement thirdCombo = $(ComboBoxElement.class).get(2);
thirdCombo.openPopup();
compareScreen(thirdCombo.getSuggestionPopup(), "third-combobox-open");
thirdCombo.selectByText(thirdCombo.getPopupSuggestions().get(3));
compareScreen(thirdCombo, "classresource");
}
@Test
public void iconResetOnSelectionCancelByEscape() {
openTestURL();
ComboBoxElement cb = $(ComboBoxElement.class).get(1);
assertSelection(cb, "hu.gif", "Hungary");
cb.openPopup();
cb.sendKeys(Keys.UP);
assertSelection(cb, "au.gif", "Australia");
cb.sendKeys(Keys.ESCAPE);
assertSelection(cb, "hu.gif", "Hungary");
}
@Test
public void iconResetOnSelectionCancelByClickingOutside() {
openTestURL();
ComboBoxElement cb = $(ComboBoxElement.class).get(1);
assertSelection(cb, "hu.gif", "Hungary");
cb.openPopup();
cb.sendKeys(Keys.UP);
assertSelection(cb, "au.gif", "Australia");
findElement(By.tagName("body")).click();
assertSelection(cb, "hu.gif", "Hungary");
}
private void assertSelection(ComboBoxElement cb, String imageSuffix,
String caption) {
assertEquals(caption, cb.getValue());
String imgSrc = cb.findElement(By.className("v-icon"))
.getAttribute("src");
imgSrc = imgSrc.substring(imgSrc.lastIndexOf('/') + 1);
assertEquals(imageSuffix, imgSrc);
}
}
|