diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java index 6263ce5b0fe..788d4a917d7 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxElement.java @@ -67,6 +67,9 @@ public String getCaption() { @Override public void click() { + if (isReadOnly()) { + throw new ReadOnlyException(); + } WebElement input = getInputElement(); if (isFirefox()) { // When using Valo, the input element is covered by a diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java index ed657c085d9..ae6e65a62dd 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/CheckBoxGroupElement.java @@ -55,11 +55,12 @@ public void selectByText(String text) throws ReadOnlyException { } /** - * Return value of the selected option in the option group + * Return list of the selected options in the checkbox group * - * @return value of the selected option in the option group + * @return list of the selected options in the checkbox group */ - public String getValue() { + public List getSelection() { + List values = new ArrayList<>(); List options = findElements(bySelectOption); for (WebElement option : options) { WebElement checkedItem; @@ -67,14 +68,14 @@ public String getValue() { String checked = checkedItem.getAttribute("checked"); if (checked != null && checkedItem.getAttribute("checked").equals("true")) { - return option.findElement(By.tagName("label")).getText(); + values.add(option.findElement(By.tagName("label")).getText()); } } - return null; + return values; } /** - * Select option in the option group with the specified value + * Select option in the option group with the specified value. * * @param chars * value of the option in the option group which will be selected diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java index 980c4a1e7ff..dcd67253636 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/ComboBoxElement.java @@ -44,6 +44,10 @@ public class ComboBoxElement extends AbstractSelectElement { * the text of the option to select */ public void selectByText(String text) { + if (isReadOnly()) { + throw new ReadOnlyException(); + } + if (!isTextInputAllowed()) { selectByTextFromPopup(text); return; @@ -57,7 +61,7 @@ public void selectByText(String text) { /** * Selects, without filtering, the first option in the ComboBox which * matches the given text. - * + * * @param text * the text of the option to select */ @@ -96,7 +100,7 @@ private boolean isReadOnly(WebElement elem) { /** * Checks if text input is allowed for the combo box. - * + * * @return true if text input is allowed, false * otherwise */ diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java index 4ce4c9008f6..77660904f34 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/ListSelectElement.java @@ -40,7 +40,7 @@ protected void init() { } /** - * Selects the option(s) with the given text. + * Selects the option with the given text. *

* For a ListSelect in multi select mode, adds the given option(s) to the * current selection. @@ -49,6 +49,10 @@ protected void init() { * the text of the option */ public void selectByText(String text) { + if (isReadOnly()) { + throw new ReadOnlyException(); + } + select.selectByVisibleText(text); if (isPhantomJS() && select.isMultiple()) { // Phantom JS does not fire a change event when @@ -64,6 +68,9 @@ public void selectByText(String text) { * the text of the option */ public void deselectByText(String text) { + if (isReadOnly()) { + throw new ReadOnlyException(); + } select.deselectByVisibleText(text); if (isPhantomJS() && select.isMultiple()) { // Phantom JS does not fire a change event when diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java index 396a2435b33..5f20c0b9d28 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/SliderElement.java @@ -15,10 +15,7 @@ */ package com.vaadin.testbench.elements; -import java.util.List; - import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.BrowserType; import com.vaadin.testbench.By; import com.vaadin.testbench.elementsbase.ServerClass; @@ -27,27 +24,13 @@ public class SliderElement extends AbstractFieldElement { /** * Get value of the slider - * + * * Warning! This method cause slider popup to appear on the screen. To hide * this popup just focus any other element on the page. */ public String getValue() { - List popupElems = findElements(By.vaadin("#popup")); - // SubPartAware was implemented after 7.2.6, not sure in which release - // it will be included - if (popupElems.isEmpty()) { - throw new UnsupportedOperationException( - "Current version of vaadin doesn't support geting values from sliderElement"); - - } - WebElement popupElem = popupElems.get(0); - - if (BrowserType.IE.equals(getCapabilities().getBrowserName()) - && "8".equals(getCapabilities().getVersion())) { - return popupElem.getAttribute("innerText"); - } else { - return popupElem.getAttribute("textContent"); - } + WebElement popupElem = findElement(By.vaadin("#popup")); + return popupElem.getAttribute("textContent"); } diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java index c68ade8ff4c..7f3859c1462 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/TwinColSelectElement.java @@ -62,7 +62,17 @@ private void deselectAll() { } } + /** + * Deselects the option with the given option text, i.e. removes it from the + * right side column. + * + * @param text + * the text of the option to deselect + */ public void deselectByText(String text) { + if (isReadOnly()) { + throw new ReadOnlyException(); + } selectedOptions.deselectAll(); selectedOptions.selectByVisibleText(text); deselButton.click(); @@ -98,7 +108,18 @@ public List getAvailableOptions() { return getOptionsFromSelect(options); } + /** + * Selects the option with the given option text, i.e. adds it to the right + * side column. + * + * @param text + * the text of the option to select + */ public void selectByText(String text) { + if (isReadOnly()) { + throw new ReadOnlyException(); + } + options.deselectAll(); options.selectByVisibleText(text); selButton.click(); @@ -113,7 +134,9 @@ private List getOptionsFromSelect(Select select) { } /** - * Return first selected item (item in the right part of component) + * Return first selected item (item in the right part of component). + * + * @return the option text for the item */ public String getValue() { String value = ""; diff --git a/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityComponentElementGetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityComponentElementGetValue.java new file mode 100644 index 00000000000..a7f88057b9b --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityComponentElementGetValue.java @@ -0,0 +1,173 @@ +package com.vaadin.tests.elements; + +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.HashSet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.data.Property.ValueChangeEvent; +import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.ui.AbstractSelect; +import com.vaadin.v7.ui.AbstractTextField; +import com.vaadin.v7.ui.CheckBox; +import com.vaadin.v7.ui.ComboBox; +import com.vaadin.v7.ui.DateField; +import com.vaadin.v7.ui.Label; +import com.vaadin.v7.ui.ListSelect; +import com.vaadin.v7.ui.NativeSelect; +import com.vaadin.v7.ui.OptionGroup; +import com.vaadin.v7.ui.PasswordField; +import com.vaadin.v7.ui.Slider; +import com.vaadin.v7.ui.TextArea; +import com.vaadin.v7.ui.TextField; +import com.vaadin.v7.ui.TwinColSelect; + +/* + * 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. + */ + +/** + * UI test for getValue() method of components: TextField, TextArea, + * PasswordField, ComboBox, ListSelect, NativeSelect, OptionGroup, CheckBox, + * DateField, TwinColSelect + * + * @since + * @author Vaadin Ltd + */ +public class CompatibilityComponentElementGetValue extends AbstractTestUI { + + public static final String TEST_STRING_VALUE = "item 2"; + public static final int TEST_SLIDER_VALUE = 42; + public static final float TEST_FLOAT_VALUE = 0.42f; + public static final Date TEST_DATE_VALUE = Calendar.getInstance().getTime(); + DateField df; + final Label valueChangeLabel = new Label("Initial value"); + + // These constants are used to check that change value event was + // called + public static final String[] FIELD_VALUES = { "textFieldValueChange", + "textAreaValueChange", "passwordValueChange" }; + public static final String CHECKBOX_VALUE_CHANGE = "checkboxValueChange"; + public static final String DATEFIELD_VALUE_CHANGE = "dateFieldValueChange"; + public static final String TWINCOL_VALUE_CHANGE = "twinColValueChange"; + + @Override + protected void setup(VaadinRequest request) { + + AbstractTextField[] fieldComponents = { new TextField(), new TextArea(), + new PasswordField() + + }; + + AbstractSelect[] selectComponents = { new ComboBox(), new ListSelect(), + new NativeSelect(), new OptionGroup() }; + + for (AbstractSelect comp : selectComponents) { + comp.addItem("item 1"); + comp.addItem(TEST_STRING_VALUE); + comp.addItem("item 3"); + comp.setValue(TEST_STRING_VALUE); + addComponent(comp); + } + addComponent(createTwinColSelect()); + for (int i = 0; i < fieldComponents.length; i++) { + AbstractTextField field = fieldComponents[i]; + field.setValue(TEST_STRING_VALUE); + ValueChangeListener listener = new MyValueChangeListener( + FIELD_VALUES[i]); + field.addValueChangeListener(listener); + addComponent(field); + } + + addComponent(createCheckBox()); + addComponent(createSlider()); + addComponent(createDateField()); + valueChangeLabel.setId("valueChangeLabel"); + addComponent(valueChangeLabel); + } + + private DateField createDateField() { + DateField df = new DateField(); + df.setDateFormat("yyyy-MM-dd"); + df.setValue(TEST_DATE_VALUE); + df.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + valueChangeLabel.setValue(DATEFIELD_VALUE_CHANGE); + } + }); + return df; + } + + private Slider createSlider() { + Slider sl = new Slider(0, 100); + sl.setWidth("100px"); + sl.setValue(new Double(TEST_SLIDER_VALUE)); + return sl; + } + + private CheckBox createCheckBox() { + CheckBox cb = new CheckBox(); + cb.setValue(true); + cb.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + valueChangeLabel.setValue(CHECKBOX_VALUE_CHANGE); + } + }); + return cb; + } + + @Override + protected String getTestDescription() { + return "Field elements getValue() should return test value"; + } + + @Override + protected Integer getTicketNumber() { + return 13455; + } + + private TwinColSelect createTwinColSelect() { + TwinColSelect tab = new TwinColSelect(""); + tab.addItems("item 1", TEST_STRING_VALUE, "item 3", "item 4"); + // Preselect a few items by creating a set + tab.setValue(new HashSet(Arrays.asList(TEST_STRING_VALUE))); + tab.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + valueChangeLabel.setValue(TWINCOL_VALUE_CHANGE); + } + }); + + return tab; + } + + private class MyValueChangeListener implements ValueChangeListener { + String value; + + public MyValueChangeListener(String value) { + this.value = value; + } + + @Override + public void valueChange(ValueChangeEvent event) { + valueChangeLabel.setValue(""); + valueChangeLabel.setValue(value); + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBase.java b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBase.java new file mode 100644 index 00000000000..b0ccfb671e2 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBase.java @@ -0,0 +1,76 @@ +package com.vaadin.tests.elements; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractLayout; +import com.vaadin.ui.Component; +import com.vaadin.v7.ui.CheckBox; +import com.vaadin.v7.ui.ColorPicker; +import com.vaadin.v7.ui.ComboBox; +import com.vaadin.v7.ui.DateField; +import com.vaadin.v7.ui.ListSelect; +import com.vaadin.v7.ui.OptionGroup; +import com.vaadin.v7.ui.Table; +import com.vaadin.v7.ui.TextArea; +import com.vaadin.v7.ui.TextField; +import com.vaadin.v7.ui.Tree; +import com.vaadin.v7.ui.TreeTable; +import com.vaadin.v7.ui.TwinColSelect; + +/* + * 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. + */ + +/** + * + * Base testUI class for testing getCaption method. Captions of elements + * implemented differently in different layouts (FormLayout) This class adds all + * elements to the layout. The exact layout is created in a child class. + */ +@Widgetset("com.vaadin.v7.Vaadin7WidgetSet") +public abstract class CompatibilityElementComponentGetCaptionBase + extends AbstractTestUI { + // Specify exact type of Layout in a child class + AbstractLayout mainLayout = null; + // default captions for all elements + public static final String[] DEFAULT_CAPTIONS = { "Combobox", "table", + "treeTable", "tree", "TwinColSelect", "optionGroup", "ListSelect", + "ColorPicker", "CheckBox", "TextField", "TextArea", "DateField", }; + + @Override + protected void setup(VaadinRequest request) { + Component[] comps = { new ComboBox(), new Table(), new TreeTable(), + new Tree(), new TwinColSelect(), new OptionGroup(), + new ListSelect(), new ColorPicker(), new CheckBox(), + new TextField(), new TextArea(), new DateField(), }; + addComponent(mainLayout); + for (int i = 0; i < comps.length; i++) { + Component component = comps[i]; + component.setCaption(DEFAULT_CAPTIONS[i]); + mainLayout.addComponent(component); + } + } + + @Override + protected String getTestDescription() { + return "Test getCaption method for vaadin compatibility components"; + } + + @Override + protected Integer getTicketNumber() { + return 14453; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionCssLayout.java b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionCssLayout.java new file mode 100644 index 00000000000..31018b61eec --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionCssLayout.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.CssLayout; + +public class CompatibilityElementComponentGetCaptionCssLayout + extends CompatibilityElementComponentGetCaptionBase { + + public CompatibilityElementComponentGetCaptionCssLayout() { + mainLayout = new CssLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionFormLayout.java b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionFormLayout.java new file mode 100644 index 00000000000..953e9355545 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionFormLayout.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.FormLayout; + +public class CompatibilityElementComponentGetCaptionFormLayout + extends CompatibilityElementComponentGetCaptionBase { + + public CompatibilityElementComponentGetCaptionFormLayout() { + mainLayout = new FormLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionGridLayout.java b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionGridLayout.java new file mode 100644 index 00000000000..179f5fc3a58 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionGridLayout.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.GridLayout; + +public class CompatibilityElementComponentGetCaptionGridLayout + extends CompatibilityElementComponentGetCaptionBase { + + public CompatibilityElementComponentGetCaptionGridLayout() { + mainLayout = new GridLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionHorizontal.java b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionHorizontal.java new file mode 100644 index 00000000000..e980471959c --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionHorizontal.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.HorizontalLayout; + +public class CompatibilityElementComponentGetCaptionHorizontal extends + CompatibilityElementComponentGetCaptionBase { + + public CompatibilityElementComponentGetCaptionHorizontal() { + mainLayout = new HorizontalLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionVerticalLayout.java b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionVerticalLayout.java new file mode 100644 index 00000000000..0f4d797df39 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionVerticalLayout.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.VerticalLayout; + +public class CompatibilityElementComponentGetCaptionVerticalLayout + extends CompatibilityElementComponentGetCaptionBase { + + public CompatibilityElementComponentGetCaptionVerticalLayout() { + mainLayout = new VerticalLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ComponentElementGetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/ComponentElementGetValue.java new file mode 100644 index 00000000000..e039b461d98 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ComponentElementGetValue.java @@ -0,0 +1,179 @@ +package com.vaadin.tests.elements; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractTextField; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.CheckBoxGroup; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.DateField; +import com.vaadin.ui.Label; +import com.vaadin.ui.ListSelect; +import com.vaadin.ui.MultiSelect; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.PasswordField; +import com.vaadin.ui.RadioButtonGroup; +import com.vaadin.ui.Slider; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; +import com.vaadin.ui.TwinColSelect; + +/* + * 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. + */ + +/** + * UI test for getValue() method of components: TextField, TextArea, + * PasswordField, ComboBox, ListSelect, NativeSelect, OptionGroup, CheckBox, + * DateField, TwinColSelect + * + * @since + * @author Vaadin Ltd + */ +public class ComponentElementGetValue extends AbstractTestUI { + + public static final String TEST_STRING_VALUE = "item 2"; + public static final int TEST_SLIDER_VALUE = 42; + public static final float TEST_FLOAT_VALUE = 0.42f; + public static final LocalDate TEST_DATE_VALUE = LocalDate.now(); + DateField df; + final Label valueChangeLabel = new Label("Initial value"); + + // These constants are used to check that change value event was + // called + public static final String[] FIELD_VALUES = { "textFieldValueChange", + "textAreaValueChange", "passwordValueChange" }; + public static final String CHECKBOX_VALUE_CHANGE = "checkboxValueChange"; + public static final String DATEFIELD_VALUE_CHANGE = "dateFieldValueChange"; + public static final String MULTI_SELECT_VALUE_CHANGE = "multiSelectValueChange"; + + private List createTestItems() { + List options = new ArrayList(); + options.add("item 1"); + options.add(TEST_STRING_VALUE); + options.add("item 3"); + return options; + } + + private void addSingleSelectComponents() { + List options = new ArrayList(); + options.add("item 1"); + options.add(TEST_STRING_VALUE); + options.add("item 3"); + + ComboBox cb = new ComboBox<>("", options); + cb.setValue(TEST_STRING_VALUE); + addComponent(cb); + + NativeSelect nativeSelect = new NativeSelect<>("", options); + nativeSelect.setValue(TEST_STRING_VALUE); + addComponent(nativeSelect); + + RadioButtonGroup rbGroup = new RadioButtonGroup<>("", options); + rbGroup.setValue(TEST_STRING_VALUE); + addComponent(rbGroup); + } + + private List createData() { + List options = new ArrayList(); + options.add("item 1"); + options.add(TEST_STRING_VALUE); + options.add("item 3"); + options.add("item 4"); + return options; + } + + private void addMultiSelectComponents() { + + List> components = new ArrayList<>(); + components.add(new ListSelect("", createData())); + components.add(new CheckBoxGroup("", createData())); + components.add(new TwinColSelect("", createData())); + components.forEach(c -> { + c.select(TEST_STRING_VALUE); + c.addValueChangeListener(event -> { + valueChangeLabel.setValue(MULTI_SELECT_VALUE_CHANGE); + }); + addComponent((Component) c); + }); + } + + @Override + protected void setup(VaadinRequest request) { + + AbstractTextField[] fieldComponents = { new TextField(), new TextArea(), + new PasswordField() }; + addSingleSelectComponents(); + addMultiSelectComponents(); + + for (int i = 0; i < fieldComponents.length; i++) { + AbstractTextField field = fieldComponents[i]; + field.setValue(TEST_STRING_VALUE); + String value = FIELD_VALUES[i]; + field.addValueChangeListener(event -> { + valueChangeLabel.setValue(value); + }); + addComponent(field); + } + + addComponent(createCheckBox()); + addComponent(createSlider()); + addComponent(createDateField()); + valueChangeLabel.setId("valueChangeLabel"); + addComponent(valueChangeLabel); + } + + private DateField createDateField() { + DateField df = new DateField(); + df.setDateFormat("yyyy-MM-dd"); + df.setValue(TEST_DATE_VALUE); + df.addValueChangeListener(event -> { + valueChangeLabel.setValue(DATEFIELD_VALUE_CHANGE); + }); + return df; + } + + private Slider createSlider() { + Slider sl = new Slider(0, 100); + sl.setWidth("100px"); + sl.setValue(new Double(TEST_SLIDER_VALUE)); + return sl; + } + + private CheckBox createCheckBox() { + CheckBox cb = new CheckBox(); + cb.setValue(true); + cb.addValueChangeListener(event -> { + valueChangeLabel.setValue(CHECKBOX_VALUE_CHANGE); + }); + return cb; + } + + @Override + protected String getTestDescription() { + return "Field elements getValue() should return test value"; + } + + @Override + protected Integer getTicketNumber() { + return 13455; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionBase.java b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionBase.java new file mode 100644 index 00000000000..5f08c23d135 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionBase.java @@ -0,0 +1,95 @@ +package com.vaadin.tests.elements; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractLayout; +import com.vaadin.ui.Accordion; +import com.vaadin.ui.BrowserFrame; +import com.vaadin.ui.Button; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.CheckBoxGroup; +import com.vaadin.ui.ColorPicker; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.DateField; +import com.vaadin.ui.Flash; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.Grid; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Image; +import com.vaadin.ui.ListSelect; +import com.vaadin.ui.RadioButtonGroup; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; +import com.vaadin.ui.TwinColSelect; +import com.vaadin.ui.VerticalLayout; + +/* + * 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. + */ + +/** + * + * Base testUI class for testing getCaption method. Captions of elements + * implemented differently in different layouts (FormLayout) This class adds all + * elements to the layout. The exact layout is created in a child class. + */ +public abstract class ElementComponentGetCaptionBase extends AbstractTestUI { + // Specify exact type of Layout in a child class + AbstractLayout mainLayout = null; + // default captions for all elements + public static final String[] DEFAULT_CAPTIONS = { "Combobox", "button", + "grid", "CheckBoxGroup", "RadioButtonGroup", "TwinColSelect", + "ListSelect", "ColorPicker", "Accordion", "Image", "Flash", + "BrowserFrame", "CheckBox", "TextField", "TextArea", "DateField", + "VerticalLayout", "HorizontalLayout", "FormLayout", "GridLayout", + "CssLayout" }; + + @Override + protected void setup(VaadinRequest request) { + Component[] comps = { new ComboBox(), new Button(), createGrid(), + new CheckBoxGroup(), new RadioButtonGroup(), + new TwinColSelect(), new ListSelect(), new ColorPicker(), + new Accordion(), new Image(), new Flash(), new BrowserFrame(), + new CheckBox(), new TextField(), new TextArea(), + new DateField(), new VerticalLayout(), new HorizontalLayout(), + new FormLayout(), new GridLayout(), new CssLayout() }; + addComponent(mainLayout); + for (int i = 0; i < comps.length; i++) { + Component component = comps[i]; + component.setCaption(DEFAULT_CAPTIONS[i]); + mainLayout.addComponent(component); + } + } + + static Component createGrid() { + Grid grid = new Grid(); + grid.addColumn(e -> "foo"); + + return grid; + } + + @Override + protected String getTestDescription() { + return "Test getCaption method for vaadin components"; + } + + @Override + protected Integer getTicketNumber() { + return 14453; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionCssLayout.java b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionCssLayout.java new file mode 100644 index 00000000000..4dd34318737 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionCssLayout.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.CssLayout; + +public class ElementComponentGetCaptionCssLayout + extends ElementComponentGetCaptionBase { + + public ElementComponentGetCaptionCssLayout() { + mainLayout = new CssLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionFormLayout.java b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionFormLayout.java new file mode 100644 index 00000000000..429f483fbe1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionFormLayout.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.FormLayout; + +public class ElementComponentGetCaptionFormLayout + extends ElementComponentGetCaptionBase { + + public ElementComponentGetCaptionFormLayout() { + mainLayout = new FormLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionGridLayout.java b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionGridLayout.java new file mode 100644 index 00000000000..a0b364cec3e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionGridLayout.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.GridLayout; + +public class ElementComponentGetCaptionGridLayout + extends ElementComponentGetCaptionBase { + + public ElementComponentGetCaptionGridLayout() { + mainLayout = new GridLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionHorizontal.java b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionHorizontal.java new file mode 100644 index 00000000000..553c1deeddb --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionHorizontal.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.HorizontalLayout; + +public class ElementComponentGetCaptionHorizontal + extends ElementComponentGetCaptionBase { + + public ElementComponentGetCaptionHorizontal() { + mainLayout = new HorizontalLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionVerticalLayout.java b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionVerticalLayout.java new file mode 100644 index 00000000000..9828bdcecaf --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ElementComponentGetCaptionVerticalLayout.java @@ -0,0 +1,26 @@ +/* + * 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.elements; + +import com.vaadin.ui.VerticalLayout; + +public class ElementComponentGetCaptionVerticalLayout + extends ElementComponentGetCaptionBase { + + public ElementComponentGetCaptionVerticalLayout() { + mainLayout = new VerticalLayout(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ElementExists.java b/uitest/src/main/java/com/vaadin/tests/elements/ElementExists.java new file mode 100644 index 00000000000..3e75e974163 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ElementExists.java @@ -0,0 +1,41 @@ +/* + * 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.elements; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; + +public class ElementExists extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Button button = new Button("b"); + addComponent(button); + } + + @Override + protected String getTestDescription() { + return "The TestBench method exists() should not throw an exception even when the UI " + + "has not been initialized."; + } + + @Override + protected Integer getTicketNumber() { + return 14808; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ElementQueryUI.java b/uitest/src/main/java/com/vaadin/tests/elements/ElementQueryUI.java new file mode 100644 index 00000000000..3857ef68df9 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/ElementQueryUI.java @@ -0,0 +1,28 @@ +package com.vaadin.tests.elements; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; + +public class ElementQueryUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + for (int i = 0; i < 10; i++) { + addComponent(new Button("Button " + i)); + } + + getLayout().setSizeUndefined(); + } + + @Override + protected String getTestDescription() { + return "A generic test for ElementQuery"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/TestBenchElementRightClick.java b/uitest/src/main/java/com/vaadin/tests/elements/TestBenchElementRightClick.java new file mode 100644 index 00000000000..11af3fe7724 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/TestBenchElementRightClick.java @@ -0,0 +1,68 @@ +package com.vaadin.tests.elements; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.MouseEventDetails.MouseButton; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.v7.event.ItemClickEvent; +import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; +import com.vaadin.v7.ui.Table; + +public class TestBenchElementRightClick extends AbstractTestUI { + + Table table = new Table(); + Label labelEvent = new Label(); + private int COLUMNS = 4; + private int ROWS = 10; + + @Override + protected void setup(VaadinRequest request) { + labelEvent.setId("label1"); + table.setId("id1"); + fillTable(table); + addComponent(table); + addComponent(labelEvent); + labelEvent.setValue("InitialValue"); + table.addItemClickListener(new ItemClickListener() { + + @Override + public void itemClick(ItemClickEvent event) { + if (event.getButton().equals(MouseButton.RIGHT)) { + labelEvent.setValue("RightClick"); + } else if (event.isDoubleClick()) { + labelEvent.setValue("DoubleClick"); + } + } + }); + } + + @Override + protected String getTestDescription() { + return "Test double click and right click on TestBenchElement"; + } + + @Override + protected Integer getTicketNumber() { + return 14384; + } + + // set up the properties (columns) + private void initProperties(Table table) { + for (int i = 0; i < COLUMNS; i++) { + table.addContainerProperty("property" + i, String.class, + "some value"); + } + } + + // fill the table with some random data + private void fillTable(Table table) { + initProperties(table); + for (int i = 0; i < ROWS; i++) { + String[] line = new String[COLUMNS]; + for (int j = 0; j < COLUMNS; j++) { + line[j] = "col=" + j + " row=" + i; + } + table.addItem(line, null); + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/TreeElementGetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/TreeElementGetValue.java new file mode 100644 index 00000000000..e8bf2b19504 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/TreeElementGetValue.java @@ -0,0 +1,62 @@ +/* + * 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.elements; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.Tree; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class TreeElementGetValue extends AbstractTestUI { + + public static final String TEST_VALUE = "testValue"; + public static final String TEST_VALUE_LVL2 = "testValueLvl2"; + public static final String TEST_VALUE_LVL3 = "testValueLvl3"; + + @Override + protected void setup(VaadinRequest request) { + Tree tree = new Tree(); + tree.addItem("item1"); + tree.addItem("item1_1"); + tree.addItem("item1_2"); + tree.setParent("item1_1", "item1"); + tree.setParent("item1_2", "item1"); + tree.addItem(TEST_VALUE); + tree.addItem(TEST_VALUE_LVL2); + tree.addItem(TEST_VALUE_LVL3); + tree.setParent(TEST_VALUE_LVL2, TEST_VALUE); + tree.setParent(TEST_VALUE_LVL3, TEST_VALUE_LVL2); + tree.addItem("item3"); + tree.setValue(TEST_VALUE_LVL2); + tree.expandItem(TEST_VALUE); + addComponent(tree); + } + + @Override + protected String getTestDescription() { + return "Method getValue() should return selected item of the tree"; + } + + @Override + protected Integer getTicketNumber() { + return 13455; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractFieldElementSetValueReadOnly.java b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractFieldElementSetValueReadOnly.java new file mode 100644 index 00000000000..01f9eedda95 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractFieldElementSetValueReadOnly.java @@ -0,0 +1,58 @@ +package com.vaadin.tests.elements.abstracttextfield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractField; +import com.vaadin.ui.AbstractMultiSelect; +import com.vaadin.ui.AbstractSingleSelect; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.CheckBoxGroup; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.DateField; +import com.vaadin.ui.ListSelect; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.PasswordField; +import com.vaadin.ui.RadioButtonGroup; +import com.vaadin.ui.RichTextArea; +import com.vaadin.ui.Slider; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; +import com.vaadin.ui.TwinColSelect; + +public class AbstractFieldElementSetValueReadOnly extends AbstractTestUI { + + private AbstractField[] fields = { new TextArea(), new TextField(), + new DateField(), new PasswordField(), new CheckBox(), + new RichTextArea(), new Slider() }; + private AbstractMultiSelect[] multiSelects = { new ListSelect(), + new CheckBoxGroup(), new TwinColSelect() }; + private AbstractSingleSelect[] singleSelects = { new ComboBox(), + new NativeSelect(), new RadioButtonGroup() }; + + @Override + protected void setup(VaadinRequest request) { + for (AbstractField field : fields) { + field.setReadOnly(true); + addComponent(field); + } + for (AbstractMultiSelect multiSelect : multiSelects) { + multiSelect.setReadOnly(true); + addComponent(multiSelect); + } + for (AbstractSingleSelect singleSelect : singleSelects) { + singleSelect.setReadOnly(true); + addComponent(singleSelect); + } + } + + @Override + protected String getTestDescription() { + return "When vaadin element is set ReadOnly, setValue() method should raise an exception"; + } + + @Override + protected Integer getTicketNumber() { + return 14068; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValue.java new file mode 100644 index 00000000000..09b6fcf02bb --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValue.java @@ -0,0 +1,94 @@ +/* + * 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.elements.abstracttextfield; + +import java.time.LocalDate; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractField; +import com.vaadin.ui.AbstractTextField; +import com.vaadin.ui.DateField; +import com.vaadin.ui.Label; +import com.vaadin.ui.PasswordField; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.TextField; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class AbstractTextElementSetValue extends AbstractTestUI { + + AbstractTextField[] comps = { new TextField(), new PasswordField(), + new TextArea() }; + // one extra label for DateField, which we create in a separate method + Label[] eventCountLabels = new Label[comps.length + 1]; + int[] eventCounters = new int[comps.length + 1]; + public static final String INITIAL_VALUE = "initial value"; + public static final LocalDate INITIAL_DATE = LocalDate.of(2016, 5, 7); + + @Override + protected void setup(VaadinRequest request) { + + for (int i = 0; i < comps.length; i++) { + comps[i].setValue(INITIAL_VALUE); + eventCountLabels[i] = new Label(); + eventCountLabels[i].setCaption("event count"); + // create an valueChangeListener to count events + addValueChangeListener(comps[i], i); + addComponent(comps[i]); + addComponent(eventCountLabels[i]); + + } + + // add one extra label for DateField, which we create in a separate + // method + eventCountLabels[comps.length] = new Label(); + DateField df = createDateField(); + addValueChangeListener(df, comps.length); + addComponent(df); + eventCountLabels[comps.length].setCaption("event count"); + addComponent(eventCountLabels[comps.length]); + + } + + private void addValueChangeListener(AbstractField field, int index) { + field.addValueChangeListener(event -> { + eventCounters[index]++; + String value = "" + eventCounters[index]; + eventCountLabels[index].setValue(value); + }); + } + + private DateField createDateField() { + DateField df = new DateField(); + df.setValue(INITIAL_DATE); + return df; + } + + @Override + protected String getTestDescription() { + return "Test type method of AbstractTextField components"; + } + + @Override + protected Integer getTicketNumber() { + return 13365; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractFieldElementSetValueReadOnly.java b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractFieldElementSetValueReadOnly.java new file mode 100644 index 00000000000..2b18a480957 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractFieldElementSetValueReadOnly.java @@ -0,0 +1,49 @@ +package com.vaadin.tests.elements.abstracttextfield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.AbstractField; +import com.vaadin.v7.ui.CheckBox; +import com.vaadin.v7.ui.ComboBox; +import com.vaadin.v7.ui.DateField; +import com.vaadin.v7.ui.Form; +import com.vaadin.v7.ui.ListSelect; +import com.vaadin.v7.ui.NativeSelect; +import com.vaadin.v7.ui.OptionGroup; +import com.vaadin.v7.ui.PasswordField; +import com.vaadin.v7.ui.ProgressBar; +import com.vaadin.v7.ui.RichTextArea; +import com.vaadin.v7.ui.Slider; +import com.vaadin.v7.ui.Table; +import com.vaadin.v7.ui.TextArea; +import com.vaadin.v7.ui.TextField; +import com.vaadin.v7.ui.Tree; +import com.vaadin.v7.ui.TwinColSelect; + +public class CompatibilityAbstractFieldElementSetValueReadOnly extends AbstractTestUI { + + AbstractField[] elems = { new ComboBox(), new ListSelect(), + new NativeSelect(), new OptionGroup(), new Table(), new Tree(), + new TwinColSelect(), new TextArea(), new TextField(), + new DateField(), new PasswordField(), new CheckBox(), new Form(), + new ProgressBar(), new RichTextArea(), new Slider() }; + + @Override + protected void setup(VaadinRequest request) { + for (int i = 0; i < elems.length; i++) { + elems[i].setReadOnly(true); + addComponent(elems[i]); + } + } + + @Override + protected String getTestDescription() { + return "When vaadin element is set ReadOnly, setValue() method should raise an exception"; + } + + @Override + protected Integer getTicketNumber() { + return 14068; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractTextElementSetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractTextElementSetValue.java new file mode 100644 index 00000000000..170afb33485 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractTextElementSetValue.java @@ -0,0 +1,102 @@ +/* + * 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.elements.abstracttextfield; + +import java.util.Date; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.data.Property.ValueChangeEvent; +import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.ui.AbstractTextField; +import com.vaadin.v7.ui.DateField; +import com.vaadin.v7.ui.Label; +import com.vaadin.v7.ui.PasswordField; +import com.vaadin.v7.ui.TextArea; +import com.vaadin.v7.ui.TextField; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class CompatibilityAbstractTextElementSetValue extends AbstractTestUI { + + AbstractTextField[] comps = { new TextField(), new PasswordField(), + new TextArea() }; + // one extra label for DateField, which we create in a separate method + Label[] eventCountLabels = new Label[comps.length + 1]; + int[] eventCounters = new int[comps.length + 1]; + public static final String INITIAL_VALUE = "initial value"; + public static final Date INITIAL_DATE = new Date(2016, 5, 7); + + @Override + protected void setup(VaadinRequest request) { + + for (int i = 0; i < comps.length; i++) { + comps[i].setValue(INITIAL_VALUE); + eventCountLabels[i] = new Label(); + eventCountLabels[i].setCaption("event count"); + // create an valueChangeListener, to count valueChangeListener + // events + comps[i].addValueChangeListener(new ValueChangeCounter(i)); + addComponent(comps[i]); + addComponent(eventCountLabels[i]); + + } + // add one extra label for DateField, which we create in a separate + // method + eventCountLabels[comps.length] = new Label(); + DateField df = createDateField(); + df.addValueChangeListener(new ValueChangeCounter(comps.length)); + addComponent(df); + eventCountLabels[comps.length].setCaption("event count"); + addComponent(eventCountLabels[comps.length]); + } + + @Override + protected String getTestDescription() { + return "Test type method of AbstractTextField components"; + } + + private DateField createDateField() { + DateField df = new DateField(); + df.setValue(INITIAL_DATE); + return df; + } + + @Override + protected Integer getTicketNumber() { + return 13365; + } + + // helper class, which increases valuechange event counter + private class ValueChangeCounter implements ValueChangeListener { + private int index; + + public ValueChangeCounter(int index) { + this.index = index; + } + + @Override + public void valueChange(ValueChangeEvent event) { + eventCounters[index]++; + String value = "" + eventCounters[index]; + eventCountLabels[index].setValue(value); + } + + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/button/ButtonUI.java b/uitest/src/main/java/com/vaadin/tests/elements/button/ButtonUI.java new file mode 100644 index 00000000000..905a9ef9418 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/button/ButtonUI.java @@ -0,0 +1,103 @@ +/* + * 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.elements.button; + +import com.vaadin.server.FontAwesome; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; +import com.vaadin.ui.themes.ValoTheme; + +/** + * + */ +@SuppressWarnings("serial") +public class ButtonUI extends AbstractTestUI { + + public static final String TEXT_FIELD_ID = "testTextfield"; + public static final String LABEL_ID = "testLabel"; + public static String QUIET_BUTTON_ID = "quietButton"; + public static String QUIET_BUTTON_NO_CAPTION_ID = "quietButton2"; + public static String NORMAL_BUTTON_ID = "normalButton"; + + final TextField testedField = new TextField(); + final Label testedLabel = new Label(); + + @Override + protected void setup(VaadinRequest request) { + testedField.setId(TEXT_FIELD_ID); + addComponent(testedField); + testedLabel.setId(LABEL_ID); + addComponent(testedLabel); + + testedField.setValue(""); + + Button quietButton = new Button("Quiet Button"); + quietButton.setId(QUIET_BUTTON_ID); + quietButton.addStyleName(ValoTheme.BUTTON_QUIET); + addListener(quietButton, "Clicked"); + + Button quietButtonNoCaption = new Button(""); + quietButtonNoCaption.setId(QUIET_BUTTON_NO_CAPTION_ID); + quietButtonNoCaption.addStyleName(ValoTheme.BUTTON_QUIET); + quietButtonNoCaption.setIcon(FontAwesome.ANDROID); + addListener(quietButtonNoCaption, "Clicked"); + + addComponent(quietButton); + addComponent(quietButtonNoCaption); + addComponent(addButtonWithDelay()); + + } + + private Button addButtonWithDelay() { + Button btn = new Button(); + btn.setId(NORMAL_BUTTON_ID); + btn.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + testedField.setValue("Clicked"); + testedLabel.setValue("Clicked"); + } + }); + return btn; + } + + private void addListener(Button button, final String clickEventText) { + button.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent clickEvent) { + testedField.setValue(clickEventText); + } + }); + } + + @Override + protected String getTestDescription() { + return "Test button click, for button with ValoTheme.BUTTON_QUIET style"; + } + + @Override + protected Integer getTicketNumber() { + return 16346; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/calendar/CalendarUI.java b/uitest/src/main/java/com/vaadin/tests/elements/calendar/CalendarUI.java new file mode 100644 index 00000000000..f6873857aea --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/calendar/CalendarUI.java @@ -0,0 +1,46 @@ +package com.vaadin.tests.elements.calendar; + +import static java.util.Calendar.DAY_OF_MONTH; + +import java.util.Locale; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.v7.ui.Calendar; + +public class CalendarUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Calendar calendar = new Calendar(); + calendar.setWidth("100%"); + + Button monthView = new Button("Month view"); + monthView.setId("month-view"); + monthView.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + java.util.Calendar javaCalendar = java.util.Calendar + .getInstance(Locale.ENGLISH); + javaCalendar.set(DAY_OF_MONTH, 1); + calendar.setStartDate(javaCalendar.getTime()); + javaCalendar.set(DAY_OF_MONTH, + javaCalendar.getActualMaximum(DAY_OF_MONTH)); + calendar.setEndDate(javaCalendar.getTime()); + } + }); + + addComponents(monthView, calendar); + } + + @Override + protected String getTestDescription() { + return "UI used to validate Calendar element API"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/checkbox/ClickCheckBoxUI.java b/uitest/src/main/java/com/vaadin/tests/elements/checkbox/ClickCheckBoxUI.java new file mode 100644 index 00000000000..5ff26b0a181 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/checkbox/ClickCheckBoxUI.java @@ -0,0 +1,41 @@ +/* + * 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.elements.checkbox; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBox; + +public class ClickCheckBoxUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + CheckBox checkBox = new CheckBox("Checkbox Caption"); + addComponent(checkBox); + addComponent(new CheckBox()); + } + + @Override + protected String getTestDescription() { + return "Ensure that CheckBoxElement.click() actually toggles checkmark"; + } + + @Override + protected Integer getTicketNumber() { + return 13763; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/checkboxgroup/CheckBoxGroupSetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/checkboxgroup/CheckBoxGroupSetValue.java new file mode 100644 index 00000000000..acc86d16ef1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/checkboxgroup/CheckBoxGroupSetValue.java @@ -0,0 +1,33 @@ +package com.vaadin.tests.elements.checkboxgroup; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBoxGroup; + +public class CheckBoxGroupSetValue extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + CheckBoxGroup group = new CheckBoxGroup<>(); + List options = new ArrayList<>(); + options.add("item1"); + options.add("item2"); + options.add("item3"); + group.setItems(options); + addComponent(group); + } + + @Override + protected String getTestDescription() { + return "Test CheckBoxGroup element setValue() and selectByText()"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxGetSuggestions.java b/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxGetSuggestions.java new file mode 100644 index 00000000000..38a133671bb --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxGetSuggestions.java @@ -0,0 +1,34 @@ +package com.vaadin.tests.elements.combobox; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +public class ComboBoxGetSuggestions extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + ComboBox cb = new ComboBox<>(); + cb.setEmptySelectionAllowed(false); + List options = new ArrayList<>(); + for (int i = 1; i < 100; i++) { + options.add("item" + i); + } + cb.setItems(options); + addComponent(cb); + } + + @Override + protected String getTestDescription() { + return "Test getSuggestions() method of ComboBoxElement returns correct values"; + } + + @Override + protected Integer getTicketNumber() { + return 14372; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxInputNotAllowed.java b/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxInputNotAllowed.java new file mode 100644 index 00000000000..12b117c3a0f --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxInputNotAllowed.java @@ -0,0 +1,47 @@ +package com.vaadin.tests.elements.combobox; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Label; + +public class ComboBoxInputNotAllowed extends AbstractTestUI { + + public static final String ITEM_ON_FIRST_PAGE = "item 2"; + public static final String ITEM_ON_SECOND_PAGE = "item 19"; + public static final String ITEM_ON_LAST_PAGE = "item 30"; + public static final String ITEM_LAST_WITH_PARENTHESIS = "item (last)"; + + public static final List ITEMS = new ArrayList(); + static { + for (int i = 1; i <= 30; i++) { + ITEMS.add("item " + i); + } + ITEMS.add(ITEM_LAST_WITH_PARENTHESIS); + } + + @Override + protected void setup(VaadinRequest request) { + ComboBox comboBox = new ComboBox<>("", ITEMS); + comboBox.setTextInputAllowed(false); + comboBox.addValueChangeListener(e -> { + addComponent(new Label("Value is now: " + e.getValue())); + }); + + addComponent(comboBox); + } + + @Override + protected String getTestDescription() { + return "ComboBoxElement.selectByText(String) selects only first item when setTextInputAllowed set to false "; + } + + @Override + protected Integer getTicketNumber() { + return 14486; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxUI.java b/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxUI.java new file mode 100644 index 00000000000..d92130c8632 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/combobox/ComboBoxUI.java @@ -0,0 +1,58 @@ +/* + * 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.elements.combobox; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +/** + * + */ +@SuppressWarnings("serial") +public class ComboBoxUI extends AbstractTestUI { + + public static final List currencies = new ArrayList(); + static { + currencies.add("GBP"); + currencies.add("EUR"); + currencies.add("USD"); + } + + @Override + protected void setup(VaadinRequest request) { + ComboBox comboBox = new ComboBox("NullAllowedComboBox", currencies); + addComponent(comboBox); + + comboBox = new ComboBox("NullForbiddenComboBox", currencies); + comboBox.setEmptySelectionAllowed(false); + addComponent(comboBox); + } + + @Override + protected String getTestDescription() { + return "When calling ComboBoxElement.selectByText(String) several times, the input text should be cleared every time, instead of being appended"; + } + + @Override + protected Integer getTicketNumber() { + return 14404; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/combobox/SelectByText.java b/uitest/src/main/java/com/vaadin/tests/elements/combobox/SelectByText.java new file mode 100644 index 00000000000..d4f1bfd8be8 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/combobox/SelectByText.java @@ -0,0 +1,73 @@ +/* + * 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.elements.combobox; + +import java.util.ArrayList; +import java.util.List; + +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.VerticalLayout; + +/** + * UI used to validate ComboBox.selectByText(String s) works properly if input + * String s contains parentheses + */ +@SuppressWarnings("serial") +public class SelectByText extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final VerticalLayout layout = new VerticalLayout(); + addComponent(layout); + + ComboBox combobox = new ComboBox<>(); + List options = new ArrayList(); + + options.add("Value 1"); + options.add("("); + options.add("(Value"); + options.add("Value 222"); + options.add("Value 22"); + options.add("Value 2"); + options.add("Value("); + options.add("Value(i)"); + options.add("((Test ) selectByTest() method(with' parentheses)(("); + options.add("Value 3"); + + combobox.setItems(options); + + layout.addComponent(combobox); + combobox.addValueChangeListener(e -> { + layout.addComponent( + new Label("Value is now '" + e.getValue() + "'")); + }); + + } + + @Override + protected String getTestDescription() { + return "ComboBox's selectByText(String text) method should work if text contains parentheses"; + } + + @Override + protected Integer getTicketNumber() { + return 14048; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/datefield/DateFieldPopupSetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/datefield/DateFieldPopupSetValue.java new file mode 100644 index 00000000000..dd0636e5d0f --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/datefield/DateFieldPopupSetValue.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.elements.datefield; + +import java.time.LocalDate; +import java.util.Date; + +import com.vaadin.data.HasValue.ValueChangeEvent; +import com.vaadin.data.HasValue.ValueChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DateField; +import com.vaadin.ui.Label; + +public class DateFieldPopupSetValue extends AbstractTestUI { + + public static LocalDate initialDate = LocalDate.of(2015, 4, 12); + public static Date changedDate = new Date(2015, 5, 11); + + Label counterLbl = new Label(); + + @Override + protected void setup(VaadinRequest request) { + counterLbl.setId("counter"); + DateField df = new DateField(); + df.setDateFormat("MM/dd/yy"); + df.setValue(initialDate); + df.addValueChangeListener(new EventCounter()); + addComponent(df); + addComponent(counterLbl); + } + + @Override + protected String getTestDescription() { + return "Test popupDateFieldElement getValue/setValue"; + } + + @Override + protected Integer getTicketNumber() { + return 15092; + } + + private class EventCounter implements ValueChangeListener { + private int counter = 0; + + @Override + public void valueChange(ValueChangeEvent event) { + counter++; + counterLbl.setValue("" + counter); + } + + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/grid/GridUI.java b/uitest/src/main/java/com/vaadin/tests/elements/grid/GridUI.java new file mode 100644 index 00000000000..4655eb35600 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/grid/GridUI.java @@ -0,0 +1,75 @@ +package com.vaadin.tests.elements.grid; + +import java.util.ArrayList; +import java.util.Collection; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Label; + +public class GridUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + int rowCount = 100; + if (request.getParameter("rowCount") != null) { + rowCount = Integer.parseInt(request.getParameter("rowCount")); + } + + final Grid grid = new Grid(); + grid.setItems(getMockData(rowCount)); + grid.addColumn(Item::getFoo).setCaption("foo"); + grid.addColumn(Item::getBar).setCaption("bar"); + + grid.setDetailsGenerator(item -> { + return new Label( + "Foo = " + item.getFoo() + " Bar = " + item.getBar()); + }); + grid.addItemClickListener(event -> { + if (event.getMouseEventDetails().isDoubleClick()) { + grid.setDetailsVisible(event.getItem(), + !grid.isDetailsVisible(event.getItem())); + } + }); + + addComponent(grid); + } + + private Collection getMockData(int rowCount) { + Collection data = new ArrayList(); + for (int i = 0; i < rowCount; i++) { + Item item = new Item("foo " + i, "bar " + i); + data.add(item); + } + return data; + } + + @Override + protected String getTestDescription() { + return "Test UI for Grid element API"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + + private static class Item { + private String foo; + private String bar; + + public Item(String foo, String bar) { + this.foo = foo; + this.bar = bar; + } + + public String getFoo() { + return foo; + } + + public String getBar() { + return bar; + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/link/LinkUI.java b/uitest/src/main/java/com/vaadin/tests/elements/link/LinkUI.java new file mode 100644 index 00000000000..b3ff1ac2925 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/link/LinkUI.java @@ -0,0 +1,25 @@ +package com.vaadin.tests.elements.link; + +import com.vaadin.server.ExternalResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Link; + +public class LinkUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Link link = new Link("server root", new ExternalResource("/")); + addComponent(link); + } + + @Override + protected String getTestDescription() { + return "Clicking on a link should work"; + } + + @Override + protected Integer getTicketNumber() { + return 15357; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/listselect/ListSelectOptionClick.java b/uitest/src/main/java/com/vaadin/tests/elements/listselect/ListSelectOptionClick.java new file mode 100644 index 00000000000..fb1fdfc53a9 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/listselect/ListSelectOptionClick.java @@ -0,0 +1,45 @@ +package com.vaadin.tests.elements.listselect; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.ListSelect; + +public class ListSelectOptionClick extends AbstractTestUI { + + private Label counterLbl = new Label(); + private int counter = 0; + + @Override + protected void setup(VaadinRequest request) { + ListSelect multiSelect = new ListSelect(); + counterLbl.setValue("0"); + List options = new ArrayList(); + options.add("item1"); + options.add("item2"); + options.add("item3"); + multiSelect.setItems(options); + multiSelect.select("item1"); + multiSelect.addSelectionListener(event -> { + counter++; + counterLbl.setValue("" + counter + ": " + event.getValue()); + }); + addComponent(multiSelect); + counterLbl.setId("multiCounterLbl"); + addComponent(counterLbl); + } + + @Override + protected String getTestDescription() { + return "Test that user can pick option from ListSelectElement by calling the click() method"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/menubar/MenuBarUI.java b/uitest/src/main/java/com/vaadin/tests/elements/menubar/MenuBarUI.java new file mode 100644 index 00000000000..a78eae271cb --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/menubar/MenuBarUI.java @@ -0,0 +1,83 @@ +/* + * 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.elements.menubar; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.MenuBar; +import com.vaadin.ui.MenuBar.Command; +import com.vaadin.ui.MenuBar.MenuItem; + +/** + * + */ +@SuppressWarnings("serial") +public class MenuBarUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent(createDefaultMenuBar("", "")); + addComponent(createDefaultMenuBar("2", "")); + addComponent(createDefaultMenuBar("", "2")); + } + + private MenuBar createDefaultMenuBar(String topLevelItemSuffix, + String secondaryLevelItemSuffix) { + MenuBar menuBar = new MenuBar(); + MenuItem file = menuBar.addItem("File" + topLevelItemSuffix, null); + file.addItem("Open" + secondaryLevelItemSuffix, new MenuBarCommand()); + file.addItem("Save" + secondaryLevelItemSuffix, new MenuBarCommand()); + file.addItem("Save As.." + secondaryLevelItemSuffix, + new MenuBarCommand()); + file.addSeparator(); + + MenuItem export = file.addItem("Export.." + secondaryLevelItemSuffix, + null); + export.addItem("As PDF..." + secondaryLevelItemSuffix, + new MenuBarCommand()); + export.addItem("As Doc..." + secondaryLevelItemSuffix, + new MenuBarCommand()); + + file.addSeparator(); + file.addItem("Exit" + secondaryLevelItemSuffix, new MenuBarCommand()); + + MenuItem edit = menuBar.addItem("Edit" + topLevelItemSuffix, null); + edit.addItem("Copy" + secondaryLevelItemSuffix, new MenuBarCommand()); + edit.addItem("Cut" + secondaryLevelItemSuffix, new MenuBarCommand()); + edit.addItem("Paste" + secondaryLevelItemSuffix, new MenuBarCommand()); + + menuBar.addItem("Help" + topLevelItemSuffix, new MenuBarCommand()); + return menuBar; + } + + @Override + protected String getTestDescription() { + return "UI used to validate MenuBarElement API"; + } + + @Override + protected Integer getTicketNumber() { + return 13364; + } + + private class MenuBarCommand implements Command { + + @Override + public void menuSelected(MenuItem selectedItem) { + } + + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/nativeselect/NativeSelectSetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/nativeselect/NativeSelectSetValue.java new file mode 100644 index 00000000000..43fc10cde12 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/nativeselect/NativeSelectSetValue.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.elements.nativeselect; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.data.provider.ListDataProvider; +import com.vaadin.event.selection.SingleSelectionEvent; +import com.vaadin.event.selection.SingleSelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.NativeSelect; + +public class NativeSelectSetValue extends AbstractTestUI { + + + private int counter = 0; + Label lblCounter = new Label("0"); + + @Override + protected void setup(VaadinRequest request) { + NativeSelect select = new NativeSelect(); + List options = new ArrayList<>(); + options.add("item 1"); + options.add("item 2"); + options.add("item 3"); + select.setDataProvider(new ListDataProvider<>(options)); + select.setValue("item 1"); + lblCounter.setId("counter"); + + select.addSelectionListener(new EventCounter()); + addComponent(select); + addComponent(lblCounter); + } + + private class EventCounter implements SingleSelectionListener { + private int counter = 0; + + @Override + public void selectionChange(SingleSelectionEvent event) { + counter++; + lblCounter.setValue("" + counter); + } + + } + + @Override + protected String getTestDescription() { + return "Native select element setValue method should change value and triggers change event"; + } + + @Override + protected Integer getTicketNumber() { + return 13365; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescription.java b/uitest/src/main/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescription.java new file mode 100644 index 00000000000..2b208d3e422 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescription.java @@ -0,0 +1,68 @@ +package com.vaadin.tests.elements.notification; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Notification.Type; + +public class NotificationGetTypeAndDescription extends AbstractTestUI { + + private final static Type[] types = { Type.WARNING_MESSAGE, + Type.ERROR_MESSAGE, Type.HUMANIZED_MESSAGE, Type.TRAY_NOTIFICATION }; + public final static String[] type_names = { "warning", "error", + "humanized", "tray_notification" }; + public final static String[] captions = { "warningC", "errorC", + "humanizedC", "tray_notificationC" }; + public final static String[] descriptions = { "warning", "error", + "humanized", "tray_notification" }; + + @Override + protected void setup(VaadinRequest request) { + for (int i = 0; i < types.length; i++) { + Button btn = new Button(); + btn.setId("button" + i); + btn.setCaption(type_names[i]); + btn.addClickListener(new CounterClickListener(i)); + addComponent(btn); + } + // add extra button which shows Notification only with caption #14356 + Button btn = new Button("Show notification"); + btn.setId("showid"); + btn.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + Notification.show("test"); + } + }); + addComponent(btn); + } + + @Override + protected String getTestDescription() { + return "Test getType and getDescription methods of NotificationElement"; + } + + @Override + protected Integer getTicketNumber() { + return 13768; + } + + private class CounterClickListener implements ClickListener { + int index; + + public CounterClickListener(int i) { + index = i; + } + + @Override + public void buttonClick(ClickEvent event) { + Notification.show(captions[index], descriptions[index], + types[index]); + } + + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/optiongroup/OptionGroupSetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/optiongroup/OptionGroupSetValue.java new file mode 100644 index 00000000000..0536f9c8e62 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/optiongroup/OptionGroupSetValue.java @@ -0,0 +1,28 @@ +package com.vaadin.tests.elements.optiongroup; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.OptionGroup; + +public class OptionGroupSetValue extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + OptionGroup group = new OptionGroup(); + group.addItem("item1"); + group.addItem("item2"); + group.addItem("item3"); + addComponent(group); + } + + @Override + protected String getTestDescription() { + return "Test OptionGroup element setValue() and SelectByText()"; + } + + @Override + protected Integer getTicketNumber() { + return 14918; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/panel/PanelScroll.java b/uitest/src/main/java/com/vaadin/tests/elements/panel/PanelScroll.java new file mode 100644 index 00000000000..c3a5f32ed3d --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/panel/PanelScroll.java @@ -0,0 +1,40 @@ +package com.vaadin.tests.elements.panel; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalLayout; + +public class PanelScroll extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Panel panel = new Panel(); + panel.setId("mainPanel"); + panel.setWidth("200px"); + panel.setHeight("200px"); + VerticalLayout layout = new VerticalLayout(); + layout.setWidth("500px"); + layout.setHeight("500px"); + Button btn = new Button("Button 1"); + Button btn2 = new Button("Button 2"); + layout.addComponent(btn); + layout.setComponentAlignment(btn, Alignment.TOP_RIGHT); + layout.addComponent(btn2); + layout.setComponentAlignment(btn2, Alignment.BOTTOM_LEFT); + panel.setContent(layout); + addComponent(panel); + } + + @Override + protected String getTestDescription() { + return "Test scroll left and scroll right methods of PanelElement"; + } + + @Override + protected Integer getTicketNumber() { + return 14819; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/progressbar/ProgressBarUI.java b/uitest/src/main/java/com/vaadin/tests/elements/progressbar/ProgressBarUI.java new file mode 100644 index 00000000000..c283fb9b03d --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/progressbar/ProgressBarUI.java @@ -0,0 +1,35 @@ +package com.vaadin.tests.elements.progressbar; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ProgressBar; + +public class ProgressBarUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + ProgressBar complete = new ProgressBar(); + complete.setId("complete"); + complete.setValue(1f); + + ProgressBar halfComplete = new ProgressBar(); + halfComplete.setId("halfComplete"); + halfComplete.setValue(0.5f); + + ProgressBar notStarted = new ProgressBar(); + notStarted.setId("notStarted"); + notStarted.setValue(0f); + + addComponents(complete, halfComplete, notStarted); + } + + @Override + protected String getTestDescription() { + return "Test UI for ProgressBar element API"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/radiobuttongroup/RadioButtonGroupSetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/radiobuttongroup/RadioButtonGroupSetValue.java new file mode 100644 index 00000000000..dbe21d4dad3 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/radiobuttongroup/RadioButtonGroupSetValue.java @@ -0,0 +1,35 @@ +package com.vaadin.tests.elements.radiobuttongroup; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.data.provider.ListDataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.RadioButtonGroup; + +public class RadioButtonGroupSetValue extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + RadioButtonGroup group = new RadioButtonGroup(); + List options = new ArrayList(); + options.add("item1"); + options.add("item2"); + options.add("item3"); + group.setDataProvider(new ListDataProvider(options)); + + addComponent(group); + } + + @Override + protected String getTestDescription() { + return "Test RadioButtonGroup element setValue() and SelectByText()"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/slider/SliderGetHandle.java b/uitest/src/main/java/com/vaadin/tests/elements/slider/SliderGetHandle.java new file mode 100644 index 00000000000..9ea0664ce1e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/slider/SliderGetHandle.java @@ -0,0 +1,22 @@ +package com.vaadin.tests.elements.slider; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Slider; + +public class SliderGetHandle extends AbstractTestUI { + + public static final double INITIAL_VALUE = 10.0; + + @Override + protected void setup(VaadinRequest request) { + Slider sl1 = new Slider(); + Slider sl2 = new Slider(); + sl2.setValue(INITIAL_VALUE); + sl1.setWidth("50px"); + sl2.setWidth("50px"); + addComponent(sl1); + addComponent(sl2); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/splitpanel/SplitPanelComponents.java b/uitest/src/main/java/com/vaadin/tests/elements/splitpanel/SplitPanelComponents.java new file mode 100644 index 00000000000..ce6fdc9f1d0 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/splitpanel/SplitPanelComponents.java @@ -0,0 +1,84 @@ +/* + * 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.elements.splitpanel; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.HorizontalSplitPanel; +import com.vaadin.ui.Label; +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalSplitPanel; + +/** + * This UI is used for testing that TestBench gets the second component of a + * split panel using getSecondComponent() even when there is no first component. + */ +public class SplitPanelComponents extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + // A horizontal split panel without a first component + Panel p1 = new Panel(); + HorizontalSplitPanel hsp = new HorizontalSplitPanel(); + hsp.setSecondComponent(new Label("Label 1.2")); + p1.setContent(hsp); + hsp.setSizeFull(); + p1.setHeight("30px"); + + // A vertical split panel without a first component + Panel p2 = new Panel(); + VerticalSplitPanel vsp = new VerticalSplitPanel(); + vsp.setSecondComponent(new Label("Label 2.2")); + p2.setContent(vsp); + vsp.setSizeFull(); + p2.setHeight("100px"); + + // A split panel containing both components + Panel p3 = new Panel(); + HorizontalSplitPanel hsp2 = new HorizontalSplitPanel(); + hsp2.setFirstComponent(new Label("Label 3.1")); + hsp2.setSecondComponent(new Label("Label 3.2")); + p3.setContent(hsp2); + hsp2.setSizeFull(); + p3.setHeight("30px"); + + // A vertical split panel without a second component + Panel p4 = new Panel(); + VerticalSplitPanel vsp2 = new VerticalSplitPanel(); + vsp2.setFirstComponent(new Button("Button")); + p4.setContent(vsp2); + vsp2.setSizeFull(); + p4.setHeight("100px"); + + addComponent(p1); + addComponent(p2); + addComponent(p3); + addComponent(p4); + } + + @Override + protected String getTestDescription() { + return "The second component of a split panel should be accessible" + + " in TestBench using getSecondComponent() regardless of whether" + + " the panel contains a first component."; + } + + @Override + protected Integer getTicketNumber() { + return 14073; + } +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/elements/table/TableElementContextMenu.java b/uitest/src/main/java/com/vaadin/tests/elements/table/TableElementContextMenu.java new file mode 100644 index 00000000000..a36beb86fa7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/table/TableElementContextMenu.java @@ -0,0 +1,70 @@ +package com.vaadin.tests.elements.table; + +import com.vaadin.event.Action; +import com.vaadin.event.Action.Handler; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Notification; +import com.vaadin.v7.ui.Table; + +public class TableElementContextMenu extends AbstractTestUI { + + Table table = new Table(); + private int COLUMNS = 4; + private int ROWS = 10; + + @Override + protected void setup(VaadinRequest request) { + fillTable(table); + table.addActionHandler(new TableActionHandler()); + addComponent(table); + } + + @Override + protected String getTestDescription() { + return "Tests that calling TableElement.contextClick() opens the context menu"; + } + + @Override + protected Integer getTicketNumber() { + return 14385; + } + + // set up the properties (columns) + private void initProperties(Table table) { + for (int i = 0; i < COLUMNS; i++) { + table.addContainerProperty("property" + i, String.class, + "some value"); + } + } + + // fill the table with some random data + private void fillTable(Table table) { + initProperties(table); + for (int i = 0; i < ROWS; i++) { + String[] line = new String[COLUMNS]; + for (int j = 0; j < COLUMNS; j++) { + line[j] = "col=" + j + " row=" + i; + } + table.addItem(line, null); + } + } + + public class TableActionHandler implements Handler { + + @Override + public Action[] getActions(Object target, Object sender) { + Action[] actions = new Action[2]; + actions[0] = new Action("Add"); + actions[1] = new Action("Edit"); + return actions; + } + + @Override + public void handleAction(Action action, Object sender, Object target) { + Notification.show(action.getCaption()); + + } + + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/table/TableScroll.java b/uitest/src/main/java/com/vaadin/tests/elements/table/TableScroll.java new file mode 100644 index 00000000000..ac5e0081232 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/table/TableScroll.java @@ -0,0 +1,58 @@ +package com.vaadin.tests.elements.table; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.ui.Table; + +public class TableScroll extends AbstractTestUI { + + Table table; + public static final int COLUMNS = 5; + public static final int ROWS = 100; + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setWidth("200px"); + layout.setHeight("200px"); + + Table table = new Table(); + table.setWidth("200px"); + table.setHeight("200px"); + initProperties(table); + fillTable(table); + layout.addComponent(table); + addComponent(layout); + } + + @Override + protected String getTestDescription() { + return "Test table element scroll and scrollLeft"; + } + + @Override + protected Integer getTicketNumber() { + return 13826; + } + + // set up the properties (columns) + private void initProperties(Table table) { + for (int i = 0; i < COLUMNS; i++) { + table.addContainerProperty("property" + i, String.class, + "some value"); + } + } + + // fill the table with some random data + private void fillTable(Table table) { + initProperties(table); + for (int i = 0; i < ROWS; i++) { + String[] line = new String[COLUMNS]; + for (int j = 0; j < COLUMNS; j++) { + line[j] = "col=" + j + " row=" + i; + } + table.addItem(line, null); + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/NestedTabSheet.java b/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/NestedTabSheet.java new file mode 100644 index 00000000000..375d75148e0 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/NestedTabSheet.java @@ -0,0 +1,57 @@ +/* + * 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.elements.tabsheet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.TabSheet; + +/** + * This UI contains a nested tab sheet, i.e., there is a tab sheet that contains + * other tab sheets as its components. + */ +public class NestedTabSheet extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + TabSheet outer = new TabSheet(); + TabSheet firstInner = new TabSheet(); + firstInner.addTab(new CssLayout(), "Tab 1.1"); + firstInner.addTab(new CssLayout(), "Tab 1.2"); + firstInner.addTab(new CssLayout(), "Tab 1.3"); + TabSheet secondInner = new TabSheet(); + secondInner.addTab(new CssLayout(), "Tab 2.1"); + TabSheet thirdInner = new TabSheet(); + thirdInner.addTab(new CssLayout(), "Tab 3.1"); + thirdInner.addTab(new CssLayout(), "Tab 3.2"); + outer.addTab(firstInner, "Tab 1"); + outer.addTab(secondInner, "Tab 2"); + outer.addTab(thirdInner, "Tab 3"); + addComponent(outer); + } + + @Override + protected String getTestDescription() { + return "TestBench should not select tabs from an inner tab sheet in" + + " calls involving the outer tab sheet."; + } + + @Override + protected Integer getTicketNumber() { + return 13735; + } +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/TabSheetElementException.java b/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/TabSheetElementException.java new file mode 100644 index 00000000000..6a610dc718a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/TabSheetElementException.java @@ -0,0 +1,48 @@ +/* + * 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.elements.tabsheet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.TabSheet; + +/** + * this UI is used for testing that an exception occurs when TestBench attempts + * to open a tab that does not exist. + */ +public class TabSheetElementException extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + TabSheet ts = new TabSheet(); + for (int i = 1; i <= 5; i++) { + ts.addTab(new CssLayout(), "Tab " + i); + } + addComponent(ts); + } + + @Override + protected String getTestDescription() { + return "Tests that an exception is thrown when TestBench attempts to" + + " click a tab that does not exist."; + } + + @Override + protected Integer getTicketNumber() { + return 13734; + } +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/TabSheetElementTabWithoutCaption.java b/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/TabSheetElementTabWithoutCaption.java new file mode 100644 index 00000000000..048baf74042 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/tabsheet/TabSheetElementTabWithoutCaption.java @@ -0,0 +1,74 @@ +/* + * 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.elements.tabsheet; + +import com.vaadin.server.ThemeResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Component; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.Tab; + +public class TabSheetElementTabWithoutCaption extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + // Create a tab sheet with a tab having no caption + TabSheet ts = new TabSheet(); + Tab newTab; + for (int i = 1; i <= 5; i++) { + Component c = createTabContent(i); + if (i != 3) { + newTab = ts.addTab(c, "Tab " + i); + } else { + newTab = ts.addTab(c); + } + newTab.setClosable(true); + } + addComponent(ts); + // Create a tab sheet that has icons instead of text captions + TabSheet ts2 = new TabSheet(); + newTab = ts2.addTab(createTabContent(10), null, new ThemeResource( + "favicon.ico")); + newTab.setClosable(true); + newTab = ts2.addTab(createTabContent(11), null, new ThemeResource( + "window/img/maximize.png")); + newTab.setClosable(false); + newTab = ts2.addTab(createTabContent(12)); + newTab.setClosable(false); + newTab = ts2.addTab(createTabContent(12)); + newTab.setClosable(true); + newTab = ts2.addTab(createTabContent(13), null, new ThemeResource( + "window/img/restore.png")); + newTab.setClosable(true); + addComponent(ts2); + } + + @Override + protected String getTestDescription() { + return "The methods of TabSheetElement should not fail when there are tabs without a caption."; + } + + @Override + protected Integer getTicketNumber() { + return 14434; + } + + private Label createTabContent(int index) { + return new Label("This is tab " + index); + } +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/elements/treetable/TreeTableElementExpandRow.java b/uitest/src/main/java/com/vaadin/tests/elements/treetable/TreeTableElementExpandRow.java new file mode 100644 index 00000000000..cde3fc794ba --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/treetable/TreeTableElementExpandRow.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.elements.treetable; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.TreeTable; + +public class TreeTableElementExpandRow extends AbstractTestUI { + + + TreeTable treeTable = new TreeTable(); + public static final String TEST_VALUE = "testValue"; + + @Override + protected void setup(VaadinRequest request) { + treeTable.setWidth("200px"); + treeTable.addContainerProperty("Name", String.class, ""); + treeTable.addItem(new Object[] { "item1" }, "item1"); + treeTable.addItem(new Object[] { "item1_1" }, "item1_1"); + treeTable.addItem(new Object[] { "item1_2" }, "item1_2"); + treeTable.setParent("item1_1", "item1"); + treeTable.setParent("item1_2", "item1"); + treeTable.addItem(new Object[] { TEST_VALUE }, TEST_VALUE); + addComponent(treeTable); + + } + + @Override + protected String getTestDescription() { + return "Test TreeTableRowElement toggleExpanded() method expands/collapses the row."; + } + + @Override + protected Integer getTicketNumber() { + return 13773; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/twincolselect/TwinColSelectUI.java b/uitest/src/main/java/com/vaadin/tests/elements/twincolselect/TwinColSelectUI.java new file mode 100644 index 00000000000..9bb4bb2aebc --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/twincolselect/TwinColSelectUI.java @@ -0,0 +1,58 @@ +package com.vaadin.tests.elements.twincolselect; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.event.selection.MultiSelectionEvent; +import com.vaadin.event.selection.MultiSelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.TwinColSelect; + +public class TwinColSelectUI extends AbstractTestUI { + + Label multiCounterLbl = new Label(); + + @Override + protected void setup(VaadinRequest request) { + TwinColSelect twinColSelect = new TwinColSelect<>(); + multiCounterLbl.setValue("0"); + List options = new ArrayList<>(); + options.add("item1"); + options.add("item2"); + options.add("item3"); + twinColSelect.setItems(options); + twinColSelect.select("item1"); + twinColSelect.addSelectionListener(new CounterListener(0)); + + addComponent(twinColSelect); + multiCounterLbl.setId("multiCounterLbl"); + addComponent(multiCounterLbl); + + } + + @Override + protected String getTestDescription() { + return "Test that user can pick option from ListSelectElement by call click() method"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + + private class CounterListener implements MultiSelectionListener { + int counter = 0; + + public CounterListener(int i) { + counter = i; + } + + @Override + public void selectionChange(MultiSelectionEvent event) { + counter++; + multiCounterLbl.setValue("" + counter + ": " + event.getValue()); + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/elements/window/WindowUI.java b/uitest/src/main/java/com/vaadin/tests/elements/window/WindowUI.java new file mode 100644 index 00000000000..0cdde86ba46 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/elements/window/WindowUI.java @@ -0,0 +1,33 @@ +package com.vaadin.tests.elements.window; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window; + +public class WindowUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Window window = new Window(); + + window.setCaption("Some caption"); + window.center(); + + window.setWidth("200px"); + window.setHeight("200px"); + + window.setContent(new Label("Hello world")); + addWindow(window); + } + + @Override + protected String getTestDescription() { + return "Test UI for Window element API"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityComponentElementGetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityComponentElementGetValueTest.java new file mode 100644 index 00000000000..28ed259840a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityComponentElementGetValueTest.java @@ -0,0 +1,126 @@ +package com.vaadin.tests.elements; + +import java.text.SimpleDateFormat; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractTextFieldElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.ListSelectElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.testbench.elements.OptionGroupElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/* + * 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. + */ + +public class CompatibilityComponentElementGetValueTest extends MultiBrowserTest { + + @Before + public void init() { + openTestURL(); + } + + @Test + public void checkComboBox() { + ComboBoxElement elem = $(ComboBoxElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkListSelect() { + ListSelectElement elem = $(ListSelectElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkNativeSelect() { + NativeSelectElement elem = $(NativeSelectElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkOptionGroup() { + OptionGroupElement elem = $(OptionGroupElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkTwinColSelect() { + TwinColSelectElement elem = $(TwinColSelectElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkTextField() { + TextFieldElement elem = $(TextFieldElement.class).get(0); + checkValue(elem); + } + + @Test + public void checkTextArea() { + TextAreaElement elem = $(TextAreaElement.class).get(0); + checkValue(elem); + } + + @Test + public void checkPassword() { + PasswordFieldElement elem = $(PasswordFieldElement.class).get(0); + checkValue(elem); + } + + @Test + public void checkCheckBox() { + CheckBoxElement cb = $(CheckBoxElement.class).get(0); + String expected = "checked"; + String actual = cb.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkDateField() { + DateFieldElement df = $(DateFieldElement.class).get(0); + SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); + String expected = format1 + .format(CompatibilityComponentElementGetValue.TEST_DATE_VALUE); + String actual = df.getValue(); + Assert.assertEquals(expected, actual); + } + + private void checkValue(AbstractTextFieldElement elem) { + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBaseTest.java b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBaseTest.java new file mode 100644 index 00000000000..9a1dfa99b41 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionBaseTest.java @@ -0,0 +1,136 @@ +package com.vaadin.tests.elements; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractComponentElement; +import com.vaadin.testbench.elements.AbstractLayoutElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.ColorPickerElement; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.ListSelectElement; +import com.vaadin.testbench.elements.OptionGroupElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.TreeElement; +import com.vaadin.testbench.elements.TreeTableElement; +import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/* + * 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. + */ + +/** + * + * Test class which have test methods for all components added in the testUI + * class. Open TestURL is called only once before tests. Parent class should + * override protected Class getUIClass() to specify which testUI should be + * used + */ + +public abstract class CompatibilityElementComponentGetCaptionBaseTest + extends MultiBrowserTest { + AbstractLayoutElement mainLayout; + + @Before + public void init() { + openTestURL(); + } + + @Test + public void getComboboxCaptionTest() { + ComboBoxElement elem = mainLayout.$(ComboBoxElement.class).get(0); + testCaption(elem, 0); + } + + @Test + public void getTableCaptionTest() { + TableElement elem = mainLayout.$(TableElement.class).get(0); + testCaption(elem, 1); + } + + @Test + public void getTreeTableCaptionTest() { + TreeTableElement elem = mainLayout.$(TreeTableElement.class).get(0); + testCaption(elem, 2); + } + + @Test + public void getTreeCaptionTest() { + TreeElement elem = mainLayout.$(TreeElement.class).get(0); + testCaption(elem, 3); + } + + @Test + public void getTwinColSelectCaptionTest() { + TwinColSelectElement elem = mainLayout.$(TwinColSelectElement.class) + .get(0); + testCaption(elem, 4); + } + + @Test + public void getOptionGroupCaptionTest() { + OptionGroupElement elem = mainLayout.$(OptionGroupElement.class).get(0); + testCaption(elem, 5); + } + + @Test + public void getListSelectCaptionTest() { + ListSelectElement elem = mainLayout.$(ListSelectElement.class).get(0); + testCaption(elem, 6); + } + + @Test + public void getColorPickerCaptionTest() { + ColorPickerElement elem = mainLayout.$(ColorPickerElement.class).get(0); + testCaption(elem, 7); + } + + @Test + public void getCheckBoxCaptionTest() { + CheckBoxElement elem = mainLayout.$(CheckBoxElement.class).get(0); + testCaption(elem, 8); + } + + @Test + public void getTextFieldCaptionTest() { + TextFieldElement elem = mainLayout.$(TextFieldElement.class).get(0); + testCaption(elem, 9); + } + + @Test + public void getTextAreaCaptionTest() { + TextAreaElement elem = mainLayout.$(TextAreaElement.class).get(0); + testCaption(elem, 10); + } + + @Test + public void getDateFieldCaptionTest() { + DateFieldElement elem = mainLayout.$(DateFieldElement.class).get(0); + testCaption(elem, 11); + } + + private void testCaption(AbstractComponentElement elem, int caption_index) { + String actual = elem.getCaption(); + String expected = CompatibilityElementComponentGetCaptionBase.DEFAULT_CAPTIONS[caption_index]; + Assert.assertTrue("Error with class:" + elem.getAttribute("class"), + expected.equals(actual)); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionCssLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionCssLayoutTest.java new file mode 100644 index 00000000000..223020a9a34 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionCssLayoutTest.java @@ -0,0 +1,32 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.CssLayoutElement; + +public class CompatibilityElementComponentGetCaptionCssLayoutTest + extends CompatibilityElementComponentGetCaptionBaseTest { + @Override + protected Class getUIClass() { + return CompatibilityElementComponentGetCaptionCssLayout.class; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + mainLayout = $(CssLayoutElement.class).get(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionFormLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionFormLayoutTest.java new file mode 100644 index 00000000000..3780a1619bd --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionFormLayoutTest.java @@ -0,0 +1,32 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.FormLayoutElement; + +public class CompatibilityElementComponentGetCaptionFormLayoutTest + extends CompatibilityElementComponentGetCaptionBaseTest { + @Override + protected Class getUIClass() { + return CompatibilityElementComponentGetCaptionFormLayout.class; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + mainLayout = $(FormLayoutElement.class).get(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionGridLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionGridLayoutTest.java new file mode 100644 index 00000000000..8509841b22d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionGridLayoutTest.java @@ -0,0 +1,32 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.GridLayoutElement; + +public class CompatibilityElementComponentGetCaptionGridLayoutTest + extends CompatibilityElementComponentGetCaptionBaseTest { + @Override + protected Class getUIClass() { + return CompatibilityElementComponentGetCaptionGridLayout.class; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + mainLayout = $(GridLayoutElement.class).get(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionHorizontalTest.java b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionHorizontalTest.java new file mode 100644 index 00000000000..4d8144b458c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionHorizontalTest.java @@ -0,0 +1,33 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.HorizontalLayoutElement; + +public class CompatibilityElementComponentGetCaptionHorizontalTest + extends CompatibilityElementComponentGetCaptionBaseTest { + + @Override + protected Class getUIClass() { + return CompatibilityElementComponentGetCaptionHorizontal.class; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + mainLayout = $(HorizontalLayoutElement.class).get(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionVerticalLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionVerticalLayoutTest.java new file mode 100644 index 00000000000..fbe94c830ec --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/CompatibilityElementComponentGetCaptionVerticalLayoutTest.java @@ -0,0 +1,32 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.VerticalLayoutElement; + +public class CompatibilityElementComponentGetCaptionVerticalLayoutTest + extends CompatibilityElementComponentGetCaptionBaseTest { + @Override + protected Class getUIClass() { + return CompatibilityElementComponentGetCaptionVerticalLayout.class; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + mainLayout = $(VerticalLayoutElement.class).get(2); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ComponentElementGetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ComponentElementGetValueTest.java new file mode 100644 index 00000000000..26c42961577 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ComponentElementGetValueTest.java @@ -0,0 +1,138 @@ +package com.vaadin.tests.elements; + +import java.time.format.DateTimeFormatter; +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractTextFieldElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.CheckBoxGroupElement; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.ListSelectElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.testbench.elements.RadioButtonGroupElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/* + * 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. + */ + +public class ComponentElementGetValueTest extends MultiBrowserTest { + + @Before + public void init() { + openTestURL(); + } + + @Test + public void checkComboBox() { + ComboBoxElement elem = $(ComboBoxElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkListSelect() { + ListSelectElement elem = $(ListSelectElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkNativeSelect() { + NativeSelectElement elem = $(NativeSelectElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkCheckBoxGroup() { + CheckBoxGroupElement elem = $(CheckBoxGroupElement.class).get(0); + List expected = Collections + .singletonList(ComponentElementGetValue.TEST_STRING_VALUE); + List actual = elem.getSelection(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkRadioButtonGroup() { + RadioButtonGroupElement elem = $(RadioButtonGroupElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkTwinColSelect() { + TwinColSelectElement elem = $(TwinColSelectElement.class).get(0); + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkTextField() { + TextFieldElement elem = $(TextFieldElement.class).get(0); + checkValue(elem); + } + + @Test + public void checkTextArea() { + TextAreaElement elem = $(TextAreaElement.class).get(0); + checkValue(elem); + } + + @Test + public void checkPassword() { + PasswordFieldElement elem = $(PasswordFieldElement.class).get(0); + checkValue(elem); + } + + @Test + public void checkCheckBox() { + CheckBoxElement cb = $(CheckBoxElement.class).get(0); + String expected = "checked"; + String actual = cb.getValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void checkDateField() { + DateFieldElement df = $(DateFieldElement.class).get(0); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String expected = formatter + .format(ComponentElementGetValue.TEST_DATE_VALUE); + String actual = df.getValue(); + Assert.assertEquals(expected, actual); + } + + private void checkValue(AbstractTextFieldElement elem) { + String expected = ComponentElementGetValue.TEST_STRING_VALUE; + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionBaseTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionBaseTest.java new file mode 100644 index 00000000000..c52341ec763 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionBaseTest.java @@ -0,0 +1,196 @@ +package com.vaadin.tests.elements; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractComponentElement; +import com.vaadin.testbench.elements.AbstractLayoutElement; +import com.vaadin.testbench.elements.AccordionElement; +import com.vaadin.testbench.elements.BrowserFrameElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.CheckBoxGroupElement; +import com.vaadin.testbench.elements.ColorPickerElement; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.FlashElement; +import com.vaadin.testbench.elements.FormLayoutElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridLayoutElement; +import com.vaadin.testbench.elements.HorizontalLayoutElement; +import com.vaadin.testbench.elements.ImageElement; +import com.vaadin.testbench.elements.ListSelectElement; +import com.vaadin.testbench.elements.RadioButtonGroupElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.testbench.elements.VerticalLayoutElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/* + * 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. + */ + +/** + * + * Test class which have test methods for all components added in the testUI + * class. Open TestURL is called only once before tests. Parent class should + * override protected Class getUIClass() to specify which testUI should be + * used + */ + +public abstract class ElementComponentGetCaptionBaseTest + extends MultiBrowserTest { + AbstractLayoutElement mainLayout; + + @Before + public void init() { + openTestURL(); + } + + @Test + public void getComboboxCaptionTest() { + ComboBoxElement elem = mainLayout.$(ComboBoxElement.class).get(0); + testCaption(elem, 0); + } + + @Test + public void getButtonCaptionTest() { + ButtonElement elem = mainLayout.$(ButtonElement.class).get(0); + testCaption(elem, 1); + } + + @Test + public void getGridCaptionTest() { + GridElement elem = mainLayout.$(GridElement.class).get(0); + testCaption(elem, 2); + } + + @Test + public void getCheckBoxGroupCaptionTest() { + CheckBoxGroupElement elem = mainLayout.$(CheckBoxGroupElement.class) + .get(0); + testCaption(elem, 3); + } + + @Test + public void getRadioButtonGroupCaptionTest() { + RadioButtonGroupElement elem = mainLayout + .$(RadioButtonGroupElement.class).get(0); + testCaption(elem, 4); + } + + @Test + public void getTwinColSelectCaptionTest() { + TwinColSelectElement elem = mainLayout.$(TwinColSelectElement.class) + .get(0); + testCaption(elem, 5); + } + + @Test + public void getListSelectCaptionTest() { + ListSelectElement elem = mainLayout.$(ListSelectElement.class).get(0); + testCaption(elem, 6); + } + + @Test + public void getColorPickerCaptionTest() { + ColorPickerElement elem = mainLayout.$(ColorPickerElement.class).get(0); + testCaption(elem, 7); + } + + @Test + public void getAccordionCaptionTest() { + AccordionElement elem = mainLayout.$(AccordionElement.class).get(0); + testCaption(elem, 8); + } + + @Test + public void getImageCaptionTest() { + ImageElement elem = mainLayout.$(ImageElement.class).get(0); + testCaption(elem, 9); + } + + @Test + public void getFlashCaptionTest() { + FlashElement elem = mainLayout.$(FlashElement.class).get(0); + testCaption(elem, 10); + } + + @Test + public void getBrowserFrameCaptionTest() { + BrowserFrameElement elem = mainLayout.$(BrowserFrameElement.class) + .get(0); + testCaption(elem, 11); + } + + @Test + public void getCheckBoxCaptionTest() { + CheckBoxElement elem = mainLayout.$(CheckBoxElement.class).get(0); + testCaption(elem, 12); + } + + @Test + public void getTextFieldCaptionTest() { + TextFieldElement elem = mainLayout.$(TextFieldElement.class).get(0); + testCaption(elem, 13); + } + + @Test + public void getTextAreaCaptionTest() { + TextAreaElement elem = mainLayout.$(TextAreaElement.class).get(0); + testCaption(elem, 14); + } + + @Test + public void getDateFieldCaptionTest() { + DateFieldElement elem = mainLayout.$(DateFieldElement.class).get(0); + testCaption(elem, 15); + } + + @Test + public void getVerticalLayoutCaptionTest() { + VerticalLayoutElement elem = mainLayout.$(VerticalLayoutElement.class) + .get(0); + testCaption(elem, 16); + } + + @Test + public void getHorizontalLayoutCaptionTest() { + HorizontalLayoutElement elem = mainLayout + .$(HorizontalLayoutElement.class).get(0); + testCaption(elem, 17); + } + + @Test + public void getFormLayoutCaptionTest() { + FormLayoutElement elem = mainLayout.$(FormLayoutElement.class).get(0); + testCaption(elem, 18); + } + + @Test + public void getGridLayoutCaptionTest() { + GridLayoutElement elem = mainLayout.$(GridLayoutElement.class).get(0); + testCaption(elem, 19); + } + + private void testCaption(AbstractComponentElement elem, int caption_index) { + String actual = elem.getCaption(); + String expected = ElementComponentGetCaptionBase.DEFAULT_CAPTIONS[caption_index]; + Assert.assertTrue("Error with class:" + elem.getAttribute("class"), + expected.equals(actual)); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionCssLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionCssLayoutTest.java new file mode 100644 index 00000000000..2abcc33d4d3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionCssLayoutTest.java @@ -0,0 +1,32 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.CssLayoutElement; + +public class ElementComponentGetCaptionCssLayoutTest + extends ElementComponentGetCaptionBaseTest { + @Override + protected Class getUIClass() { + return ElementComponentGetCaptionCssLayout.class; + } + + @Override + protected void openTestURL() { + openTestURL("theme=reindeer"); + mainLayout = $(CssLayoutElement.class).get(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionFormLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionFormLayoutTest.java new file mode 100644 index 00000000000..fed112f4393 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionFormLayoutTest.java @@ -0,0 +1,32 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.FormLayoutElement; + +public class ElementComponentGetCaptionFormLayoutTest + extends ElementComponentGetCaptionBaseTest { + @Override + protected Class getUIClass() { + return ElementComponentGetCaptionFormLayout.class; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + mainLayout = $(FormLayoutElement.class).get(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionGridLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionGridLayoutTest.java new file mode 100644 index 00000000000..9ac667b5a31 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionGridLayoutTest.java @@ -0,0 +1,32 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.GridLayoutElement; + +public class ElementComponentGetCaptionGridLayoutTest + extends ElementComponentGetCaptionBaseTest { + @Override + protected Class getUIClass() { + return ElementComponentGetCaptionGridLayout.class; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + mainLayout = $(GridLayoutElement.class).get(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionHorizontalTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionHorizontalTest.java new file mode 100644 index 00000000000..5b32c86b66f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionHorizontalTest.java @@ -0,0 +1,33 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.HorizontalLayoutElement; + +public class ElementComponentGetCaptionHorizontalTest + extends ElementComponentGetCaptionBaseTest { + + @Override + protected Class getUIClass() { + return ElementComponentGetCaptionHorizontal.class; + } + + @Override + protected void openTestURL() { + super.openTestURL(); + mainLayout = $(HorizontalLayoutElement.class).get(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionVerticalLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionVerticalLayoutTest.java new file mode 100644 index 00000000000..cf8c573198f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ElementComponentGetCaptionVerticalLayoutTest.java @@ -0,0 +1,32 @@ +/* + * 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.elements; + +import com.vaadin.testbench.elements.VerticalLayoutElement; + +public class ElementComponentGetCaptionVerticalLayoutTest + extends ElementComponentGetCaptionBaseTest { + @Override + protected Class getUIClass() { + return ElementComponentGetCaptionVerticalLayout.class; + } + + @Override + protected void openTestURL() { + openTestURL("theme=reindeer"); + mainLayout = $(VerticalLayoutElement.class).get(2); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ElementExistsTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ElementExistsTest.java new file mode 100644 index 00000000000..f30fd5d5b00 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ElementExistsTest.java @@ -0,0 +1,60 @@ +/* + * 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.elements; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ElementExistsTest extends MultiBrowserTest { + @Test + public void testExistsWithoutUI() { + // Test that an exists query does not throw an exception even when the + // initialization of the UI has not been done (#14808). + boolean buttonExists = $(ButtonElement.class).exists(); + assertFalse( + "$(ButtonElement.class).exists() returned true, but there should be no buttons.", + buttonExists); + buttonExists = $(ButtonElement.class).caption("b").exists(); + assertFalse( + "$(ButtonElement.class).caption(\"b\").exists() returned true, " + + "but there should be no buttons.", + buttonExists); + } + + @Test + public void testExistsWithUI() { + // Test the expected case where the UI has been properly set up. + openTestURL(); + boolean buttonExists = $(ButtonElement.class).exists(); + assertTrue( + "No button was found, although one should be present in the UI.", + buttonExists); + buttonExists = $(ButtonElement.class).caption("b").exists(); + assertTrue( + "No button with caption 'b' was found, although one should be present in the UI.", + buttonExists); + buttonExists = $(ButtonElement.class).caption("Button 2").exists(); + assertFalse( + "$(ButtonElement.class).caption(\"Button 2\") returned true, but " + + "there should be no button with that caption.", + buttonExists); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ElementQueryUITest.java b/uitest/src/test/java/com/vaadin/tests/elements/ElementQueryUITest.java new file mode 100644 index 00000000000..b8f3d8d2075 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/ElementQueryUITest.java @@ -0,0 +1,29 @@ +package com.vaadin.tests.elements; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ElementQueryUITest extends MultiBrowserTest { + + @Test + public void firstGetAllLast() { + openTestURL(); + Assert.assertEquals("Button 0", + $(ButtonElement.class).first().getCaption()); + Assert.assertEquals("Button 9", + $(ButtonElement.class).last().getCaption()); + + List all = $(ButtonElement.class).all(); + + for (int i = 0; i < 10; i++) { + Assert.assertEquals("Button " + i, all.get(i).getCaption()); + Assert.assertEquals("Button " + i, + $(ButtonElement.class).get(i).getCaption()); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/TestBenchElementClearValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/TestBenchElementClearValueTest.java new file mode 100644 index 00000000000..9237a541e0d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/TestBenchElementClearValueTest.java @@ -0,0 +1,168 @@ +/* + * 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.elements; + +import java.time.format.DateTimeFormatter; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractTextFieldElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.CheckBoxGroupElement; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.ListSelectElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.testbench.elements.RadioButtonGroupElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test clear method. Checks that value of the component was changed both on + * client and server side Testing of the client side done by comparing first + * with initial value then calling clear and comparing with empty value. Testing + * of the server side by checking that changeValue even was raised on the server + * side. Each element has changeValue listener added in the UI class. Compare + * labelChangeValue value with the value used in the listener of the UI class. + * + * @since + * @author Vaadin Ltd + */ + +public class TestBenchElementClearValueTest extends MultiBrowserTest { + // The label text is changed on element component ValueChange event + // Used to test that element.clear() method has actually triggered the + // server side code + private LabelElement labelChangeValue; + + // use same TestUI class as for getValue method + @Override + protected Class getUIClass() { + return ComponentElementGetValue.class; + } + + @Before + public void init() { + openTestURL(); + labelChangeValue = $(LabelElement.class).get(1); + } + + @Test + public void clearTextField() { + TextFieldElement elem = $(TextFieldElement.class).get(0); + checkElementValue(elem); + Assert.assertEquals(ComponentElementGetValue.FIELD_VALUES[0], + labelChangeValue.getText()); + } + + @Test + public void clearTextArea() { + TextAreaElement elem = $(TextAreaElement.class).get(0); + checkElementValue(elem); + Assert.assertEquals(ComponentElementGetValue.FIELD_VALUES[1], + labelChangeValue.getText()); + } + + @Test + public void clearPasswordField() { + PasswordFieldElement elem = $(PasswordFieldElement.class).get(0); + checkElementValue(elem); + Assert.assertEquals(ComponentElementGetValue.FIELD_VALUES[2], + labelChangeValue.getText()); + } + + @Test + public void clearDateField() { + DateFieldElement df = $(DateFieldElement.class).get(0); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String expected = formatter + .format(ComponentElementGetValue.TEST_DATE_VALUE); + String initial = df.getValue(); + Assert.assertEquals(expected, initial); + df.clear(); + Assert.assertEquals("", df.getValue()); + Assert.assertEquals(ComponentElementGetValue.DATEFIELD_VALUE_CHANGE, + labelChangeValue.getText()); + } + + // Clear method should do not raise exception + public void clearComboBox() { + ComboBoxElement elem = $(ComboBoxElement.class).get(0); + elem.clear(); + } + + public void clearNativeSelect() { + NativeSelectElement elem = $(NativeSelectElement.class).get(0); + elem.clear(); + } + + public void clearListSelect() { + ListSelectElement elem = $(ListSelectElement.class).get(0); + elem.clear(); + } + + public void clearCheckBoxGroup() { + CheckBoxGroupElement elem = $(CheckBoxGroupElement.class).get(0); + elem.clear(); + } + + public void clearRadioButtonGroup() { + RadioButtonGroupElement elem = $(RadioButtonGroupElement.class).get(0); + elem.clear(); + } + + @Test + public void clearCheckBox() { + CheckBoxElement elem = $(CheckBoxElement.class).get(0); + elem.clear(); + Assert.assertTrue(elem.getValue().equals("unchecked")); + Assert.assertEquals(ComponentElementGetValue.CHECKBOX_VALUE_CHANGE, + labelChangeValue.getText()); + } + + @Test + public void clearTwinCol() { + TwinColSelectElement elem = $(TwinColSelectElement.class).get(0); + elem.clear(); + Assert.assertEquals("", elem.getValue()); + Assert.assertEquals(ComponentElementGetValue.MULTI_SELECT_VALUE_CHANGE, + labelChangeValue.getText()); + } + + // helper functions + private void checkElementValue(AbstractTextFieldElement elem) { + String initial = ComponentElementGetValue.TEST_STRING_VALUE; + checkElementValue(elem, initial); + } + + private void checkElementValue(AbstractTextFieldElement elem, + String expected) { + // check initial element value + String actual = elem.getValue(); + Assert.assertEquals(expected, actual); + // check cleared element value + elem.clear(); + expected = ""; + actual = elem.getValue(); + Assert.assertEquals(expected, actual); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/TestBenchElementRightClickTest.java b/uitest/src/test/java/com/vaadin/tests/elements/TestBenchElementRightClickTest.java new file mode 100644 index 00000000000..866776c70bc --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/TestBenchElementRightClickTest.java @@ -0,0 +1,41 @@ +package com.vaadin.tests.elements; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TestBenchElementRightClickTest extends MultiBrowserTest { + TestBenchElement cell; + LabelElement label; + + @Before + public void init() { + openTestURL(); + cell = $(TableElement.class).id("id1").getCell(1, 1); + label = $(LabelElement.class).id("label1"); + } + + @Test + public void testTableRightClick() { + cell.contextClick(); + String actual = label.getText(); + String expected = "RightClick"; + Assert.assertEquals("TestBenchElement right click fails", expected, + actual); + + } + + @Test + public void testTableDoubleClick() { + cell.doubleClick(); + String actual = label.getText(); + String expected = "DoubleClick"; + Assert.assertEquals("TestBenchElement double click fails", expected, + actual); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/TreeElementGetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/TreeElementGetValueTest.java new file mode 100644 index 00000000000..c7c0915dee7 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/TreeElementGetValueTest.java @@ -0,0 +1,37 @@ +/* + * 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.elements; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.TreeElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TreeElementGetValueTest extends MultiBrowserTest { + @Before + public void init() { + openTestURL(); + } + + @Test + public void testGetValue() { + TreeElement tree = $(TreeElement.class).get(0); + Assert.assertEquals(tree.getValue(), + TreeElementGetValue.TEST_VALUE_LVL2); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractFieldElementSetValueReadOnlyTest.java b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractFieldElementSetValueReadOnlyTest.java new file mode 100644 index 00000000000..28c6980fdbc --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractFieldElementSetValueReadOnlyTest.java @@ -0,0 +1,119 @@ +package com.vaadin.tests.elements.abstracttextfield; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractComponentElement.ReadOnlyException; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.CheckBoxGroupElement; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.ListSelectElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.testbench.elements.RadioButtonGroupElement; +import com.vaadin.testbench.elements.RichTextAreaElement; +import com.vaadin.testbench.elements.SliderElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class AbstractFieldElementSetValueReadOnlyTest extends MultiBrowserTest { + + @Before + public void init() { + openTestURL(); + } + + @Test(expected = ReadOnlyException.class) + public void testNativeSelect() { + NativeSelectElement elem = $(NativeSelectElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testCheckBoxGroup() { + CheckBoxGroupElement elem = $(CheckBoxGroupElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testRadioButtonGroup() { + RadioButtonGroupElement elem = $(RadioButtonGroupElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testTextField() { + TextFieldElement elem = $(TextFieldElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testTextArea() { + TextAreaElement elem = $(TextAreaElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testPasswordField() { + PasswordFieldElement elem = $(PasswordFieldElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testDateField() { + DateFieldElement elem = $(DateFieldElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testCheckBox() { + CheckBoxElement elem = $(CheckBoxElement.class).first(); + elem.click(); + } + + @Ignore("SliderElement.setValue does not exist") + @Test(expected = ReadOnlyException.class) + public void testSlider() { + $(SliderElement.class).first(); + } + + @Test(expected = ReadOnlyException.class) + public void testListSelect() { + ListSelectElement elem = $(ListSelectElement.class).first(); + elem.selectByText("foo"); + } + + @Test(expected = ReadOnlyException.class) + public void testListSelectDeselect() { + ListSelectElement elem = $(ListSelectElement.class).first(); + elem.deselectByText("foo"); + } + + @Ignore("RichTextAreaElement does not have a setValue") + @Test(expected = ReadOnlyException.class) + public void testRichTextArea() { + $(RichTextAreaElement.class).first(); + } + + @Test(expected = ReadOnlyException.class) + public void testTwinColSelect() { + TwinColSelectElement elem = $(TwinColSelectElement.class).first(); + elem.selectByText("foo"); + } + + @Test(expected = ReadOnlyException.class) + public void testTwinColSelectDeselect() { + TwinColSelectElement elem = $(TwinColSelectElement.class).first(); + elem.deselectByText("foo"); + } + + @Test(expected = ReadOnlyException.class) + public void testComboBox() { + ComboBoxElement elem = $(ComboBoxElement.class).first(); + elem.selectByText("foo"); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java new file mode 100644 index 00000000000..012b4605f21 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java @@ -0,0 +1,88 @@ +/* + * 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.elements.abstracttextfield; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractTextFieldElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class AbstractTextElementSetValueTest extends MultiBrowserTest { + private final static String TYPED_STRING = "this is typed string"; + + @Before + public void init() { + openTestURL(); + } + + @Test + public void textFieldSetValue() { + checkType($(TextFieldElement.class).get(0), + $(LabelElement.class).get(1)); + } + + @Test + public void passwordFieldSetValue() { + checkType($(PasswordFieldElement.class).get(0), + $(LabelElement.class).get(2)); + } + + @Test + public void textAreaSetValue() { + checkType($(TextAreaElement.class).get(0), + $(LabelElement.class).get(3)); + } + + @Test + public void dateFieldSetValue() { + DateFieldElement elem = $(DateFieldElement.class).get(0); + LabelElement eventCount = $(LabelElement.class).get(4); + // we can type any string in date field element + elem.setValue(TYPED_STRING); + // invalid values are cleared from the field + Assert.assertEquals("", elem.getValue()); + Assert.assertEquals("1", eventCount.getText()); + } + + // helper methods + // checks that setValue method works + private void checkType(AbstractTextFieldElement elem, + LabelElement eventCount) { + // check first that the initial value is set + Assert.assertEquals(AbstractTextElementSetValue.INITIAL_VALUE, + elem.getValue()); + elem.setValue(TYPED_STRING); + + // check that typed value is the same + Assert.assertEquals(TYPED_STRING, elem.getValue()); + + // checks that there was only one change value event + Assert.assertEquals("1", eventCount.getText()); + + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractFieldElementSetValueReadOnlyTest.java b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractFieldElementSetValueReadOnlyTest.java new file mode 100644 index 00000000000..771b2996fc2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractFieldElementSetValueReadOnlyTest.java @@ -0,0 +1,113 @@ +package com.vaadin.tests.elements.abstracttextfield; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractComponentElement.ReadOnlyException; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.ListSelectElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.testbench.elements.OptionGroupElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.testbench.elements.RichTextAreaElement; +import com.vaadin.testbench.elements.SliderElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CompatibilityAbstractFieldElementSetValueReadOnlyTest + extends MultiBrowserTest { + + @Before + public void init() { + openTestURL(); + } + + @Test(expected = ReadOnlyException.class) + public void testNativeSelect() { + NativeSelectElement elem = $(NativeSelectElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testOptionGroup() { + OptionGroupElement elem = $(OptionGroupElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testTextField() { + TextFieldElement elem = $(TextFieldElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testTextArea() { + TextAreaElement elem = $(TextAreaElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testPasswordField() { + PasswordFieldElement elem = $(PasswordFieldElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testDateField() { + DateFieldElement elem = $(DateFieldElement.class).first(); + elem.setValue(""); + } + + @Test(expected = ReadOnlyException.class) + public void testCheckBox() { + CheckBoxElement elem = $(CheckBoxElement.class).first(); + elem.click(); + } + + @Ignore("SliderElement.setValue does not exist") + @Test(expected = ReadOnlyException.class) + public void testSlider() { + $(SliderElement.class).first(); + } + + @Test(expected = ReadOnlyException.class) + public void testListSelect() { + ListSelectElement elem = $(ListSelectElement.class).first(); + elem.selectByText("foo"); + } + + @Test(expected = ReadOnlyException.class) + public void testListSelectDeselect() { + ListSelectElement elem = $(ListSelectElement.class).first(); + elem.deselectByText("foo"); + } + + @Ignore("RichTextAreaElement does not have a setValue") + @Test(expected = ReadOnlyException.class) + public void testRichTextArea() { + RichTextAreaElement elem = $(RichTextAreaElement.class).first(); + } + + @Test(expected = ReadOnlyException.class) + public void testTwinColSelect() { + TwinColSelectElement elem = $(TwinColSelectElement.class).first(); + elem.selectByText("foo"); + } + + @Test(expected = ReadOnlyException.class) + public void testTwinColSelectDeselect() { + TwinColSelectElement elem = $(TwinColSelectElement.class).first(); + elem.deselectByText("foo"); + } + + @Test(expected = ReadOnlyException.class) + public void testComboBox() { + ComboBoxElement elem = $(ComboBoxElement.class).first(); + elem.selectByText("foo"); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractTextElementSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractTextElementSetValueTest.java new file mode 100644 index 00000000000..c7f4b8d11e0 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/CompatibilityAbstractTextElementSetValueTest.java @@ -0,0 +1,84 @@ +/* + * 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.elements.abstracttextfield; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.AbstractTextFieldElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.testbench.elements.TextAreaElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CompatibilityAbstractTextElementSetValueTest + extends MultiBrowserTest { + private final static String TYPED_STRING = "this is typed string"; + + @Before + public void init() { + openTestURL(); + } + + @Test + public void textFieldSetValue() { + checkType($(TextFieldElement.class).get(0), + $(LabelElement.class).get(1)); + } + + @Test + public void passwordFieldSetValue() { + checkType($(PasswordFieldElement.class).get(0), + $(LabelElement.class).get(2)); + } + + @Test + public void textAreaSetValue() { + checkType($(TextAreaElement.class).get(0), + $(LabelElement.class).get(3)); + } + + @Test + public void dateFieldSetValue() { + DateFieldElement elem = $(DateFieldElement.class).get(0); + LabelElement eventCount = $(LabelElement.class).get(4); + // we can type any string in date field element + elem.setValue(TYPED_STRING); + Assert.assertEquals(TYPED_STRING, elem.getValue()); + Assert.assertEquals("1", eventCount.getText()); + } + + // helper methods + // checks that setValue method works + private void checkType(AbstractTextFieldElement elem, + LabelElement eventCount) { + // check first that the initial value is set + Assert.assertEquals( + CompatibilityAbstractTextElementSetValue.INITIAL_VALUE, + elem.getValue()); + elem.setValue(TYPED_STRING); + + // check that typed value is the same + Assert.assertEquals(TYPED_STRING, elem.getValue()); + + // checks that there was only one change value event + Assert.assertEquals("1", eventCount.getText()); + + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/button/ButtonUITest.java b/uitest/src/test/java/com/vaadin/tests/elements/button/ButtonUITest.java new file mode 100644 index 00000000000..c5a166f8f57 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/button/ButtonUITest.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.elements.button; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ButtonUITest extends MultiBrowserTest { + @Before + public void init() { + openTestURL(); + } + + @Test + public void testButtonWithQUIETStyle() { + ButtonElement button = $(ButtonElement.class) + .id(ButtonUI.QUIET_BUTTON_ID); + TextFieldElement field = $(TextFieldElement.class).first(); + button.click(); + Assert.assertEquals("Clicked", field.getValue()); + } + + @Test + public void testButtonWithQUIETStyleNoCaption() { + ButtonElement button = $(ButtonElement.class) + .id(ButtonUI.QUIET_BUTTON_NO_CAPTION_ID); + TextFieldElement field = $(TextFieldElement.class).first(); + button.click(); + Assert.assertEquals("Clicked", field.getValue()); + } + + @Test + public void testButton_clickButtonWithSleep_TextFieldWorkAsExpected() { + openTestURL(); + ButtonElement button = $(ButtonElement.class) + .id(ButtonUI.NORMAL_BUTTON_ID); + TextFieldElement field = $(TextFieldElement.class) + .id(ButtonUI.TEXT_FIELD_ID); + button.click(); + Assert.assertEquals("Clicked", field.getValue()); + } + + @Test + public void testButton_clickButtonWithSleep_LabelWorkAsExpected() { + openTestURL(); + ButtonElement button = $(ButtonElement.class) + .id(ButtonUI.NORMAL_BUTTON_ID); + LabelElement label = $(LabelElement.class).id(ButtonUI.LABEL_ID); + button.click(); + + Assert.assertEquals("Clicked", label.getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/calendar/CalendarNavigationTest.java b/uitest/src/test/java/com/vaadin/tests/elements/calendar/CalendarNavigationTest.java new file mode 100644 index 00000000000..d9d497798b3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/calendar/CalendarNavigationTest.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.elements.calendar; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.CalendarElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CalendarNavigationTest extends MultiBrowserTest { + + private CalendarElement calendarElement; + + @Override + protected Class getUIClass() { + return CalendarUI.class; + } + + @Before + public void init() { + openTestURL(); + calendarElement = $(CalendarElement.class).first(); + } + + @Test + public void calendarNavigation_backAndForwardInWeekView_navigationWorks() { + assertTrue(calendarElement.hasWeekView()); + String originalFirstDay = calendarElement.getDayHeaders().get(0) + .getText(); + + calendarElement.back(); + calendarElement.waitForVaadin(); + assertNotEquals(originalFirstDay, + calendarElement.getDayHeaders().get(0).getText()); + + calendarElement.next(); + calendarElement.waitForVaadin(); + + assertEquals(originalFirstDay, + calendarElement.getDayHeaders().get(0).getText()); + } + + @Test(expected = IllegalStateException.class) + public void calendarNavigation_navigationInMonthView_exceptionThrown() { + $(ButtonElement.class).get(0).click(); + calendarElement.waitForVaadin(); + + assertTrue(calendarElement.hasMonthView()); + + calendarElement.next(); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/checkbox/ClickCheckBoxUITest.java b/uitest/src/test/java/com/vaadin/tests/elements/checkbox/ClickCheckBoxUITest.java new file mode 100644 index 00000000000..8d28c490cb9 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/checkbox/ClickCheckBoxUITest.java @@ -0,0 +1,55 @@ +/* + * 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.elements.checkbox; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Testcase used to validate {@link CheckBoxElement#click()} works as expected. + * See #13763 + */ +public class ClickCheckBoxUITest extends MultiBrowserTest { + + @Before + public void init() { + openTestURL(); + } + + @Test + public void testClickToggleCheckboxMark() { + CheckBoxElement checkboxWithLabel = $(CheckBoxElement.class).first(); + CheckBoxElement checkboxWithoutLabel = $(CheckBoxElement.class).last(); + assertFalse(checkboxWithLabel.isChecked()); + assertFalse(checkboxWithoutLabel.isChecked()); + + checkboxWithLabel.click(); + assertTrue(checkboxWithLabel.isChecked()); + checkboxWithoutLabel.click(); + assertTrue(checkboxWithoutLabel.isChecked()); + + checkboxWithLabel.click(); + assertFalse(checkboxWithLabel.isChecked()); + checkboxWithoutLabel.click(); + assertFalse(checkboxWithoutLabel.isChecked()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/checkboxgroup/CheckBoxGroupSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/checkboxgroup/CheckBoxGroupSetValueTest.java new file mode 100644 index 00000000000..c18e8a10a60 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/checkboxgroup/CheckBoxGroupSetValueTest.java @@ -0,0 +1,39 @@ +package com.vaadin.tests.elements.checkboxgroup; + +import java.util.Collections; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.CheckBoxGroupElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CheckBoxGroupSetValueTest extends MultiBrowserTest { + + private static final String NEW_VALUE = "item2"; + + private CheckBoxGroupElement group; + + @Before + public void init() { + openTestURL(); + group = $(CheckBoxGroupElement.class).first(); + + } + + @Test + public void testSetValue() { + group.setValue(NEW_VALUE); + Assert.assertEquals(Collections.singletonList(NEW_VALUE), + group.getSelection()); + } + + @Test + public void testSelectByText() { + group.selectByText(NEW_VALUE); + Assert.assertEquals(Collections.singletonList(NEW_VALUE), + group.getSelection()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxGetSuggestionsTest.java b/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxGetSuggestionsTest.java new file mode 100644 index 00000000000..1a527d8e9a3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxGetSuggestionsTest.java @@ -0,0 +1,24 @@ +package com.vaadin.tests.elements.combobox; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ComboBoxGetSuggestionsTest extends MultiBrowserTest { + @Test + public void testSuggestions() { + openTestURL(); + ComboBoxElement cb = $(ComboBoxElement.class).get(0); + List suggestions = cb.getPopupSuggestions(); + List expectedSuggestions = new ArrayList(); + for (int i = 1; i < 11; i++) { + expectedSuggestions.add("item" + i); + } + Assert.assertEquals(expectedSuggestions, suggestions); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxInputNotAllowedTest.java b/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxInputNotAllowedTest.java new file mode 100644 index 00000000000..f05572e9506 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxInputNotAllowedTest.java @@ -0,0 +1,38 @@ +package com.vaadin.tests.elements.combobox; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ComboBoxInputNotAllowedTest extends MultiBrowserTest { + + @Test + public void selectByTextComboBoxWithTextInputDisabled_invalidSelection() { + openTestURL(); + ComboBoxElement cb = $(ComboBoxElement.class).first(); + cb.selectByText("Foobar"); + } + + @Test + public void selectByTextComboBoxWithTextInputDisabled() { + openTestURL(); + ComboBoxElement cb = $(ComboBoxElement.class).first(); + + String[] optionsToTest = new String[] { + ComboBoxInputNotAllowed.ITEM_ON_FIRST_PAGE, + ComboBoxInputNotAllowed.ITEM_ON_SECOND_PAGE, + ComboBoxInputNotAllowed.ITEM_ON_LAST_PAGE, + ComboBoxInputNotAllowed.ITEM_LAST_WITH_PARENTHESIS, + ComboBoxInputNotAllowed.ITEM_ON_FIRST_PAGE }; + + for (String option : optionsToTest) { + cb.selectByText(option); + Assert.assertEquals("Value is now: " + option, + $(LabelElement.class).last().getText()); + Assert.assertEquals(option, cb.getValue()); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxPopupTest.java b/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxPopupTest.java new file mode 100644 index 00000000000..8dde197067e --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxPopupTest.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.elements.combobox; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ComboBoxPopupTest extends MultiBrowserTest { + + private ComboBoxElement comboBoxElement; + + @Override + protected Class getUIClass() { + return ComboBoxUI.class; + } + + @Before + public void init() { + openTestURL(); + comboBoxElement = $(ComboBoxElement.class).first(); + } + + @Test + public void comboBoxPopup_popupOpen_popupFetchedSuccessfully() { + comboBoxElement.openPopup(); + + assertNotNull(comboBoxElement.getSuggestionPopup()); + } + + @Test + public void comboBoxPopup_popupClosed_popupFetchedSuccessfully() { + assertNotNull(comboBoxElement.getSuggestionPopup()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxUITest.java b/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxUITest.java new file mode 100644 index 00000000000..fb84ea3055d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/combobox/ComboBoxUITest.java @@ -0,0 +1,68 @@ +/* + * 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.elements.combobox; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Validates that multiple calls to ComboBoxElement.selectByText(String) do not + * append the input given each time to the previous one. The value in the + * combobox's search field should be cleared before searching for a new one. + */ +public class ComboBoxUITest extends MultiBrowserTest { + + @Before + public void init() { + openTestURL(); + } + + @Test + public void testMultipleSelectByTextOperationsAllowingNullSelection() { + ComboBoxElement cb = $(ComboBoxElement.class).first(); + testMultipleSelectByTextOperationsIn(cb); + } + + @Test + public void testMultipleSelectByTextOperationsForbiddingNullSelection() { + ComboBoxElement cb = $(ComboBoxElement.class).get(1); + testMultipleSelectByTextOperationsIn(cb); + } + + @Test + public void testSelectByTextNotFound() { + ComboBoxElement cb = $(ComboBoxElement.class).first(); + cb.selectByText("foobar"); + } + + private void testMultipleSelectByTextOperationsIn( + ComboBoxElement comboBox) { + // Select all items from the menu + for (String currency : ComboBoxUI.currencies) { + comboBox.selectByText(currency); + + // Check that the value was selected as the input value of the CB + WebElement input = comboBox.getInputField(); + assertEquals(currency, input.getAttribute("value")); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/combobox/SelectByTextTest.java b/uitest/src/test/java/com/vaadin/tests/elements/combobox/SelectByTextTest.java new file mode 100644 index 00000000000..7c65872d173 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/combobox/SelectByTextTest.java @@ -0,0 +1,89 @@ +/* + * 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.elements.combobox; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Validates ComboBox.selectByText(String s) works properly if input String s + * contains parentheses + */ +public class SelectByTextTest extends MultiBrowserTest { + + @Before + public void init() { + openTestURL(); + } + + private void selectAndAssertValue(String text) { + ComboBoxElement comboBox = $(ComboBoxElement.class).first(); + comboBox.selectByText(text); + + assertEquals(text, getComboBoxValue()); + assertEquals("Value is now '" + text + "'", + $(LabelElement.class).last().getText()); + } + + @Test + public void selectByParenthesesOnly() { + selectAndAssertValue("("); + } + + @Test + public void selectByStartingParentheses() { + selectAndAssertValue("(Value"); + } + + @Test + public void selectByFinishingParentheses() { + selectAndAssertValue("Value("); + } + + @Test + public void selectByRegularParentheses() { + selectAndAssertValue("Value(i)"); + } + + @Test + public void selectByComplexParenthesesCase() { + selectAndAssertValue( + "((Test ) selectByTest() method(with' parentheses)(("); + } + + private String getComboBoxValue() { + ComboBoxElement comboBox = $(ComboBoxElement.class).first(); + WebElement textbox = comboBox.findElement(By.vaadin("#textbox")); + return textbox.getAttribute("value"); + } + + @Test + public void selectSharedPrefixOption() { + for (String text : new String[] { "Value 2", "Value 22", + "Value 222" }) { + selectAndAssertValue(text); + } + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/datefield/DateFieldPopupSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/datefield/DateFieldPopupSetValueTest.java new file mode 100644 index 00000000000..831ec1371ab --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/datefield/DateFieldPopupSetValueTest.java @@ -0,0 +1,50 @@ +package com.vaadin.tests.elements.datefield; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.PopupDateFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DateFieldPopupSetValueTest extends MultiBrowserTest { + + LabelElement counter; + PopupDateFieldElement dfPopup; + DateFieldElement df; + + @Before + public void init() { + openTestURL(); + counter = $(LabelElement.class).id("counter"); + df = $(DateFieldElement.class).first(); + } + + @Test + public void testGetValue() { + String value = df.getValue(); + Assert.assertEquals("04/12/15", value); + } + + @Test + public void testSetValue() { + Date date = DateFieldPopupSetValue.changedDate; + String value = (new SimpleDateFormat("MM/dd/yy")).format(date); + df.setValue(value); + Assert.assertEquals("06/11/15", df.getValue()); + } + + @Test + public void testValueChanged() { + Date date = DateFieldPopupSetValue.changedDate; + String value = (new SimpleDateFormat("MM/dd/yy")).format(date); + df.setValue(value); + counter.waitForVaadin(); + Assert.assertEquals("1", counter.getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/grid/GridDetailsTest.java b/uitest/src/test/java/com/vaadin/tests/elements/grid/GridDetailsTest.java new file mode 100644 index 00000000000..17f5d867e2e --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/grid/GridDetailsTest.java @@ -0,0 +1,42 @@ +package com.vaadin.tests.elements.grid; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.NoSuchElementException; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridDetailsTest extends MultiBrowserTest { + + private GridElement gridElement; + + @Override + protected Class getUIClass() { + return GridUI.class; + } + + @Before + public void init() { + openTestURL(); + gridElement = $(GridElement.class).first(); + } + + @Test + public void gridDetails_gridDetailsOpen_elementReturned() { + gridElement.getCell(0, 0).doubleClick(); + + final TestBenchElement details = gridElement.getDetails(0); + assertEquals("Foo = foo 0 Bar = bar 0", + details.$(LabelElement.class).first().getText()); + } + + @Test(expected = NoSuchElementException.class) + public void gridDetails_gridDetailsClosed_exceptionThrown() { + gridElement.getDetails(0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/grid/GridUITest.java b/uitest/src/test/java/com/vaadin/tests/elements/grid/GridUITest.java new file mode 100644 index 00000000000..dc3a49eafe0 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/grid/GridUITest.java @@ -0,0 +1,53 @@ +package com.vaadin.tests.elements.grid; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridUITest extends MultiBrowserTest { + + @Test + public void testRowCount() { + openTestURL("rowCount=0"); + Assert.assertEquals(0, getRowCount()); + openTestURL("rowCount=1&restartApplication"); + Assert.assertEquals(1, getRowCount()); + openTestURL("rowCount=10&restartApplication"); + Assert.assertEquals(10, getRowCount()); + openTestURL("rowCount=1000&restartApplication"); + Assert.assertEquals(1000, getRowCount()); + } + + private long getRowCount() { + return $(GridElement.class).first().getRowCount(); + } + + private Iterable getRows() { + return $(GridElement.class).first().getRows(); + } + + @Test + public void testGetRows() { + openTestURL("rowCount=0"); + Assert.assertEquals(0, checkRows()); + openTestURL("rowCount=1&restartApplication"); + Assert.assertEquals(1, checkRows()); + openTestURL("rowCount=10&restartApplication"); + Assert.assertEquals(10, checkRows()); + openTestURL("rowCount=100&restartApplication"); + Assert.assertEquals(100, checkRows()); + } + + private int checkRows() { + int rowCount = 0; + for (final GridRowElement row : getRows()) { + Assert.assertEquals("foo " + rowCount, row.getCell(0).getText()); + Assert.assertEquals("bar " + rowCount, row.getCell(1).getText()); + rowCount++; + } + return rowCount; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/link/LinkUITest.java b/uitest/src/test/java/com/vaadin/tests/elements/link/LinkUITest.java new file mode 100644 index 00000000000..1560dc64d51 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/link/LinkUITest.java @@ -0,0 +1,38 @@ +package com.vaadin.tests.elements.link; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.LinkElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class LinkUITest extends MultiBrowserTest { + LinkElement link; + + @Before + public void init() { + openTestURL(); + link = $(LinkElement.class).first(); + } + + @Test + public void testLinkClick() { + String currentUrl = getDriver().getCurrentUrl(); + Assert.assertTrue( + "Current URL " + currentUrl + " should end with LinkUI?", + currentUrl.endsWith("LinkUI")); + link.click(); + currentUrl = getDriver().getCurrentUrl(); + Assert.assertFalse( + "Current URL " + currentUrl + " should not end with LinkUI?", + currentUrl.endsWith("LinkUI")); + + } + + @Test + public void getLinkCaption() { + Assert.assertEquals("server root", link.getCaption()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/listselect/ListSelectOptionClickTest.java b/uitest/src/test/java/com/vaadin/tests/elements/listselect/ListSelectOptionClickTest.java new file mode 100644 index 00000000000..ce7eca6322d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/listselect/ListSelectOptionClickTest.java @@ -0,0 +1,78 @@ +package com.vaadin.tests.elements.listselect; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.ListSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ListSelectOptionClickTest extends MultiBrowserTest { + ListSelectElement select; + LabelElement counterLbl; + + @Before + public void init() { + openTestURL(); + select = $(ListSelectElement.class).first(); + counterLbl = $(LabelElement.class).id("multiCounterLbl"); + } + + @Test + @Ignore("depends on framework8-issues/issues/464 fix") + public void testOptionClick() { + List options = select.findElements(By.tagName("option")); + WebElement option = options.get(1); + option.click(); + checkValueChanged(); + } + + @Test + @Ignore("depends on framework8-issues/issues/464 fix") + public void testSelectByText() { + select.selectByText("item2"); + checkValueChanged(); + } + + @Test + public void testMultiSelectDeselectByText() { + select.selectByText("item2"); + Assert.assertEquals("1: [item1, item2]", counterLbl.getText()); + select.selectByText("item3"); + Assert.assertEquals("2: [item1, item2, item3]", counterLbl.getText()); + select.deselectByText("item2"); + Assert.assertEquals("3: [item1, item3]", counterLbl.getText()); + } + + @Test + public void testDeselectSelectByText() { + select.deselectByText("item1"); + Assert.assertEquals("1: []", counterLbl.getText()); + select.selectByText("item1"); + Assert.assertEquals("2: [item1]", counterLbl.getText()); + select.selectByText("item3"); + Assert.assertEquals("3: [item1, item3]", counterLbl.getText()); + select.deselectByText("item1"); + Assert.assertEquals("4: [item3]", counterLbl.getText()); + } + + /* + * Checks that value has changed. Checks that the change event was fired + * once. + */ + private void checkValueChanged() { + String actual = select.getValue(); + String actualCounter = counterLbl.getText(); + Assert.assertEquals("The value of the ListSelect has not changed", + "item2", actual); + Assert.assertEquals( + "The number of list select valueChange events is not one.", + "1: item2", actualCounter); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/menubar/MenuBarUITest.java b/uitest/src/test/java/com/vaadin/tests/elements/menubar/MenuBarUITest.java new file mode 100644 index 00000000000..dc960f4d49f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/menubar/MenuBarUITest.java @@ -0,0 +1,141 @@ +/* + * 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.elements.menubar; + +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 { + + @Before + public void init() { + openTestURL(); + } + + // Tests against bug #14568 + @Test + public void testClickTopLevelItemHavingSubmenuItemFocused() { + MenuBarElement menuBar = $(MenuBarElement.class).first(); + + menuBar.clickItem("File"); + assertTrue(isItemVisible("Export..")); + + menuBar.clickItem("Export.."); + assertTrue(isItemVisible("As PDF...")); + + menuBar.clickItem("File"); + assertFalse(isItemVisible("Export..")); + } + + /** + * Validates clickItem(String) of MenuBarElement. + */ + @Test + public void testMenuBarClick() { + MenuBarElement menuBar = $(MenuBarElement.class).first(); + + menuBar.clickItem("File"); + assertTrue(isItemVisible("Save As..")); + + menuBar.clickItem("Export.."); + 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"); + menuBar.clickItem("Edit"); + assertFalse(isItemVisible("Save As..")); + assertTrue(isItemVisible("Paste")); + + menuBar.clickItem("Edit"); + assertFalse(isItemVisible("Save As..")); + assertFalse(isItemVisible("Paste")); + + menuBar.clickItem("Edit"); + assertFalse(isItemVisible("Save As..")); + assertTrue(isItemVisible("Paste")); + + // Menu does not contain a submenu, no need to click twice. + menuBar.clickItem("Help"); + assertFalse(isItemVisible("Save As..")); + assertFalse(isItemVisible("Paste")); + + // No submenu is open, so click only once to open the File menu. + menuBar.clickItem("File"); + assertTrue(isItemVisible("Save As..")); + } + + /** + * Validates menuBar.clickItem(String...) feature. + */ + @Test + public void testMenuBarClickPath() { + MenuBarElement menuBar = $(MenuBarElement.class).first(); + menuBar.clickItem("File", "Export.."); + 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"); + assertTrue(isItemVisible("Open2")); + // Close the menu item + menuBar.clickItem("File"); + + menuBar = $(MenuBarElement.class).get(1); + menuBar.clickItem("Edit2"); + assertTrue(isItemVisible("Cut")); + menuBar.clickItem("Edit2"); + + menuBar = $(MenuBarElement.class).first(); + menuBar.clickItem("File"); + assertTrue(isItemVisible("Open")); + } + + 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 getItemCaptions() { + return findElements(By.className("v-menubar-menuitem-caption")); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/nativeselect/NativeSelectSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/nativeselect/NativeSelectSetValueTest.java new file mode 100644 index 00000000000..0ce358e7278 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/nativeselect/NativeSelectSetValueTest.java @@ -0,0 +1,42 @@ +package com.vaadin.tests.elements.nativeselect; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class NativeSelectSetValueTest extends MultiBrowserTest { + + NativeSelectElement select; + LabelElement counter; + + @Before + public void init() { + openTestURL(); + select = $(NativeSelectElement.class).get(0); + counter = $(LabelElement.class).id("counter"); + } + + @Test + public void testSetValue() throws InterruptedException { + select.setValue("item 2"); + checkTestValue(); + } + + @Test + public void testSelectByText() { + select.selectByText("item 2"); + checkTestValue(); + } + + private void checkTestValue() { + // checks value has changed + String actual = select.getValue(); + Assert.assertEquals("item 2", actual); + // checks change value event occures + Assert.assertEquals("1", counter.getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationCloseTest.java b/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationCloseTest.java new file mode 100644 index 00000000000..2640c1a5e78 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationCloseTest.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.elements.notification; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class NotificationCloseTest extends MultiBrowserTest { + + @Override + protected Class getUIClass() { + return NotificationGetTypeAndDescription.class; + } + + @Test + public void testWarning() { + testClose(0); + } + + @Test + public void testError() { + testClose(1); + } + + @Test + public void testHumanized() { + testClose(2); + } + + @Test + public void testTrayNotification() { + testClose(3); + } + + private void testClose(int index) { + openTestURL(); + String id = "button" + index; + ButtonElement btn = $(ButtonElement.class).id(id); + // show notification + btn.click(); + $(NotificationElement.class).get(0).close(); + List notifications = $(NotificationElement.class) + .all(); + // check that all notifications are closed + Assert.assertTrue("There are open notifications", + notifications.isEmpty()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescriptionTest.java b/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescriptionTest.java new file mode 100644 index 00000000000..ae0ea0e7570 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescriptionTest.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.elements.notification; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class NotificationGetTypeAndDescriptionTest extends MultiBrowserTest { + @Test + public void testWarning() { + testNotificationByIndex(0); + } + + @Test + public void testError() { + testNotificationByIndex(1); + } + + @Test + public void testHumanized() { + testNotificationByIndex(2); + } + + @Test + public void testTrayNotification() { + testNotificationByIndex(3); + } + + // helper method find button by index click and test the notification + // This method tests caption, description and type of the notification + private void testNotificationByIndex(int index) { + openTestURL(); + String id = "button" + index; + ButtonElement btn = $(ButtonElement.class).id(id); + btn.click(); + NotificationElement notification = $(NotificationElement.class).get(0); + String eCaption = NotificationGetTypeAndDescription.captions[index]; + String aCaption = notification.getCaption(); + Assert.assertEquals("Test captions fail", eCaption, aCaption); + String eDescription = NotificationGetTypeAndDescription.descriptions[index]; + String aDescription = notification.getDescription(); + Assert.assertEquals("Test descriptions fail", eDescription, + aDescription); + String eType = NotificationGetTypeAndDescription.type_names[index]; + String aType = notification.getType(); + Assert.assertEquals("Test types fail", eType, aType); + + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/optiongroup/OptionGroupSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/optiongroup/OptionGroupSetValueTest.java new file mode 100644 index 00000000000..a4fc3932db8 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/optiongroup/OptionGroupSetValueTest.java @@ -0,0 +1,34 @@ +package com.vaadin.tests.elements.optiongroup; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.OptionGroupElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class OptionGroupSetValueTest extends MultiBrowserTest { + + private static final String NEW_VALUE = "item2"; + + private OptionGroupElement group; + + @Before + public void init() { + openTestURL(); + group = $(OptionGroupElement.class).first(); + } + + @Test + public void testSetValue() { + group.setValue(NEW_VALUE); + Assert.assertEquals(NEW_VALUE, group.getValue()); + } + + @Test + public void testSelectByText() { + group.selectByText(NEW_VALUE); + Assert.assertEquals(NEW_VALUE, group.getValue()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/panel/PanelScrollTest.java b/uitest/src/test/java/com/vaadin/tests/elements/panel/PanelScrollTest.java new file mode 100644 index 00000000000..97b35b2e63f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/panel/PanelScrollTest.java @@ -0,0 +1,43 @@ +package com.vaadin.tests.elements.panel; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.PanelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class PanelScrollTest extends MultiBrowserTest { + private static final int SCROLL_VALUE = 300; + + @Test + public void testScrollLeft() throws InterruptedException { + openTestURL(); + PanelElement panel = $(PanelElement.class).get(0); + panel.scrollLeft(SCROLL_VALUE); + Assert.assertEquals(SCROLL_VALUE, getScrollLeftValue(panel)); + } + + @Test + public void testScrollTop() { + openTestURL(); + PanelElement panel = $(PanelElement.class).get(0); + panel.scroll(SCROLL_VALUE); + Assert.assertEquals(SCROLL_VALUE, getScrollTopValue(panel)); + } + + // helper functions + private int getScrollTopValue(WebElement elem) { + Long scrollTop = (Long) executeScript( + "return arguments[0].getElementsByClassName(\"v-scrollable\")[0].scrollTop;", + elem); + return scrollTop.intValue(); + } + + private int getScrollLeftValue(WebElement elem) { + Long scrollTop = (Long) executeScript( + "return arguments[0].getElementsByClassName(\"v-scrollable\")[0].scrollLeft;", + elem); + return scrollTop.intValue(); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/progressbar/ProgressBarValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/progressbar/ProgressBarValueTest.java new file mode 100644 index 00000000000..cd2c6c10463 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/progressbar/ProgressBarValueTest.java @@ -0,0 +1,32 @@ +package com.vaadin.tests.elements.progressbar; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.ProgressBarElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ProgressBarValueTest extends MultiBrowserTest { + + @Override + protected Class getUIClass() { + return ProgressBarUI.class; + } + + @Before + public void init() { + openTestURL(); + } + + @Test + public void progressBar_differentValues_valuesFetchedCorrectly() { + assertEquals(1, $(ProgressBarElement.class).id("complete").getValue(), + 0); + assertEquals(0.5, + $(ProgressBarElement.class).id("halfComplete").getValue(), 0); + assertEquals(0, $(ProgressBarElement.class).id("notStarted").getValue(), + 0); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/radiobuttongroup/RadioButtonGroupSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/radiobuttongroup/RadioButtonGroupSetValueTest.java new file mode 100644 index 00000000000..03bc2d83798 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/radiobuttongroup/RadioButtonGroupSetValueTest.java @@ -0,0 +1,34 @@ +package com.vaadin.tests.elements.radiobuttongroup; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.RadioButtonGroupElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class RadioButtonGroupSetValueTest extends MultiBrowserTest { + + private static final String NEW_VALUE = "item2"; + + private RadioButtonGroupElement group; + + @Before + public void init() { + openTestURL(); + group = $(RadioButtonGroupElement.class).first(); + } + + @Test + public void testSetValue() { + group.setValue(NEW_VALUE); + Assert.assertEquals(NEW_VALUE, group.getValue()); + } + + @Test + public void testSelectByText() { + group.selectByText(NEW_VALUE); + Assert.assertEquals(NEW_VALUE, group.getValue()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/slider/SliderGetHandleTest.java b/uitest/src/test/java/com/vaadin/tests/elements/slider/SliderGetHandleTest.java new file mode 100644 index 00000000000..bd4e567b705 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/slider/SliderGetHandleTest.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.elements.slider; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.SliderElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class SliderGetHandleTest extends MultiBrowserTest { + + @Test + public void testGetHandle() { + openTestURL(); + + // get second slider, to check that getHandler get the handler + // of the correct slider, not of the very first one + SliderElement slider = $(SliderElement.class).get(1); + WebElement handle = slider.getHandle(); + slider.isDisplayed(); + handle.isDisplayed(); + // Handle has 0*0 size in Valo theme and requires some special treatment + ((JavascriptExecutor) driver).executeScript( + "function simulate(f,c,d,e){var b,a=null;for(b in eventMatchers)if(eventMatchers[b].test(c)){a=b;break}if(!a)return!1;document.createEvent?(b=document.createEvent(a),a==\"HTMLEvents\"?b.initEvent(c,!0,!0):b.initMouseEvent(c,!0,!0,document.defaultView,0,d,e,d,e,!1,!1,!1,!1,0,null),f.dispatchEvent(b)):(a=document.createEventObject(),a.detail=0,a.screenX=d,a.screenY=e,a.clientX=d,a.clientY=e,a.ctrlKey=!1,a.altKey=!1,a.shiftKey=!1,a.metaKey=!1,a.button=1,f.fireEvent(\"on\"+c,a));return!0} var eventMatchers={HTMLEvents:/^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,MouseEvents:/^(?:click|dblclick|mouse(?:down|up|over|move|out))$/}; " + + "simulate(arguments[0],\"mousedown\",0,0); simulate(arguments[0],\"mousemove\",arguments[1],arguments[2]); simulate(arguments[0],\"mouseup\",arguments[1],arguments[2]); ", + handle, handle.getLocation().x + 10, 0); + // action to do the same test using a theme other than Valo + // new Actions(driver).clickAndHold(handle).moveByOffset(10, + // 0).release().perform(); + + String initial = "" + (int) SliderGetHandle.INITIAL_VALUE; + String actual = slider.getValue(); + Assert.assertNotEquals(initial, actual); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/slider/SliderGetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/slider/SliderGetValueTest.java new file mode 100644 index 00000000000..ef41ab8a0fe --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/slider/SliderGetValueTest.java @@ -0,0 +1,30 @@ +package com.vaadin.tests.elements.slider; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.SliderElement; +import com.vaadin.tests.elements.ComponentElementGetValue; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class SliderGetValueTest extends MultiBrowserTest { + + @Override + protected Class getUIClass() { + return ComponentElementGetValue.class; + } + + @Before + public void init() { + openTestURL(); + } + + @Test + public void checkSlider() { + SliderElement pb = $(SliderElement.class).get(0); + String expected = "" + ComponentElementGetValue.TEST_SLIDER_VALUE; + String actual = pb.getValue(); + Assert.assertEquals(expected, actual); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/splitpanel/SplitPanelComponentsTest.java b/uitest/src/test/java/com/vaadin/tests/elements/splitpanel/SplitPanelComponentsTest.java new file mode 100644 index 00000000000..68842d21599 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/splitpanel/SplitPanelComponentsTest.java @@ -0,0 +1,149 @@ +/* + * 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.elements.splitpanel; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.HorizontalSplitPanelElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.VerticalSplitPanelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * This class contains tests for checking that the methods getFirstComponent() + * and getSecondComponent() of AbstractSplitPanelElement return the correct + * components also when the split panel only has a second component. See #14073 + * and #14075. + * + */ +public class SplitPanelComponentsTest extends MultiBrowserTest { + + @Before + public void init() { + openTestURL(); + } + + @Test + public void getSecondInHorizontalSplitPanel() throws Exception { + HorizontalSplitPanelElement sp = $(HorizontalSplitPanelElement.class) + .first(); + LabelElement label = sp.getSecondComponent(LabelElement.class); + String labelText = label.getText(); + assertTrue("The second component of the split panel should be a label" + + " containing the text 'Label 1.2'. Actual text: " + labelText, + "Label 1.2".equals(labelText)); + } + + @Test + public void getSecondInVerticalSplitPanel() throws Exception { + VerticalSplitPanelElement sp = $(VerticalSplitPanelElement.class) + .first(); + LabelElement label = sp.getSecondComponent(LabelElement.class); + String labelText = label.getText(); + assertTrue("The second component of the split panel should be a label" + + " containing the text 'Label 2.2'. Actual text: " + labelText, + "Label 2.2".equals(labelText)); + } + + @Test + public void getFirstInHorizontalSplitPanel() throws Exception { + HorizontalSplitPanelElement sp = $(HorizontalSplitPanelElement.class) + .first(); + LabelElement label = null; + // There is no first component, so allow an exception. + try { + label = sp.getFirstComponent(LabelElement.class); + } catch (Exception e) { + } + String labelText = label == null ? "" : label.getText(); + assertTrue( + "The split panel should not have a first component. Found a label with" + + " text " + labelText, + label == null); + } + + @Test + public void getFirstInVerticalSplitPanel() throws Exception { + VerticalSplitPanelElement sp = $(VerticalSplitPanelElement.class) + .first(); + LabelElement label = null; + // There is no first component, so allow an exception. + try { + label = sp.getFirstComponent(LabelElement.class); + } catch (Exception e) { + } + String labelText = label == null ? "" : label.getText(); + assertTrue( + "The split panel should not have a first component. Found a label with" + + " text " + labelText, + label == null); + } + + @Test + public void getElementsInSplitPanelWithBothComponents() throws Exception { + // This test is for regression checking - getFirst and getSecond + // should work also when the split panel has both components. + HorizontalSplitPanelElement sp = $(HorizontalSplitPanelElement.class) + .get(1); + LabelElement label1 = sp.getFirstComponent(LabelElement.class); + String label1Text = label1.getText(); + assertTrue("The first component of the split panel should be a label" + + " containing the text 'Label 3.1'. Actual text: " + + label1Text, "Label 3.1".equals(label1Text)); + LabelElement label2 = sp.getSecondComponent(LabelElement.class); + String label2Text = label2.getText(); + assertTrue("The second component of the split panel should be a label" + + " containing the text 'Label 3.2'. Actual text: " + + label2Text, "Label 3.2".equals(label2Text)); + } + + @Test + public void getFirstInSplitPanelWithFirstComponent() throws Exception { + // This test is for regression checking - getFirst should also work + // in a tab sheet with only the second component. + VerticalSplitPanelElement sp = $(VerticalSplitPanelElement.class) + .get(1); + ButtonElement button = sp.getFirstComponent(ButtonElement.class); + String buttonText = button.getText(); + assertTrue( + "The first component of the split panel should be a button labeled \"Button\"." + + " Actual label: " + buttonText, + "Button".equals(buttonText)); + } + + @Test + public void getSecondInSplitPanelWithFirstComponent() throws Exception { + // This test is for regression checking - getSecond should not return a + // non-null element in a tab sheet with only the second component. + VerticalSplitPanelElement sp = $(VerticalSplitPanelElement.class) + .get(1); + ButtonElement button = null; + // There is no second component, so allow an exception. + try { + button = sp.getSecondComponent(ButtonElement.class); + } catch (Exception e) { + } + String buttonText = button == null ? "" : button.getText(); + assertTrue( + "The split panel should not have a second component. Found a button with" + + " text " + buttonText, + button == null); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/elements/table/GetRowHeaderTest.java b/uitest/src/test/java/com/vaadin/tests/elements/table/GetRowHeaderTest.java new file mode 100644 index 00000000000..742fd339474 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/table/GetRowHeaderTest.java @@ -0,0 +1,101 @@ +package com.vaadin.tests.elements.table; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.testbench.elements.TableHeaderElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GetRowHeaderTest extends MultiBrowserTest { + + TableElement table; + private static final int COLUMN_INDEX = 0; + + @Override + protected Class getUIClass() { + return TableScroll.class; + } + + @Before + public void init() { + openTestURL(); + table = $(TableElement.class).first(); + } + + @Test + public void testGetRowHeaderCaption() { + TableHeaderElement header = table.getHeaderCell(COLUMN_INDEX); + String expected = "property0"; + String actual = header.getCaption(); + Assert.assertEquals( + "TableHeaderElement.getCaption() returns wrong value.", + expected, actual); + } + + // Test that clicking on the header sorts the column + @Test + public void testTableRowHeaderSort() { + TableHeaderElement header = table.getHeaderCell(COLUMN_INDEX); + // sort in asc order + header.click(); + table.waitForVaadin(); + // sort in desc order + header.click(); + table.waitForVaadin(); + String expected = "col=0 row=99"; + String actual = table.getCell(0, COLUMN_INDEX).getText(); + Assert.assertEquals( + "TableHeaderElement.toggleSort() did not sort column " + + COLUMN_INDEX, + expected, actual); + } + + @Test + public void testTableRowHeaderGetHandle() { + TableHeaderElement header = table.getHeaderCell(COLUMN_INDEX); + int initialWidth = header.getSize().width; + WebElement handle = header.getResizeHandle(); + Actions builder = new Actions(getDriver()); + /* + * To workaround a bug with clicking on small elements(not precise + * cursor positioning) in IE we do the following: 1. Extend the resize + * handle element (it's initial width is 3) 2. Resize the column. 3. + * Resize the handle back to initial value. + */ + if (BrowserUtil.isIE(getDesiredCapabilities())) { + int initHandleWidth = handle.getSize().width; + setElementWidth(handle, 20); + handle = header.getResizeHandle(); + builder.clickAndHold(handle).moveByOffset(-20, 0).release().build() + .perform(); + setElementWidth(handle, initHandleWidth); + } else { + builder.clickAndHold(handle).moveByOffset(-20, 0).release().build() + .perform(); + } + header = table.getHeaderCell(COLUMN_INDEX); + int widthAfterResize = header.getSize().width; + Assert.assertTrue( + "The column with index " + COLUMN_INDEX + " was not resized.", + initialWidth > widthAfterResize); + } + + @Test(expected = NoSuchElementException.class) + public void testGetHeaderCellException() { + table.getHeaderCell(-10); + } + + private void setElementWidth(WebElement elem, int width) { + JavascriptExecutor js = getCommandExecutor(); + String jsScript = "var elem=arguments[0];" + "elem.style.width='" + + width + "px';"; + js.executeScript(jsScript, elem); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/table/TableElementContextMenuTest.java b/uitest/src/test/java/com/vaadin/tests/elements/table/TableElementContextMenuTest.java new file mode 100644 index 00000000000..6a05730814c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/table/TableElementContextMenuTest.java @@ -0,0 +1,35 @@ +package com.vaadin.tests.elements.table; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.NoSuchElementException; + +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableElementContextMenuTest extends MultiBrowserTest { + + private TableElement tableElement; + + @Before + public void init() { + openTestURL(); + tableElement = $(TableElement.class).first(); + } + + @Test + public void tableContextMenu_menuOpenFetchMenu_contextMenuFetchedCorrectly() { + tableElement.contextClick(); + TableElement.ContextMenuElement contextMenu = tableElement + .getContextMenu(); + Assert.assertNotNull( + "There is no context menu open by tableElement.contextClick()", + contextMenu); + } + + @Test(expected = NoSuchElementException.class) + public void tableContextMenu_menuClosedfetchContextMenu_exceptionThrown() { + tableElement.getContextMenu(); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/table/TableGetRowTest.java b/uitest/src/test/java/com/vaadin/tests/elements/table/TableGetRowTest.java new file mode 100644 index 00000000000..8068c5aabd0 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/table/TableGetRowTest.java @@ -0,0 +1,79 @@ +package com.vaadin.tests.elements.table; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.testbench.elements.TableRowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableGetRowTest extends MultiBrowserTest { + + private static final String GET_ROW_ERROR_MESSAGE = "TableElement.getRow() returns wrong row."; + private static final String GET_CELL_ERROR_MESSAGE = "TableElement.getCell() returns wrong cell."; + + @Override + protected Class getUIClass() { + return TableScroll.class; + } + + TableElement table; + int firstRow = 0; + int firstCol = 0; + + @Before + public void init() { + openTestURL(); + table = $(TableElement.class).first(); + } + + @Test + public void getTopRowTest() { + TableRowElement row = table.getRow(0); + WebElement cell = row.getCell(0); + String expected = "col=0 row=0"; + String actual = cell.getText(); + + Assert.assertEquals(GET_ROW_ERROR_MESSAGE, expected, actual); + } + + @Test + public void getFifthRowTest() { + TableRowElement row = table.getRow(4); + WebElement cell = row.getCell(1); + String expected = "col=1 row=4"; + String actual = cell.getText(); + Assert.assertEquals(GET_ROW_ERROR_MESSAGE, expected, actual); + } + + @Test + public void rowGetCellTest() { + TestBenchElement cellFromTable = table.getCell(firstRow, firstCol); + WebElement cellFromRow = table.getRow(firstRow).getCell(firstCol); + Assert.assertEquals( + "Table.getCell() and Row.getCell() return different values", + cellFromRow.getText(), cellFromTable.getText()); + } + + @Test + public void tableGetCellTest() { + TestBenchElement cell = table.getCell(firstRow, firstCol); + String actual = cell.getText(); + String expected = "col=0 row=0"; + Assert.assertEquals(GET_CELL_ERROR_MESSAGE, expected, actual); + } + + @Test(expected = NoSuchElementException.class) + public void getRowExceptionTest() { + table.getRow(-5); + } + + @Test(expected = NoSuchElementException.class) + public void tableGetCellExceptionTest() { + table.getCell(-1, -1); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/table/TableScrollTest.java b/uitest/src/test/java/com/vaadin/tests/elements/table/TableScrollTest.java new file mode 100644 index 00000000000..f607db2fc3c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/table/TableScrollTest.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.elements.table; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.TableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableScrollTest extends MultiBrowserTest { + private static final int SCROLL_VALUE = 200; + + @Test + public void testScrollLeft() { + openTestURL(); + TableElement table = $(TableElement.class).get(0); + table.scrollLeft(SCROLL_VALUE); + Assert.assertEquals(SCROLL_VALUE, getScrollLeftValue(table)); + } + + @Test + public void testScrollTop() { + openTestURL(); + TableElement table = $(TableElement.class).get(0); + table.scroll(SCROLL_VALUE); + Assert.assertEquals(SCROLL_VALUE, getScrollTopValue(table)); + } + + // helper functions + private int getScrollTopValue(WebElement elem) { + JavascriptExecutor js = getCommandExecutor(); + String jsScript = "return arguments[0].getElementsByClassName(\"v-scrollable\")[0].scrollTop;"; + Long scrollTop = (Long) js.executeScript(jsScript, elem); + return scrollTop.intValue(); + } + + private int getScrollLeftValue(WebElement elem) { + JavascriptExecutor js = getCommandExecutor(); + String jsScript = "return arguments[0].getElementsByClassName(\"v-scrollable\")[0].scrollLeft;"; + Long scrollLeft = (Long) js.executeScript(jsScript, elem); + return scrollLeft.intValue(); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/NestedTabSheetTest.java b/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/NestedTabSheetTest.java new file mode 100644 index 00000000000..f7d85beaddd --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/NestedTabSheetTest.java @@ -0,0 +1,91 @@ +/* + * 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.elements.tabsheet; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests selecting tabs in a nested tab sheet. TabSheetElement.openTab should + * not open tabs that are in a tab sheet that is itself contained in the current + * tab sheet. Only the tabs in the current tab sheet should be candidates for + * selection. + */ +public class NestedTabSheetTest extends MultiBrowserTest { + + @Test + public void openOuterTabInNestedTabSheet() { + openTestURL(); + // Open a tab in the outer tab sheet. No errors should occur. + TabSheetElement outer = $(TabSheetElement.class).first(); + outer.openTab("Tab 2"); + checkForSelectedTab(outer, "Tab 2"); + } + + @Test + public void openInnerTabInNestedTabSheet() { + openTestURL(); + // Properly open a tab that is in an inner tab sheet. + TabSheetElement outer = $(TabSheetElement.class).first(); + outer.openTab("Tab 3"); + TabSheetElement thirdInner = outer.$(TabSheetElement.class).first(); + thirdInner.openTab("Tab 3.2"); + checkForSelectedTab(thirdInner, "Tab 3.2"); + } + + @Test + public void testThatOpeningInnerTabFails() { + openTestURL(); + // Attempt to improperly open an inner tab. This should fail. + TabSheetElement outer = $(TabSheetElement.class).first(); + try { + outer.openTab("Tab 1.3"); + } catch (NoSuchElementException e) { + // openTab may throw an exception when the tab is not found. + } + // Check that inner tab 1.3 is not selected. + TabSheetElement inner = outer.$(TabSheetElement.class).first(); + assertFalse("Tab 1.3 is selected, but it should not be.", + isTabSelected(inner, "Tab 1.3")); + } + + private void checkForSelectedTab(TabSheetElement tse, String tabCaption) { + assertTrue("Tab " + tabCaption + " should be selected, but it is not.", + isTabSelected(tse, tabCaption)); + } + + private boolean isTabSelected(TabSheetElement tse, String tabCaption) { + List selectedTabs = tse + .findElements(By.className("v-tabsheet-tabitemcell-selected")); + for (WebElement tab : selectedTabs) { + WebElement caption = tab.findElement(By.className("v-captiontext")); + if (tabCaption.equals(caption.getText())) { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/TabSheetElementExceptionTest.java b/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/TabSheetElementExceptionTest.java new file mode 100644 index 00000000000..06157288fbd --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/TabSheetElementExceptionTest.java @@ -0,0 +1,45 @@ +/* + * 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.elements.tabsheet; + +import org.junit.Test; +import org.openqa.selenium.NoSuchElementException; + +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that an exception is thrown when attempting to select a tab that does + * not exist in the tab sheet. + */ +public class TabSheetElementExceptionTest extends MultiBrowserTest { + + @Test + public void testNoExceptionWhenFound() { + openTestURL(); + TabSheetElement tse = $(TabSheetElement.class).first(); + for (int i = 1; i <= 5; i++) { + tse.openTab("Tab " + i); + } + } + + @Test(expected = NoSuchElementException.class) + public void testExceptionWhenNotFound() { + openTestURL(); + TabSheetElement tse = $(TabSheetElement.class).first(); + tse.openTab("Tab 6"); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/TabSheetElementTabWithoutCaptionTest.java b/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/TabSheetElementTabWithoutCaptionTest.java new file mode 100644 index 00000000000..fb975428622 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/tabsheet/TabSheetElementTabWithoutCaptionTest.java @@ -0,0 +1,143 @@ +/* + * 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.elements.tabsheet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TabSheetElementTabWithoutCaptionTest extends MultiBrowserTest { + + @Before + public void init() { + openTestURL("theme=reindeer"); + } + + @Test + public void openTabByCaption() { + for (int i = 1; i <= 5; i++) { + String caption = (i != 3 ? "Tab " + i : null); + $(TabSheetElement.class).first().openTab(caption); + checkSelectedTab(caption); + } + } + + @Test + public void getCaptions() { + List expectedCaptions = Arrays.asList( + new String[] { "Tab 1", "Tab 2", null, "Tab 4", "Tab 5" }); + List actualCaptions = $(TabSheetElement.class).first() + .getTabCaptions(); + assertEquals("Unexpected tab captions", expectedCaptions, + actualCaptions); + } + + @Test + public void closeTabByCaption() { + for (int i = 1; i <= 5; i++) { + String caption = (i != 3 ? "Tab " + i : null); + $(TabSheetElement.class).first().closeTab(caption); + checkTabClosed(caption); + } + } + + @Test + public void openTabByIndex() { + int maxIndex = $(TabSheetElement.class).get(1).getTabCount(); + for (int i = 0; i < maxIndex; i++) { + $(TabSheetElement.class).all().get(1).openTab(i); + checkIconTabOpen(i); + } + } + + @Test + public void closeTabByIndex() { + $(TabSheetElement.class).get(1).closeTab(0); + int numTabs = $(TabSheetElement.class).get(1) + .findElements(By.className("v-tabsheet-tabitemcell")).size(); + assertEquals("The number of open tabs is incorrect", 4, numTabs); + $(TabSheetElement.class).get(1).closeTab(3); + numTabs = $(TabSheetElement.class).get(1) + .findElements(By.className("v-tabsheet-tabitemcell")).size(); + assertEquals("The number of open tabs is incorrect", 3, numTabs); + $(TabSheetElement.class).get(1).closeTab(2); + numTabs = $(TabSheetElement.class).get(1) + .findElements(By.className("v-tabsheet-tabitemcell")).size(); + assertEquals("The number of open tabs is incorrect", 2, numTabs); + } + + private void checkSelectedTab(String caption) { + // Check that the currently selected tab has the given caption. + WebElement elem = $(TabSheetElement.class).first().getWrappedElement(); + List openTabs = elem + .findElements(By.className("v-tabsheet-tabitem-selected")); + assertTrue( + "Exactly one tab should be open, but there are " + + openTabs.size() + " open tabs.", + openTabs.size() == 1); + WebElement tab = openTabs.get(0); + List openTabCaptionElements = tab + .findElement(By.className("v-caption")) + .findElements(By.className("v-captiontext")); + if (openTabCaptionElements.size() > 0) { + String openTabCaption = openTabCaptionElements.get(0).getText(); + assertEquals("Wrong tab is open.", caption, openTabCaption); + } else { + assertEquals("Wrong tab is open.", caption, null); + } + } + + private void checkTabClosed(String caption) { + List openTabs = $(TabSheetElement.class).first() + .getTabCaptions(); + assertFalse( + "The tab with caption " + caption + + " is present, although it should have been closed.", + openTabs.contains(caption)); + } + + private void checkIconTabOpen(int index) { + List tabs = $(TabSheetElement.class).get(1) + .findElements(By.className("v-tabsheet-tabitemcell")); + boolean tabsOpen = false; + for (int i = 0; i < tabs.size(); i++) { + WebElement tab = tabs.get(i); + boolean isOpened = tab + .findElements(By.className("v-tabsheet-tabitem-selected")) + .size() > 0; + if (isOpened) { + tabsOpen = true; + assertEquals("The wrong tab is open.", index, i); + } + } + if (!tabsOpen) { + fail("There are no tabs open, but tab with index " + index + + " should be open."); + } + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/elements/treetable/TreeTableElementExpandRowTest.java b/uitest/src/test/java/com/vaadin/tests/elements/treetable/TreeTableElementExpandRowTest.java new file mode 100644 index 00000000000..49847ae0b6c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/treetable/TreeTableElementExpandRowTest.java @@ -0,0 +1,58 @@ +package com.vaadin.tests.elements.treetable; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.TreeTableElement; +import com.vaadin.testbench.elements.TreeTableRowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TreeTableElementExpandRowTest extends MultiBrowserTest { + TreeTableElement tree; + + @Before + public void init() { + openTestURL(); + tree = $(TreeTableElement.class).first(); + } + + @Test + public void testGetRow() { + testRowByIndex(1, "testValue", ""); + } + + @Test + public void testExpandRow0() { + TreeTableRowElement row = tree.getRow(0); + row.toggleExpanded();// expand row + testRowByIndex(1, "item1_1", "Should expand row with index 0."); + testRowByIndex(2, "item1_2", "Should expand row with index 0."); + + } + + @Test + public void testCollapseRow0() { + TreeTableRowElement row = tree.getRow(0); + row.toggleExpanded();// expand row + testRowByIndex(1, "item1_1", "Should expand row with index 0."); + row = tree.getRow(0); + row.toggleExpanded(); // collapse row + testRowByIndex(1, "testValue", "Should collapse row with index 0."); + + } + + private void testRowByIndex(int rowIndex, String expectedValue, + String extraInfo) { + TreeTableRowElement row = tree.getRow(rowIndex); + WebElement cell = row.getCell(0); + String errorMessage = ""; + if (extraInfo != null && !extraInfo.equals("")) { + errorMessage += extraInfo; + } + errorMessage += "Return value of row=" + rowIndex + " cell=0 should be " + + expectedValue + "."; + Assert.assertEquals(errorMessage, expectedValue, cell.getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/twincolselect/TwinColSelectUITest.java b/uitest/src/test/java/com/vaadin/tests/elements/twincolselect/TwinColSelectUITest.java new file mode 100644 index 00000000000..66be8c2aa97 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/twincolselect/TwinColSelectUITest.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.elements.twincolselect; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TwinColSelectUITest extends MultiBrowserTest { + TwinColSelectElement multiSelect; + LabelElement multiCounterLbl; + + @Before + public void init() { + openTestURL(); + multiSelect = $(TwinColSelectElement.class).first(); + multiCounterLbl = $(LabelElement.class).id("multiCounterLbl"); + } + + @Test + public void testSelectDeselectByText() { + multiSelect.selectByText("item2"); + Assert.assertEquals("1: [item1, item2]", multiCounterLbl.getText()); + multiSelect.selectByText("item3"); + Assert.assertEquals("2: [item1, item2, item3]", + multiCounterLbl.getText()); + multiSelect.deselectByText("item2"); + Assert.assertEquals("3: [item1, item3]", multiCounterLbl.getText()); + } + + @Test + public void testDeselectSelectByText() { + multiSelect.deselectByText("item1"); + Assert.assertEquals("1: []", multiCounterLbl.getText()); + multiSelect.selectByText("item1"); + Assert.assertEquals("2: [item1]", multiCounterLbl.getText()); + } + + @Test + public void testGetAvailableOptions() { + assertAvailableOptions("item2", "item3"); + multiSelect.selectByText("item2"); + assertAvailableOptions("item3"); + multiSelect.deselectByText("item1"); + assertAvailableOptions("item1", "item3"); + } + + private void assertAvailableOptions(String... items) { + List optionTexts = multiSelect.getAvailableOptions(); + Assert.assertArrayEquals(items, optionTexts.toArray()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/elements/window/WindowButtonsTest.java b/uitest/src/test/java/com/vaadin/tests/elements/window/WindowButtonsTest.java new file mode 100644 index 00000000000..6130d013038 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/elements/window/WindowButtonsTest.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.elements.window; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.Dimension; + +import com.vaadin.testbench.elements.WindowElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class WindowButtonsTest extends MultiBrowserTest { + + private WindowElement windowElement; + + @Override + protected Class getUIClass() { + return WindowUI.class; + } + + @Before + public void init() { + openTestURL(); + windowElement = $(WindowElement.class).first(); + } + + @Test + public void window_clickCloseButton_windowClosed() { + windowElement.close(); + + assertFalse($(WindowElement.class).exists()); + } + + @Test + public void window_maximizeAndRestore_windowOriginalSize() + throws IOException, InterruptedException { + assertFalse(windowElement.isMaximized()); + final Dimension originalSize = windowElement.getSize(); + + windowElement.maximize(); + + assertTrue(windowElement.isMaximized()); + assertNotEquals(originalSize, windowElement.getSize()); + + windowElement.restore(); + + assertFalse(windowElement.isMaximized()); + assertEquals(originalSize, windowElement.getSize()); + } + +}