diff options
author | Artur <artur@vaadin.com> | 2017-01-11 13:45:51 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-01-11 13:45:51 +0200 |
commit | f7e33df4fcf07a73a06a372955b793bd77fe103a (patch) | |
tree | 2983cb6a2d0f0a1c77d67283220e3c546c6711e7 /uitest/src/test | |
parent | aae36190f7647dc773c7410f68f41b731c937d97 (diff) | |
download | vaadin-framework-f7e33df4fcf07a73a06a372955b793bd77fe103a.tar.gz vaadin-framework-f7e33df4fcf07a73a06a372955b793bd77fe103a.zip |
Import element tests from TestBench (#8117)
Contains some additional tests and element changes based on review.
Diffstat (limited to 'uitest/src/test')
58 files changed, 3734 insertions, 0 deletions
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 0000000000..28ed259840 --- /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 0000000000..9a1dfa99b4 --- /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 0000000000..223020a9a3 --- /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 0000000000..3780a1619b --- /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 0000000000..8509841b22 --- /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 0000000000..4d8144b458 --- /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 0000000000..fbe94c830e --- /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 0000000000..26c4296157 --- /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<String> expected = Collections + .singletonList(ComponentElementGetValue.TEST_STRING_VALUE); + List<String> 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 0000000000..c52341ec76 --- /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 0000000000..2abcc33d4d --- /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 0000000000..fed112f439 --- /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 0000000000..9ac667b5a3 --- /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 0000000000..5b32c86b66 --- /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 0000000000..cf8c573198 --- /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 0000000000..f30fd5d5b0 --- /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 0000000000..b8f3d8d207 --- /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<ButtonElement> 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 0000000000..9237a541e0 --- /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 0000000000..866776c70b --- /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 0000000000..c7c0915dee --- /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 0000000000..28c6980fdb --- /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 0000000000..012b4605f2 --- /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 0000000000..771b2996fc --- /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 0000000000..c7f4b8d11e --- /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 0000000000..c5a166f8f5 --- /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 0000000000..d9d497798b --- /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 0000000000..8d28c490cb --- /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 0000000000..c18e8a10a6 --- /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 0000000000..1a527d8e9a --- /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<String> suggestions = cb.getPopupSuggestions(); + List<String> expectedSuggestions = new ArrayList<String>(); + 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 0000000000..f05572e950 --- /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 0000000000..8dde197067 --- /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 0000000000..fb84ea3055 --- /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 0000000000..7c65872d17 --- /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 0000000000..831ec1371a --- /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 0000000000..17f5d867e2 --- /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 0000000000..dc3a49eafe --- /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<GridRowElement> 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 0000000000..1560dc64d5 --- /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 0000000000..ce7eca6322 --- /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<WebElement> 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 0000000000..dc960f4d49 --- /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<WebElement> 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 0000000000..0ce358e727 --- /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 0000000000..2640c1a5e7 --- /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<NotificationElement> 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 0000000000..ae0ea0e757 --- /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 0000000000..a4fc3932db --- /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 0000000000..97b35b2e63 --- /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 0000000000..cd2c6c1046 --- /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 0000000000..03bc2d8379 --- /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 0000000000..bd4e567b70 --- /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 0000000000..ef41ab8a0f --- /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 0000000000..68842d2159 --- /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 0000000000..742fd33947 --- /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 0000000000..6a05730814 --- /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 0000000000..8068c5aabd --- /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 0000000000..f607db2fc3 --- /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 0000000000..f7d85beadd --- /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<WebElement> 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 0000000000..06157288fb --- /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 0000000000..fb97542862 --- /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<String> expectedCaptions = Arrays.asList( + new String[] { "Tab 1", "Tab 2", null, "Tab 4", "Tab 5" }); + List<String> 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<WebElement> 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<WebElement> 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<String> 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<WebElement> 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 0000000000..49847ae0b6 --- /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 0000000000..66be8c2aa9 --- /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<String> 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 0000000000..6130d01303 --- /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()); + } + +} |