]> source.dussan.org Git - vaadin-framework.git/blob
fe06f4f32987e40af6ab5d177497ac2b37d545b0
[vaadin-framework.git] /
1 package com.vaadin.tests.components.combobox;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.collection.IsEmptyCollection.empty;
5
6 import java.util.List;
7
8 import org.junit.Test;
9 import org.openqa.selenium.Keys;
10 import org.openqa.selenium.WebElement;
11
12 import com.vaadin.testbench.By;
13 import com.vaadin.tests.tb3.SingleBrowserTestPhantomJS2;
14 import com.vaadin.v7.testbench.customelements.ComboBoxElement;
15
16 public class ComboBoxEmptyItemsKeyboardNavigationTest
17         extends SingleBrowserTestPhantomJS2 {
18
19     @Test
20     public void navigatingUpOnAnEmptyMenuDoesntThrowErrors() {
21         setDebug(true);
22         openTestURL();
23
24         ComboBoxElement combobox = $(ComboBoxElement.class).first();
25         combobox.sendKeys("a", Keys.ARROW_UP);
26
27         List<WebElement> errors = findElements(By.className("SEVERE"));
28
29         assertThat(errors, empty());
30     }
31
32     @Test
33     public void selectingUsingEnterInAnEmptyMenu() {
34         setDebug(true);
35         openTestURL();
36
37         ComboBoxElement combobox = $(ComboBoxElement.class).first();
38         combobox.sendKeys("a", Keys.ENTER);
39
40         List<WebElement> errors = findElements(By.className("SEVERE"));
41
42         assertThat(errors, empty());
43
44         assertPopupClosed(combobox);
45     }
46
47     @Test
48     public void selectingUsingTabInAnEmptyMenu() {
49         setDebug(true);
50         openTestURL();
51
52         ComboBoxElement combobox = $(ComboBoxElement.class).first();
53         // The joy of testing, one tab should be enough but is not (it is
54         // locally), two tabs does the trick for PhantomJS on the cluster...
55         combobox.sendKeys("abc", Keys.TAB, Keys.TAB);
56
57         List<WebElement> errors = findElements(By.className("SEVERE"));
58
59         assertThat(errors, empty());
60         assertPopupClosed(combobox);
61     }
62
63     private void assertPopupClosed(ComboBoxElement combobox) {
64         org.openqa.selenium.By bySuggestionPopup = By.vaadin("#popup");
65
66         assertThat("ComboBox popup should not be open",
67                 combobox.findElements(bySuggestionPopup).isEmpty());
68
69     }
70 }