diff options
Diffstat (limited to 'uitest/src')
11 files changed, 167 insertions, 776 deletions
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxIdenticalItemsTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxIdenticalItemsTest.java index 709d3d9a60..d2cb80ae67 100644 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxIdenticalItemsTest.java +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxIdenticalItemsTest.java @@ -15,70 +15,62 @@ */ package com.vaadin.tests.components.combobox; +import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.WebElement; import com.vaadin.testbench.By; -import com.vaadin.testbench.parallel.BrowserUtil; import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.tests.tb3.newelements.ComboBoxElement; /** - * Test for identical item captions in ComboBox. - * * @author Vaadin Ltd */ public class ComboBoxIdenticalItemsTest extends MultiBrowserTest { + private WebElement select; + + /* This test has been directly ported from a TB2 test */ @Test - public void identicalItemsKeyboardTest() { + public void identicalItemsKeyboardTest() throws Exception { openTestURL(); - int delay = BrowserUtil.isPhantomJS(getDesiredCapabilities()) ? 500 : 0; - ComboBoxElement combobox = $(ComboBoxElement.class).first(); + // wait for the UI to be fully loaded + waitForElementVisible(By.className("v-filterselect")); + waitForElementVisible(By.id("Log")); - combobox.sendKeys(delay, Keys.ARROW_DOWN, getReturn()); - waitUntilLogText("1. Item one-1 selected"); + select = findElement(By + .vaadin("/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VFilterSelect[0]/domChild[0]")); + select.click(); Keys[] downDownEnter = new Keys[] { Keys.ARROW_DOWN, Keys.ARROW_DOWN, - getReturn() }; + Keys.ENTER }; + sendKeys(downDownEnter); + assertLogText("1. Item one-1 selected"); - combobox.sendKeys(delay, downDownEnter); - waitUntilLogText("2. Item one-2 selected"); + sendKeys(downDownEnter); + assertLogText("2. Item one-2 selected"); - combobox.sendKeys(delay, downDownEnter); - waitUntilLogText("3. Item two selected"); + sendKeys(downDownEnter); + assertLogText("3. Item two selected"); - combobox.sendKeys(delay, new Keys[] { Keys.ARROW_UP, Keys.ARROW_UP, - Keys.ARROW_UP, getReturn() }); - waitUntilLogText("4. Item one-1 selected"); + sendKeys(new Keys[] { Keys.ARROW_UP, Keys.ARROW_UP, Keys.ARROW_UP, + Keys.ENTER }); + assertLogText("4. Item one-1 selected"); } - private Keys getReturn() { - if (BrowserUtil.isPhantomJS(getDesiredCapabilities())) { - return Keys.ENTER; - } - return Keys.RETURN; + private void assertLogText(String expected) throws Exception { + String text = findElement(By.vaadin("PID_SLog_row_0")).getText(); + Assert.assertTrue("Expected '" + expected + "' found '" + text + "'", + text.equals(expected)); } - private void waitUntilLogText(final String expected) { - waitUntil(new ExpectedCondition<Boolean>() { - private String text; - - @Override - public Boolean apply(WebDriver input) { - text = findElement(By.vaadin("PID_SLog_row_0")).getText(); - return text.equals(expected); - } - - @Override - public String toString() { - return String.format( - "log content to update. Expected: '%s' (was: '%s')", - expected, text); - } - }); + private void sendKeys(Keys[] keys) throws Exception { + for (Keys key : keys) { + select.sendKeys(key); + // wait a while between the key presses, at least PhantomJS fails if + // they are sent too fast + sleep(10); + } } } diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValue.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValue.java index 7196547861..b6b284c5c5 100644 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValue.java +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValue.java @@ -12,8 +12,8 @@ import com.vaadin.ui.VerticalLayout; public class ComboBoxResetValue extends AbstractTestUI { protected static final String EMPTY_VALUE = "Empty value"; - protected static final String WITH_SET_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithSetNullSelectionItemId"; - protected static final String WITHOUT_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithoutNullSelectionItemId"; + protected static final String NULL_SELECTION_ALLOWED_WITH_SET_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithSetNullSelectionItemId"; + protected static final String NULL_SELECTION_ALLOWED_WITHOUT_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithoutNullSelectionItemId"; protected static final String NULL_SELECTION_NOT_ALLOWED = "nullSelectionNotAllowed"; @Override @@ -40,7 +40,7 @@ public class ComboBoxResetValue extends AbstractTestUI { protected ComboBox getComboBoxWithNullSelectionAllowedWithSetNullSelectionItemId() { ComboBox cb = new ComboBox(); - cb.setId(WITH_SET_NULL_SELECTION_ITEM_ID); + cb.setId(NULL_SELECTION_ALLOWED_WITH_SET_NULL_SELECTION_ITEM_ID); cb.setImmediate(true); cb.setNullSelectionAllowed(true); @@ -54,7 +54,7 @@ public class ComboBoxResetValue extends AbstractTestUI { protected ComboBox getComboBoxWithNullSelectionAllowedWithoutNullSelectionItemId() { ComboBox cb = new ComboBox(); - cb.setId(WITHOUT_NULL_SELECTION_ITEM_ID); + cb.setId(NULL_SELECTION_ALLOWED_WITHOUT_NULL_SELECTION_ITEM_ID); cb.setImmediate(true); cb.setNullSelectionAllowed(true); diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValueTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValueTest.java index 0295f4ba41..3021cb6e1a 100644 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValueTest.java +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValueTest.java @@ -15,96 +15,152 @@ */ package com.vaadin.tests.components.combobox; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; import org.junit.Test; import org.openqa.selenium.Keys; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import com.vaadin.testbench.By; import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.ComboBoxElement; import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.tests.tb3.newelements.ComboBoxElement; public class ComboBoxResetValueTest extends MultiBrowserTest { - private ComboBoxElement comboBoxWithNullSelectionItemId; - private ComboBoxElement comboBoxWithoutNullSelectionItemId; - private ComboBoxElement comboBoxWithNullNotAllowed; - - @Override - public void setup() throws Exception { - super.setup(); + static final String FILTER_STRING = "filter"; + @Test + public void testNullSelectionAllowedAndSetNullSelectionItemId() { openTestURL(); - comboBoxWithNullSelectionItemId = $(ComboBoxElement.class).id( - ComboBoxResetValue.WITH_SET_NULL_SELECTION_ITEM_ID); - - comboBoxWithoutNullSelectionItemId = $(ComboBoxElement.class).id( - ComboBoxResetValue.WITHOUT_NULL_SELECTION_ITEM_ID); - - comboBoxWithNullNotAllowed = $(ComboBoxElement.class).id( - ComboBoxResetValue.NULL_SELECTION_NOT_ALLOWED); - + ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class) + .id(ComboBoxResetValue.NULL_SELECTION_ALLOWED_WITH_SET_NULL_SELECTION_ITEM_ID); clickResetButton(); - } - @Test - public void testNullSelectionAllowedAndSetNullSelectionItemId() { - comboBoxWithNullSelectionItemId.openPopup(); + openPopup(comboBoxWebElement); - assertThatNullSelectionItemSelected(comboBoxWithNullSelectionItemId); + assertEquals("There should be selected: " + + ComboBoxResetValue.EMPTY_VALUE, + ComboBoxResetValue.EMPTY_VALUE, getSelectedInPopupValue()); } @Test public void testFilterNullSelectionAllowedAndSetNullSelectionItemId() { - comboBoxWithNullSelectionItemId.sendKeys("foo", Keys.TAB); + openTestURL(); - assertThatNullSelectionItemSelected(comboBoxWithNullSelectionItemId); + ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class) + .id(ComboBoxResetValue.NULL_SELECTION_ALLOWED_WITH_SET_NULL_SELECTION_ITEM_ID); + clickResetButton(); + printFilterAndRemoveIt(getComboBoxInput(comboBoxWebElement)); + + assertEquals("There should be " + ComboBoxResetValue.EMPTY_VALUE, + ComboBoxResetValue.EMPTY_VALUE, + getComboBoxValue(comboBoxWebElement)); } @Test public void testNullSelectionAllowedWithoutNullSelectionItemId() { - comboBoxWithoutNullSelectionItemId.openPopup(); + openTestURL(); - assertThatSelectionIsEmpty(comboBoxWithoutNullSelectionItemId); + ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class) + .id(ComboBoxResetValue.NULL_SELECTION_ALLOWED_WITHOUT_NULL_SELECTION_ITEM_ID); + clickResetButton(); + + openPopup(comboBoxWebElement); + + // not sure about expected result here.. Should be first empty string + // selected or not after reseting.. + assertEquals("There should be no selection", null, + getSelectedInPopupValue()); } @Test public void testFilterNullSelectionAllowedWithoutNullSelectionItemId() { - comboBoxWithoutNullSelectionItemId.sendKeys("foo", Keys.TAB); + openTestURL(); - assertThatSelectionIsEmpty(comboBoxWithoutNullSelectionItemId); + ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class) + .id(ComboBoxResetValue.NULL_SELECTION_ALLOWED_WITHOUT_NULL_SELECTION_ITEM_ID); + clickResetButton(); + printFilterAndRemoveIt(getComboBoxInput(comboBoxWebElement)); + + assertEquals("There should be empty value", "", + getComboBoxValue(comboBoxWebElement)); } @Test public void testNullSelectionNotAllowed() { - comboBoxWithNullNotAllowed.openPopup(); + openTestURL(); - assertThatSelectionIsEmpty(comboBoxWithNullNotAllowed); + ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class).id( + ComboBoxResetValue.NULL_SELECTION_NOT_ALLOWED); + clickResetButton(); + + openPopup(comboBoxWebElement); + + assertEquals("There should be no selection", null, + getSelectedInPopupValue()); } @Test public void testFilterNullSelectionNotAllowed() { - comboBoxWithNullNotAllowed.sendKeys("1", Keys.TAB); - comboBoxWithNullNotAllowed.sendKeys(Keys.BACK_SPACE, Keys.TAB); + openTestURL(); - assertThat("Selection changed when it shouldn't have.", - comboBoxWithNullNotAllowed.getText(), is("1")); + ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class).id( + ComboBoxResetValue.NULL_SELECTION_NOT_ALLOWED); + clickResetButton(); + printFilterAndRemoveIt(getComboBoxInput(comboBoxWebElement)); + + assertEquals("There should be empty value", "", + getComboBoxValue(comboBoxWebElement)); } - private void assertThatNullSelectionItemSelected(ComboBoxElement comboBox) { - assertThat("Null selection item not selected.", comboBox.getText(), - is(ComboBoxResetValue.EMPTY_VALUE)); + private void openPopup(ComboBoxElement comboBox) { + if (!isElementPresent(By.vaadin("#popup"))) { + comboBox.openPopup(); + } } - private void assertThatSelectionIsEmpty(ComboBoxElement comboBox) { - assertThat("Something selected when should be empty.", - comboBox.getText(), is("")); + private String getSelectedInPopupValue() { + try { + WebElement selectedSpan = driver.findElement(By + .cssSelector(".gwt-MenuItem-selected span")); + return selectedSpan.getText(); + } catch (NoSuchElementException e) { + return null; + } catch (WebDriverException e) { + if (e.getMessage() != null + && e.getMessage().contains("Unable to find element")) { + return null; + } + throw e; + } } private void clickResetButton() { ButtonElement resetButton = $(ButtonElement.class).first(); - resetButton.click(); + // workaround because of IE10 that doesn't always respond to click + resetButton.focus(); + resetButton.sendKeys(Keys.ENTER); + } + + private void printFilterAndRemoveIt(WebElement target) { + Actions actions = new Actions(getDriver()); + actions.click(target).perform(); + actions.sendKeys(Keys.chord(Keys.CONTROL, "a")).perform(); // Select all + actions.sendKeys(FILTER_STRING); + actions.sendKeys(Keys.ENTER).sendKeys(Keys.ESCAPE).sendKeys(Keys.TAB); // hack + actions.perform(); + } + + private String getComboBoxValue(ComboBoxElement comboBox) { + return getComboBoxInput(comboBox).getAttribute("value"); + } + + private WebElement getComboBoxInput(ComboBoxElement comboBox) { + return comboBox.findElement(By.tagName("input")); } } diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingWithArrowsTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingWithArrowsTest.java index a95301acc7..bc1fe39fe5 100644 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingWithArrowsTest.java +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxScrollingWithArrowsTest.java @@ -64,7 +64,8 @@ public class ComboBoxScrollingWithArrowsTest extends MultiBrowserTest { public void scrollDownArrowKeyTest() throws InterruptedException { WebElement dropDownComboBox = getDropDown(); - for (int i = 0; i < PAGESIZE; i++) { + // go to the last item and then one more + for (int i = 0; i < PAGESIZE + 1; i++) { dropDownComboBox.sendKeys(Keys.DOWN); } @@ -81,7 +82,8 @@ public class ComboBoxScrollingWithArrowsTest extends MultiBrowserTest { public void scrollUpArrowKeyTest() throws InterruptedException { WebElement dropDownComboBox = getDropDown(); - for (int i = 0; i < PAGESIZE; i++) { + // go to the last item and then one more + for (int i = 0; i < PAGESIZE + 1; i++) { dropDownComboBox.sendKeys(Keys.DOWN); } diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelecting.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelecting.java deleted file mode 100644 index 99f2254891..0000000000 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelecting.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.vaadin.tests.components.combobox; - -import com.vaadin.data.Property; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.ComboBox; -import com.vaadin.ui.Label; -import com.vaadin.ui.TextField; - -public class ComboBoxSelecting extends AbstractTestUI { - protected ComboBox comboBox; - - @Override - protected void setup(VaadinRequest request) { - comboBox = new ComboBox(); - final Label label = new Label(); - label.setId("value"); - - comboBox.setTextInputAllowed(true); - comboBox.setNullSelectionAllowed(true); - comboBox.setNullSelectionItemId(null); - - for (char c = 'a'; c <= 'z'; c++) { - for (int i = 0; i < 100; i++) { - comboBox.addItem("" + c + i); - } - } - - comboBox.addValueChangeListener(new Property.ValueChangeListener() { - @Override - public void valueChange(Property.ValueChangeEvent event) { - Object value = event.getProperty().getValue(); - if (value != null) { - label.setValue(value.toString()); - } else { - label.setValue("null"); - } - - } - }); - - // Had to add an extra text field for our old Firefox browsers, because - // tab will otherwise send the focus to address bar and FF 24 won't fire - // a key event properly. Nice! - addComponents(comboBox, label, new TextField()); - } - - @Override - protected String getTestDescription() { - return "Clearing the filter and hitting enter should select the null item"; - } - - @Override - protected Integer getTicketNumber() { - return 15502; - } -} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingTest.java deleted file mode 100644 index 0fad2c309b..0000000000 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingTest.java +++ /dev/null @@ -1,214 +0,0 @@ -package com.vaadin.tests.components.combobox; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.LabelElement; -import com.vaadin.testbench.parallel.BrowserUtil; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.tests.tb3.newelements.ComboBoxElement; - -public class ComboBoxSelectingTest extends MultiBrowserTest { - - private ComboBoxElement comboBoxElement; - - @Override - public void setup() throws Exception { - super.setup(); - - openTestURL(); - waitForElementPresent(By.className("v-filterselect")); - comboBoxElement = $(ComboBoxElement.class).first(); - } - - @Test - public void firstSuggestionIsSelectedWithEnter() { - typeInputAndHitEnter("a"); - - assertThatSelectedValueIs("a0"); - } - - @Test - public void firstSuggestionIsSelectedWithTab() { - typeInputAndHitTab("a"); - - assertThatSelectedValueIs("a0"); - } - - @Test - public void nullIsSelected() { - typeInputAndHitEnter("a"); - assertThatSelectedValueIs("a0"); - - clearInputAndHitEnter(); - - assertThatSelectedValueIs("", "null"); - } - - @Test - public void itemFromSecondPageIsSelected() { - typeInputAndHitEnter("a20"); - - assertThatSelectedValueIs("a20"); - } - - @Test - public void selectingNullFromSecondPage() { - typeInputAndHitEnter("a20"); - assertThatSelectedValueIs("a20"); - - clearInputAndHitEnter(); - assertThatSelectedValueIs("", "null"); - } - - @Test - public void selectionRemainsAfterOpeningPopup() { - typeInputAndHitEnter("a20"); - assertThatSelectedValueIs("a20"); - - openPopup(); - assertThatSelectedValueIs("a20"); - } - - @Test - public void noSelectionAfterMouseOut() { - typeInputAndHitEnter("a20"); - comboBoxElement.sendKeys(Keys.ARROW_DOWN, Keys.ARROW_DOWN); - - findElement(By.className("v-app")).click(); - - assertThatSelectedValueIs("a20"); - } - - @Test - public void cancelResetsSelection() { - sendKeysToInput("a20"); - cancelSelection(); - - assertThatSelectedValueIs(""); - } - - @Test - public void inputFieldResetsToSelectedText() { - typeInputAndHitEnter("z5"); - - sendKeysToInput(Keys.BACK_SPACE, Keys.BACK_SPACE); - cancelSelection(); - - assertThatSelectedValueIs("z5"); - } - - @Test - public void emptyValueIsSelectedWithTab() { - typeInputAndHitEnter("z5"); - - assertThatSelectedValueIs("z5"); - // longer delay for this one because otherwise it keeps failing when run - // on local machine - comboBoxElement.sendKeys(200, Keys.BACK_SPACE, Keys.BACK_SPACE, - Keys.TAB); - assertThatSelectedValueIs("", "null"); - - sendKeysToInput("z5"); - cancelSelection(); - assertThatSelectedValueIs("", "null"); - } - - @Test - public void arrowNavigatedValueIsSelectedWithEnter() { - sendKeysToInput("z"); - sendKeysToInput(Keys.DOWN, Keys.DOWN, getReturn()); - - assertThatSelectedValueIs("z2"); - } - - @Test - public void arrowNavigatedValueIsSelectedWithTab() { - sendKeysToInput("z"); - sendKeysToInput(Keys.DOWN, Keys.DOWN, Keys.TAB); - - assertThatSelectedValueIs("z2"); - } - - private void clearInputAndHitEnter() { - sendKeysToInput(Keys.BACK_SPACE, Keys.BACK_SPACE, Keys.BACK_SPACE); - sendKeysToInput(getReturn()); - } - - private void typeInputAndHitEnter(String input) { - clearInputAndType(input); - sendKeysToInput(getReturn()); - } - - private void typeInputAndHitTab(String input) { - clearInputAndType(input); - sendKeysToInput(Keys.TAB); - } - - private void clearInputAndType(String input) { - comboBoxElement.clear(); - sendKeysToInput(input); - } - - private void sendKeysToInput(CharSequence... keys) { - comboBoxElement.sendKeys(keys); - } - - private Keys getReturn() { - if (BrowserUtil.isPhantomJS(getDesiredCapabilities())) { - return Keys.ENTER; - } else { - return Keys.RETURN; - } - } - - private void openPopup() { - // Need to wait to make sure popup is closed first. - try { - Thread.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } - comboBoxElement.openPopup(); - } - - private void cancelSelection() { - if (BrowserUtil.isFirefox(getDesiredCapabilities())) { - findElement(By.className("v-app")).click(); - } else { - sendKeysToInput(Keys.ESCAPE); - } - } - - private void assertThatSelectedValueIs(final String value) { - assertThatSelectedValueIs(value, value); - } - - private void assertThatSelectedValueIs(final String value, - final String labelValue) { - assertThat(comboBoxElement.getText(), is(value)); - - waitUntil(new ExpectedCondition<Boolean>() { - private String actualValue; - - @Override - public Boolean apply(WebDriver input) { - actualValue = $(LabelElement.class).id("value").getText(); - return actualValue.equals(labelValue); - } - - @Override - public String toString() { - // Timed out after 10 seconds waiting for ... - return String.format("label value to match '%s' (was: '%s')", - labelValue, actualValue); - } - }); - } -} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowed.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowed.java deleted file mode 100644 index d941c153c3..0000000000 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowed.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.combobox; - -import com.vaadin.data.Property; -import com.vaadin.server.VaadinRequest; -import com.vaadin.ui.Label; - -public class ComboBoxSelectingWithNewItemsAllowed extends ComboBoxSelecting { - - @Override - protected void setup(VaadinRequest request) { - super.setup(request); - comboBox.setNewItemsAllowed(true); - - final Label label = new Label(String.valueOf(comboBox.getItemIds() - .size())); - label.setCaption("Item count:"); - label.setId("count"); - comboBox.addValueChangeListener(new Property.ValueChangeListener() { - - @Override - public void valueChange(Property.ValueChangeEvent event) { - label.setValue(String.valueOf(comboBox.getItemIds().size())); - } - }); - addComponent(label); - } - - @Override - protected String getTestDescription() { - return "ComboBox should select value on TAB also when new items are allowed."; - } - - @Override - protected Integer getTicketNumber() { - return 9369; - } -} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java deleted file mode 100644 index c0a67514bb..0000000000 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxSelectingWithNewItemsAllowedTest.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.combobox; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.LabelElement; -import com.vaadin.testbench.parallel.BrowserUtil; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.tests.tb3.newelements.ComboBoxElement; - -public class ComboBoxSelectingWithNewItemsAllowedTest extends MultiBrowserTest { - private ComboBoxElement comboBoxElement; - private LabelElement labelElement; - - @Override - public void setup() throws Exception { - super.setup(); - - openTestURL(); - waitForElementPresent(By.className("v-filterselect")); - comboBoxElement = $(ComboBoxElement.class).first(); - labelElement = $(LabelElement.class).id("count"); - } - - @Test - public void checkDefaults() { - assertInitialItemCount(); - } - - @Test - public void itemIsAddedWithEnter() { - typeInputAndHitEnter("a"); - - assertOneMoreThanInitial(); - assertThatSelectedValueIs("a"); - } - - @Test - public void itemIsAddedWithTab() { - typeInputAndHitTab("a"); - - assertOneMoreThanInitial(); - assertThatSelectedValueIs("a"); - } - - @Test - public void matchingSuggestionIsSelectedWithEnter() { - typeInputAndHitEnter("a0"); - - assertInitialItemCount(); - assertThatSelectedValueIs("a0"); - } - - @Test - public void matchingSuggestionIsSelectedWithTab() { - typeInputAndHitTab("a0"); - - assertInitialItemCount(); - assertThatSelectedValueIs("a0"); - } - - @Test - public void nullIsSelected() { - typeInputAndHitEnter("a"); - assertOneMoreThanInitial(); - assertThatSelectedValueIs("a"); - - clearInputAndHitEnter(); - - assertOneMoreThanInitial(); - assertThatSelectedValueIs("", "null"); - } - - @Test - public void itemFromSecondPageIsSelected() { - typeInputAndHitEnter("a20"); - - assertInitialItemCount(); - assertThatSelectedValueIs("a20"); - } - - @Test - public void selectingNullFromSecondPage() { - typeInputAndHitEnter("a20"); - assertInitialItemCount(); - assertThatSelectedValueIs("a20"); - - clearInputAndHitEnter(); - assertInitialItemCount(); - assertThatSelectedValueIs("", "null"); - } - - @Test - public void selectionRemainsAfterOpeningPopup() { - typeInputAndHitEnter("a20"); - assertInitialItemCount(); - assertThatSelectedValueIs("a20"); - - openPopup(); - assertThatSelectedValueIs("a20"); - } - - @Test - public void noSelectionAfterMouseOut() { - typeInputAndHitEnter("a20"); - comboBoxElement.sendKeys(Keys.ARROW_DOWN, Keys.ARROW_DOWN); - - findElement(By.className("v-app")).click(); - - assertInitialItemCount(); - assertThatSelectedValueIs("a20"); - } - - @Test - public void cancelResetsSelection() { - sendKeysToInput("a20"); - cancelSelection(); - - assertInitialItemCount(); - assertThatSelectedValueIs(""); - } - - @Test - public void inputFieldResetsToSelectedText() { - typeInputAndHitEnter("z5"); - - sendKeysToInput(Keys.BACK_SPACE, Keys.BACK_SPACE); - cancelSelection(); - - assertInitialItemCount(); - assertThatSelectedValueIs("z5"); - } - - @Test - public void emptyValueIsSelectedWithTab() { - typeInputAndHitEnter("z5"); - - assertInitialItemCount(); - assertThatSelectedValueIs("z5"); - // longer delay for this one because otherwise it keeps failing when run - // on local machine - comboBoxElement.sendKeys(200, Keys.BACK_SPACE, Keys.BACK_SPACE, - Keys.TAB); - assertInitialItemCount(); - assertThatSelectedValueIs("", "null"); - - sendKeysToInput("z5"); - cancelSelection(); - assertInitialItemCount(); - assertThatSelectedValueIs("", "null"); - } - - @Test - public void arrowNavigatedValueIsSelectedWithEnter() { - sendKeysToInput("z"); - sendKeysToInput(Keys.DOWN, Keys.DOWN, getReturn()); - - assertInitialItemCount(); - assertThatSelectedValueIs("z1"); - } - - @Test - public void arrowNavigatedValueIsSelectedWithTab() { - sendKeysToInput("z"); - sendKeysToInput(Keys.DOWN, Keys.DOWN, Keys.TAB); - - assertInitialItemCount(); - assertThatSelectedValueIs("z1"); - } - - private void clearInputAndHitEnter() { - sendKeysToInput(Keys.BACK_SPACE, Keys.BACK_SPACE, Keys.BACK_SPACE); - sendKeysToInput(getReturn()); - } - - private void typeInputAndHitEnter(String input) { - clearInputAndType(input); - sendKeysToInput(getReturn()); - } - - private void typeInputAndHitTab(String input) { - clearInputAndType(input); - sendKeysToInput(Keys.TAB); - } - - private void clearInputAndType(String input) { - comboBoxElement.clear(); - sendKeysToInput(input); - } - - private void sendKeysToInput(CharSequence... keys) { - comboBoxElement.sendKeys(keys); - } - - private Keys getReturn() { - if (BrowserUtil.isPhantomJS(getDesiredCapabilities())) { - return Keys.ENTER; - } else { - return Keys.RETURN; - } - } - - private void openPopup() { - // Need to wait to make sure popup is closed first. - try { - Thread.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } - comboBoxElement.openPopup(); - } - - private void cancelSelection() { - if (BrowserUtil.isFirefox(getDesiredCapabilities())) { - findElement(By.className("v-app")).click(); - } else { - sendKeysToInput(Keys.ESCAPE); - } - } - - private void assertThatSelectedValueIs(final String value) { - assertThatSelectedValueIs(value, value); - } - - private void assertThatSelectedValueIs(final String value, - final String labelValue) { - assertThat(comboBoxElement.getText(), is(value)); - - waitUntil(new ExpectedCondition<Boolean>() { - private String actualValue; - - @Override - public Boolean apply(WebDriver input) { - actualValue = $(LabelElement.class).id("value").getText(); - return actualValue.equals(labelValue); - } - - @Override - public String toString() { - // Timed out after 10 seconds waiting for ... - return String.format("label value to match '%s' (was: '%s')", - labelValue, actualValue); - } - }); - } - - private void assertInitialItemCount() { - // wait for a bit in case the count is updating - try { - sleep(1000); - } catch (InterruptedException ignore) { - } - assertThat("Wrong initial item count.", labelElement.getText(), - is("2600")); - } - - private void assertOneMoreThanInitial() { - waitUntil(new ExpectedCondition<Boolean>() { - @Override - public Boolean apply(WebDriver input) { - return "2601".equals(labelElement.getText()); - } - - @Override - public String toString() { - // Timed out after 10 seconds waiting for ... - return String.format("item count to become 2601 (was: %s)", - labelElement.getText()); - } - }); - } -} diff --git a/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindowTest.java b/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindowTest.java index a80938ba32..627efdc5b3 100644 --- a/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindowTest.java +++ b/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindowTest.java @@ -24,12 +24,10 @@ import org.openqa.selenium.WebElement; import com.vaadin.testbench.By; import com.vaadin.testbench.commands.TestBenchElementCommands; import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.tests.tb3.newelements.ComboBoxElement; -import com.vaadin.tests.tb3.newelements.WindowElement; /** - * Tests that a ComboBox at the bottom of a Window remains visible when clicked. * + * @since * @author Vaadin Ltd */ public class ComboboxScrollableWindowTest extends MultiBrowserTest { @@ -38,16 +36,20 @@ public class ComboboxScrollableWindowTest extends MultiBrowserTest { public void testWindowScrollbars() throws Exception { openTestURL(); - WindowElement window = $(WindowElement.class).id(WINDOW_ID); + WebElement window = driver.findElement(By.id(WINDOW_ID)); WebElement scrollableElement = window.findElement(By .className("v-scrollable")); TestBenchElementCommands scrollable = testBenchElement(scrollableElement); scrollable.scroll(1000); - ComboBoxElement comboBox = $(ComboBoxElement.class).id(COMBOBOX_ID); - comboBox.openPopup(); - waitForElementPresent(By.className("v-filterselect-suggestpopup")); + WebElement comboBox = driver.findElement(By.id(COMBOBOX_ID)); + WebElement selectButton = driver.findElement(By + .className("v-filterselect-button")); + selectButton.click(); + + // Wait for the browser before taking a screenshot + Thread.sleep(1000); + compareScreen(getScreenshotBaseName()); - compareScreen("combobox-open"); } } diff --git a/uitest/src/com/vaadin/tests/fonticon/FontIconsTest.java b/uitest/src/com/vaadin/tests/fonticon/FontIconsTest.java index 4cfcd8fa59..948c3c13b2 100644 --- a/uitest/src/com/vaadin/tests/fonticon/FontIconsTest.java +++ b/uitest/src/com/vaadin/tests/fonticon/FontIconsTest.java @@ -20,10 +20,11 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; 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; -import com.vaadin.tests.tb3.newelements.ComboBoxElement; public class FontIconsTest extends MultiBrowserTest { @@ -36,21 +37,29 @@ public class FontIconsTest extends MultiBrowserTest { @Test public void comboBoxItemIconsOnKeyboardNavigation() throws Exception { openTestURL(); - - ComboBoxElement comboBox = $(ComboBoxElement.class).first(); + WebElement comboBoxInput = getDriver().findElement( + By.className("v-filterselect-input")); // No initial value. - assertEquals("", comboBox.getText()); + assertEquals("", comboBoxInput.getText()); // Navigate to the first item with keyboard navigation. - comboBox.sendKeys(400, Keys.ARROW_DOWN, Keys.ARROW_DOWN); + sendKeys(comboBoxInput, Keys.ARROW_DOWN, Keys.ARROW_DOWN, + Keys.ARROW_DOWN); // Value must be "One" without any extra characters. // See ticket #14660 - assertEquals("One", comboBox.getText()); + assertEquals("One", comboBoxInput.getAttribute("value")); // Check also the second item. - comboBox.sendKeys(Keys.ARROW_DOWN); - assertEquals("Two", comboBox.getText()); + sendKeys(comboBoxInput, Keys.ARROW_DOWN); + assertEquals("Two", comboBoxInput.getAttribute("value")); + } + + private void sendKeys(WebElement element, Keys... keys) throws Exception { + for (Keys key : keys) { + element.sendKeys(key); + sleep(10); // For PhantomJS. + } } } diff --git a/uitest/src/com/vaadin/tests/tb3/newelements/ComboBoxElement.java b/uitest/src/com/vaadin/tests/tb3/newelements/ComboBoxElement.java deleted file mode 100644 index 6a0f164b13..0000000000 --- a/uitest/src/com/vaadin/tests/tb3/newelements/ComboBoxElement.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.vaadin.tests.tb3.newelements; - -import org.junit.Assert; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elementsbase.ServerClass; - -@ServerClass("com.vaadin.ui.ComboBox") -public class ComboBoxElement extends - com.vaadin.testbench.elements.ComboBoxElement { - - public WebElement getInputField() { - return findElement(By.vaadin("#textbox")); - } - - @Override - public String getText() { - return getInputField().getAttribute("value"); - } - - @Override - public void clear() { - getInputField().clear(); - } - - @Override - public void sendKeys(CharSequence... keysToSend) { - sendKeys(50, keysToSend); - } - - /** - * Use this method to simulate typing into an element, which may set its - * value. - * - * @param delay - * delay after sending each individual key (mainly needed for - * PhantomJS) - * @param keysToSend - * keys to type into the element - */ - public void sendKeys(int delay, CharSequence... keysToSend) { - WebElement input = getInputField(); - - for (CharSequence key : keysToSend) { - input.sendKeys(key); - try { - Thread.sleep(delay); - } catch (InterruptedException e) { - Assert.fail(e.getMessage()); - } - } - } -} |