diff options
Diffstat (limited to 'uitest/src')
50 files changed, 2281 insertions, 281 deletions
diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java index d7fb7d03fb..558379260b 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java @@ -181,9 +181,13 @@ public abstract class AbstractTestUI extends UI { getLayout().replaceComponent(oldComponent, newComponent); } - protected abstract String getTestDescription(); + protected String getTestDescription() { + return null; + }; - protected abstract Integer getTicketNumber(); + protected Integer getTicketNumber() { + return null; + }; protected WebBrowser getBrowser() { return getSession().getBrowser(); diff --git a/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutRelativeSizeContent.java b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutRelativeSizeContent.java new file mode 100644 index 0000000000..4e1c8f5ca2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutRelativeSizeContent.java @@ -0,0 +1,218 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.absolutelayout; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.MarginInfo; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbsoluteLayout; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Table; + +/** + * Tests how AbsoluteLayout handles relative sized contents. + * + * @author Vaadin Ltd + */ +@Theme("tests-tickets") +public class AbsoluteLayoutRelativeSizeContent extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + HorizontalLayout level1 = new HorizontalLayout( + createComparisonTableOnFixed(), createTableOnFixed(), + createHalfTableOnFixed(), + createHalfTableAndFixedTableOnFixed(), createHalfTableOnFull()); + level1.setSpacing(true); + level1.setWidth(100, Unit.PERCENTAGE); + level1.setExpandRatio( + level1.getComponent(level1.getComponentCount() - 1), 1); + level1.setMargin(new MarginInfo(true, false, false, false)); + + HorizontalLayout level2 = new HorizontalLayout(createFullOnFixed(), + createFullOnFull()); + level2.setSpacing(true); + level2.setWidth(100, Unit.PERCENTAGE); + level2.setExpandRatio( + level2.getComponent(level2.getComponentCount() - 1), 1); + level2.setMargin(new MarginInfo(true, false, false, false)); + + addComponent(level1); + addComponent(level2); + } + + /** + * Creates an {@link AbsoluteLayout} of fixed size that contains a + * full-sized {@link Table} that has been forced to full size with css. + * Represents the workaround given for this ticket. + * + * @return the created layout + */ + private Component createComparisonTableOnFixed() { + AbsoluteLayout absoluteLayout = new AbsoluteLayout(); + absoluteLayout.setWidth(200, Unit.PIXELS); + absoluteLayout.setHeight(200, Unit.PIXELS); + absoluteLayout.setCaption("comparison table in full size"); + + Table table = new Table(); + table.setSizeFull(); + table.setId("comparison-table"); + absoluteLayout.addComponent(table, "top:0;bottom:0;left:0;right:0;"); + return absoluteLayout; + } + + /** + * Creates an {@link AbsoluteLayout} of fixed size that contains a + * full-sized {@link Table}. + * + * @return the created layout + */ + private Component createTableOnFixed() { + AbsoluteLayout absoluteLayout = new AbsoluteLayout(); + absoluteLayout.setWidth(200, Unit.PIXELS); + absoluteLayout.setHeight(200, Unit.PIXELS); + absoluteLayout.setCaption("full-sized table expected"); + + Table table = new Table(); + table.setSizeFull(); + table.setId("full-table"); + absoluteLayout.addComponent(table); + return absoluteLayout; + } + + /** + * Creates an {@link AbsoluteLayout} of fixed size that contains a + * half-sized {@link Table}. + * + * @return the created layout + */ + private Component createHalfTableOnFixed() { + AbsoluteLayout absoluteLayout = new AbsoluteLayout(); + absoluteLayout.setWidth(200, Unit.PIXELS); + absoluteLayout.setHeight(200, Unit.PIXELS); + absoluteLayout.setCaption("half-sized table expected"); + + Table table = new Table(); + table.setWidth(50, Unit.PERCENTAGE); + table.setHeight(50, Unit.PERCENTAGE); + table.setId("half-table"); + absoluteLayout.addComponent(table); + return absoluteLayout; + } + + /** + * Creates an {@link AbsoluteLayout} of fixed size that contains a + * half-sized {@link Table} and a fixed size {@link Table}. + * + * @return the created layout + */ + private Component createHalfTableAndFixedTableOnFixed() { + AbsoluteLayout absoluteLayout = new AbsoluteLayout(); + absoluteLayout.setWidth(200, Unit.PIXELS); + absoluteLayout.setHeight(200, Unit.PIXELS); + absoluteLayout.setCaption("half-sized and tiny expected"); + + Table table = new Table(); + table.setWidth(50, Unit.PERCENTAGE); + table.setHeight(50, Unit.PERCENTAGE); + table.setId("halfwithtiny-table"); + absoluteLayout.addComponent(table); + + Table tableTiny = new Table(); + tableTiny.setWidth(50, Unit.PIXELS); + tableTiny.setHeight(50, Unit.PIXELS); + absoluteLayout.addComponent(tableTiny, "right:50;"); + return absoluteLayout; + } + + /** + * Creates an {@link AbsoluteLayout} of full size that contains a half-sized + * {@link Table}. + * + * @return the created layout + */ + private Component createHalfTableOnFull() { + AbsoluteLayout absoluteLayout = new AbsoluteLayout(); + absoluteLayout.setSizeFull(); + absoluteLayout.setId("halfinfull-layout"); + absoluteLayout.setCaption("half-sized table expected"); + + Table table = new Table(); + table.setWidth(50, Unit.PERCENTAGE); + table.setHeight(50, Unit.PERCENTAGE); + table.setId("halfinfull-table"); + absoluteLayout.addComponent(table); + return absoluteLayout; + } + + /** + * Creates an {@link AbsoluteLayout} of fixed size that contains a + * fixed-sized {@link AbsoluteLayout}. + * + * @return the created layout + */ + private Component createFullOnFixed() { + AbsoluteLayout absoluteLayout = new AbsoluteLayout(); + absoluteLayout.setWidth(200, Unit.PIXELS); + absoluteLayout.setHeight(200, Unit.PIXELS); + absoluteLayout.setId("fullonfixed-outer"); + absoluteLayout.addStyleName("green"); + absoluteLayout.setCaption("yellow area expected"); + + AbsoluteLayout absoluteLayout2 = new AbsoluteLayout(); + absoluteLayout2.setSizeFull(); + absoluteLayout2.setId("fullonfixed-inner"); + absoluteLayout2.addStyleName("yellow"); + + absoluteLayout.addComponent(absoluteLayout2, "top:50px;left:100px;"); + return absoluteLayout; + } + + /** + * Creates an {@link AbsoluteLayout} of full size that contains another + * full-sized {@link AbsoluteLayout}. + * + * @return the created layout + */ + private AbsoluteLayout createFullOnFull() { + AbsoluteLayout absoluteLayout = new AbsoluteLayout(); + absoluteLayout.setSizeFull(); + absoluteLayout.setId("fullonfull-outer"); + absoluteLayout.addStyleName("cyan"); + absoluteLayout.setCaption("area with red border expected"); + + AbsoluteLayout absoluteLayout2 = new AbsoluteLayout(); + absoluteLayout2.setSizeFull(); + absoluteLayout2.setId("fullonfull-inner"); + absoluteLayout2.addStyleName("redborder"); + + absoluteLayout.addComponent(absoluteLayout2, "top:50px;left:100px;"); + return absoluteLayout; + } + + @Override + protected String getTestDescription() { + return "Full size component in AbsoluteLayout shouldn't get undefined size"; + } + + @Override + protected Integer getTicketNumber() { + return 13131; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutRelativeSizeContentTest.java b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutRelativeSizeContentTest.java new file mode 100644 index 0000000000..6cb8c476c9 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutRelativeSizeContentTest.java @@ -0,0 +1,120 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.absolutelayout; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.number.IsCloseTo.closeTo; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests how AbsoluteLayout handles relative sized contents. + * + * @author Vaadin Ltd + */ +public class AbsoluteLayoutRelativeSizeContentTest extends MultiBrowserTest { + + @Override + @Before + public void setup() throws Exception { + super.setup(); + openTestURL(); + + waitForElementPresent(By.id("comparison-table")); + }; + + @Test + public void testFullAgainstComparison() { + WebElement comparison = findElement(By.id("comparison-table")); + WebElement full = findElement(By.id("full-table")); + + assertThat("Full table should be as wide as comparison table", + full.getSize().width, is(comparison.getSize().width)); + assertThat("Full table should be as high as comparison table", + full.getSize().height, is(comparison.getSize().height)); + } + + @Test + public void testHalfAgainstComparison() { + WebElement comparison = findElement(By.id("comparison-table")); + WebElement half = findElement(By.id("half-table")); + + assertThat( + "Half-sized table should be half as wide as comparison table", + half.getSize().width, is(comparison.getSize().width / 2)); + assertThat( + "Half-sized table should be half as high as comparison table", + half.getSize().height, is(comparison.getSize().height / 2)); + } + + @Test + public void testHalfWithTinyAgainstComparison() { + WebElement comparison = findElement(By.id("comparison-table")); + WebElement half = findElement(By.id("halfwithtiny-table")); + + assertThat( + "Half-sized table should be half as wide as comparison table even if there are other components in the layout", + half.getSize().width, is(comparison.getSize().width / 2)); + assertThat( + "Half-sized table should be half as high as comparison table even if there are other components in the layout", + half.getSize().height, is(comparison.getSize().height / 2)); + } + + @Test + public void testHalfAgainstFullLayout() { + WebElement layout = findElement(By.id("halfinfull-layout")); + WebElement half = findElement(By.id("halfinfull-table")); + + assertThat("Half-sized table should be half as wide as full layout", + (double) half.getSize().width, + closeTo(((double) layout.getSize().width) / 2, 0.5)); + assertThat("Half-sized table should be half as high as full layout", + (double) half.getSize().height, + closeTo(((double) layout.getSize().height) / 2, 0.5)); + } + + @Test + public void testFullOnFixedWithSetLocation() { + WebElement outer = findElement(By.id("fullonfixed-outer")); + WebElement inner = findElement(By.id("fullonfixed-inner")); + + assertThat( + "Inner layout should be as wide as outer layout minus left position", + inner.getSize().width, is(outer.getSize().width - 100)); + assertThat( + "Inner layout should be as high as outer layout minus top position", + inner.getSize().height, is(outer.getSize().height - 50)); + } + + @Test + public void testFullOnFullWithSetLocation() { + WebElement outer = findElement(By.id("fullonfull-outer")); + WebElement inner = findElement(By.id("fullonfull-inner")); + + assertThat( + "Inner layout should be as wide as outer layout minus left position", + inner.getSize().width, is(outer.getSize().width - 100)); + assertThat( + "Inner layout should be as high as outer layout minus top position", + inner.getSize().height, is(outer.getSize().height - 50)); + } +} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxClickIcon.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxClickIcon.java new file mode 100644 index 0000000000..b0450e22c3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxClickIcon.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.combobox; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.FontAwesome; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; + +/** + * Test UI to check click on icon in the combobox. + * + * @author Vaadin Ltd + */ +public class ComboBoxClickIcon extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final List<String> items = new ArrayList<String>(); + items.add("A"); + items.add("B"); + items.add("C"); + final ComboBox combo = new ComboBox(); + combo.setImmediate(true); + combo.setItemIcon(items.get(0), FontAwesome.ALIGN_CENTER); + combo.setItemIcon(items.get(1), FontAwesome.ALIGN_CENTER); + combo.setItemIcon(items.get(2), FontAwesome.ALIGN_CENTER); + combo.addItems(items); + combo.setTextInputAllowed(false); + addComponent(combo); + } + + @Override + protected String getTestDescription() { + return "Combobox icon should handle click events"; + } + + @Override + protected Integer getTicketNumber() { + return 14624; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxClickIconTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxClickIconTest.java new file mode 100644 index 0000000000..949fcdb882 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxClickIconTest.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.combobox; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ComboBoxElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test to check whether combobox is expanded when icon is clicked. + * + * @author Vaadin Ltd + */ +public class ComboBoxClickIconTest extends MultiBrowserTest { + + @Test + public void testClickOnIconInCombobox() { + openTestURL(); + + $(ComboBoxElement.class).first().openPopup(); + + getDriver().findElements(By.className("gwt-MenuItem")).get(1).click(); + + getDriver().findElement(By.className("v-filterselect")) + .findElement(By.className("v-icon")).click(); + + Assert.assertTrue("Unable to find menu items in combobox popup", + isElementPresent(By.className("gwt-MenuItem"))); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxInputPromptTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxInputPromptTest.java index cbd83c5734..1e6f7e4170 100644 --- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxInputPromptTest.java +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxInputPromptTest.java @@ -18,16 +18,13 @@ package com.vaadin.tests.components.combobox; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyString; -import static org.junit.Assert.assertEquals; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.ComboBoxElement; -import com.vaadin.testbench.elements.TextFieldElement; -import com.vaadin.tests.tb3.AbstractTB3Test; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.ComboBoxElement; import com.vaadin.tests.tb3.MultiBrowserTest; public class ComboBoxInputPromptTest extends MultiBrowserTest { diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java new file mode 100644 index 0000000000..62db60be76 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java @@ -0,0 +1,68 @@ +package com.vaadin.tests.components.datefield; + +import com.vaadin.data.Property; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DateField; +import com.vaadin.ui.Label; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +public class DateFieldDayResolutionOffset extends AbstractTestUI { + + private final String initialDateString = "09/01/2014 00:00:00"; + + @Override + protected void setup(VaadinRequest request) { + final Label dateValue = new Label(initialDateString); + dateValue.setId("dateValue"); + + final TimeZone timezone = TimeZone.getTimeZone("GMT"); + final SimpleDateFormat dateformat = getDateFormat(timezone); + final DateField dateField = getDateField(timezone, dateformat); + + addComponent(dateValue); + addComponent(dateField); + + dateField.addValueChangeListener( new Property.ValueChangeListener(){ + @Override + public void valueChange(Property.ValueChangeEvent event) { + dateValue.setValue(dateformat.format(dateField.getValue())); + } + }); + } + + private DateField getDateField(TimeZone timezone, SimpleDateFormat dateformat) { + final DateField dateField = new DateField(); + try { + Date initialDate = dateformat.parse(initialDateString); + dateField.setResolution(Resolution.DAY); + dateField.setTimeZone(timezone); + dateField.setValue(initialDate); + } catch (ParseException e) { + e.printStackTrace(); + } + return dateField; + } + + private SimpleDateFormat getDateFormat(TimeZone timezone) { + final SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); + dateformat.setTimeZone(timezone); + return dateformat; + } + + @Override + protected String getTestDescription() { + return "The time should stay at 00:00:00 when selecting dates with Resolution.DAY selected."; + } + + @Override + protected Integer getTicketNumber() { + return 14653; + } +} diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java new file mode 100644 index 0000000000..c3b3af9aa4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java @@ -0,0 +1,43 @@ +package com.vaadin.tests.components.datefield; + +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.AbstractTB3Test; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +public class DateFieldDayResolutionOffsetTest extends MultiBrowserTest { + + @Test + public void dateValueDoesNotHaveOffset() throws InterruptedException { + openTestURL(); + + openDatePicker(); + select2ndOfSeptember(); + + LabelElement dateValue = $(LabelElement.class).id("dateValue"); + assertThat(dateValue.getText(), is("09/02/2014 00:00:00")); + } + + private void select2ndOfSeptember() { + for(WebElement e : findElements(By.className("v-datefield-calendarpanel-day"))) { + if(e.getText().equals("2")) { + e.click(); + break; + } + } + } + + private void openDatePicker() { + DateFieldElement dateField = $(DateFieldElement.class).first(); + + dateField.findElement(By.tagName("button")) + .click(); + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/formlayout/TableInFormLayoutCausesScrollingTest.java b/uitest/src/com/vaadin/tests/components/formlayout/TableInFormLayoutCausesScrollingTest.java index dc10217efb..3a0dcafe1f 100644 --- a/uitest/src/com/vaadin/tests/components/formlayout/TableInFormLayoutCausesScrollingTest.java +++ b/uitest/src/com/vaadin/tests/components/formlayout/TableInFormLayoutCausesScrollingTest.java @@ -2,6 +2,7 @@ package com.vaadin.tests.components.formlayout; import com.vaadin.testbench.elements.TableElement; import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Ignore; import org.junit.Test; import org.openqa.selenium.Keys; import org.openqa.selenium.interactions.Actions; @@ -11,6 +12,12 @@ import java.io.IOException; public class TableInFormLayoutCausesScrollingTest extends MultiBrowserTest { @Test + @Ignore + //This test is actually testing that #7309 is NOT fixed. + //Ignoring the test because it is not stable and it's + //occasionally failing on browsers even when it shouldn't. + + //There's no point fixing this test before #7309 is actually fixed. public void pageIsNotScrolled() throws IOException { openTestURL(); diff --git a/uitest/src/com/vaadin/tests/components/panel/UndefinedSizeScrollbars.java b/uitest/src/com/vaadin/tests/components/panel/UndefinedSizeScrollbars.java new file mode 100644 index 0000000000..ef535baa0a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/panel/UndefinedSizeScrollbars.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.panel; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Panel; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class UndefinedSizeScrollbars extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setSpacing(true); + layout.setSizeFull(); + setContent(layout); + + GridLayout grid = new GridLayout(); + grid.setSpacing(true); + + TextField text1 = new TextField(); + text1.setCaption("Text1"); + text1.setRequired(true); + + TextField text2 = new TextField(); + text2.setCaption("Text2"); + text2.setRequired(true); + + ComboBox combo = new ComboBox(); + combo.setCaption("Combo1"); + + CheckBox check = new CheckBox(); + check.setCaption("Check"); + + grid.setColumns(2); + grid.setRows(2); + + grid.addComponent(text1); + grid.addComponent(text2); + grid.addComponent(combo); + grid.addComponent(check); + + grid.setSizeUndefined(); + + Panel panel = new Panel(); + panel.setContent(grid); + + panel.setSizeUndefined(); + + layout.addComponent(panel); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/panel/UndefinedSizeScrollbarsTest.java b/uitest/src/com/vaadin/tests/components/panel/UndefinedSizeScrollbarsTest.java new file mode 100644 index 0000000000..c055356624 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/panel/UndefinedSizeScrollbarsTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.panel; + +import java.io.IOException; + +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UndefinedSizeScrollbarsTest extends MultiBrowserTest { + + @Test + public void testNoScrollbars() throws IOException { + openTestURL(); + compareScreen("noscrollbars"); + } +} diff --git a/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupView.java b/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupView.java new file mode 100644 index 0000000000..ecce1781a5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupView.java @@ -0,0 +1,23 @@ +package com.vaadin.tests.components.popupview; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.PopupView; + +public class DisabledPopupView extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + PopupView popupView = new PopupView("Disabled Popup", new Button("Hi!")); + + popupView.setEnabled(false); + + addComponent(popupView); + } + + @Override + protected Integer getTicketNumber() { + return 14797; + } +} diff --git a/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupViewTest.java b/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupViewTest.java new file mode 100644 index 0000000000..be9345d588 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/popupview/DisabledPopupViewTest.java @@ -0,0 +1,20 @@ +package com.vaadin.tests.components.popupview; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.PopupViewElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; + +public class DisabledPopupViewTest extends MultiBrowserTest { + + @Test + public void disabledPopupDoesNotOpen() { + openTestURL(); + + $(PopupViewElement.class).first().click(); + + assertFalse($(ButtonElement.class).exists()); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/ContainerSizeChangeTest.java b/uitest/src/com/vaadin/tests/components/table/ContainerSizeChangeTest.java index 041b23749c..e13238e10d 100644 --- a/uitest/src/com/vaadin/tests/components/table/ContainerSizeChangeTest.java +++ b/uitest/src/com/vaadin/tests/components/table/ContainerSizeChangeTest.java @@ -1,5 +1,6 @@ package com.vaadin.tests.components.table; +import static junit.framework.TestCase.fail; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -19,9 +20,6 @@ import com.vaadin.tests.tb3.MultiBrowserTest; public class ContainerSizeChangeTest extends MultiBrowserTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void tableShouldLoadCorrectItems() throws IOException, InterruptedException { @@ -52,11 +50,12 @@ public class ContainerSizeChangeTest extends MultiBrowserTest { } private void assertRowDoesNotExist(TableElement table, int rowIndex) { - // This is a really crappy way to workaround JUnit's limitation to - // provide a proper assert.throws method... - thrown.expect(NoSuchElementException.class); - table.getCell(rowIndex, 0); + try { + table.getCell(rowIndex, 0); + + fail(String.format("Row %s should not exists.", rowIndex)); + } catch (NoSuchElementException e) { - Assert.fail(String.format("Row %s should not exists.", rowIndex)); + } } } diff --git a/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponentsTest.java b/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponentsTest.java index 4a46342cab..aee8cc96d9 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponentsTest.java +++ b/uitest/src/com/vaadin/tests/components/table/TableClickAndDragOnIconAndComponentsTest.java @@ -15,19 +15,22 @@ */ package com.vaadin.tests.components.table; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.List; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.SingleBrowserTest; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; import com.vaadin.testbench.elements.TableElement; -import com.vaadin.tests.tb3.MultiBrowserTest; +import org.openqa.selenium.interactions.Actions; /** * Tests that clicking on active fields doesn't change Table selection, nor does @@ -36,203 +39,174 @@ import com.vaadin.tests.tb3.MultiBrowserTest; * @author Vaadin Ltd */ public class TableClickAndDragOnIconAndComponentsTest extends MultiBrowserTest { - @Test - public void testClickingAndDragging() { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + } - TableElement table = $(TableElement.class).first(); + @Test + public void clickOnTextFieldDoesNotSelectRow() { + selectRow(1); - // ensure there's no initial selection - List<WebElement> selected = table.findElements(By - .className("v-selected")); - assertTrue("selection found when there should be none", - selected.isEmpty()); - - // click a cell - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 2nd row expected)", - "red 1foo", table.getCell(1, 2).getText()); - table.getCell(1, 2).click(); - - // ensure the correct row and nothing but that got selected - selected = table.findElements(By.className("v-selected")); - assertFalse("no selection found when there should be some", - selected.isEmpty()); - // find cell contents (row header included) - List<WebElement> cellContents = selected.get(0).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 2nd row expected)", - "red 1foo", cellContents.get(2).getText()); - assertEquals("unexpected table selection size", 1, selected.size()); + clickOnTextField(2); + assertThatFocusTextFieldHasText("foo 2foo"); - List<WebElement> rows = table.findElement(By.className("v-table-body")) - .findElements(By.tagName("tr")); - assertEquals("unexpected table row count", 5, rows.size()); + assertThat(getSelectedRowTextValue(), is(1)); + } - // find a row that isn't the one selected - cellContents = rows.get(2).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 3rd row expected)", - "red 2foo", cellContents.get(2).getText()); - - // click on a TextField on that row - WebElement textField = rows.get(2) - .findElements(By.className("v-textfield")).get(0); - assertEquals( - "expected value not found, wrong cell or contents (6th column of the 3rd row expected)", - "foo 2foo", textField.getAttribute("value")); - textField.click(); + @Test + public void clickOnReadOnlyTextFieldSelectsRow() { + selectRow(1); + + clickOnReadOnlyTextField(2); + + assertThat(getSelectedRowTextValue(), is(2)); + } + + @Test + public void clickOnLabelSelectsRow() { + selectRow(1); + + clickOnLabel(2); - // ensure the focus shifted correctly - List<WebElement> focused = table.findElements(By + assertThat(getSelectedRowTextValue(), is(2)); + } + + @Test + public void clickOnEmbeddedIconSelectsRow() { + selectRow(1); + + clickOnEmbeddedIcon(2); + + assertThat(getSelectedRowTextValue(), is(2)); + } + + @Test + public void dragAndDroppingRowDoesNotSelectRow() { + selectRow(1); + + moveRow(0, 3); + + assertThat(getSelectedRowTextValue(), is(1)); + assertThat(getSelectedRowIndex(), is(0)); + } + + @Test + public void dragAndDroppingSelectedRowStaysSelected() { + selectRow(1); + + moveRow(1, 4); + + assertThat(getSelectedRowTextValue(), is(1)); + assertThat(getSelectedRowIndex(), is(4)); + } + + private void assertThatFocusTextFieldHasText(String text) { + List<WebElement> focused = getTable().findElements(By .className("v-textfield-focus")); - assertEquals("unexpected amount of focused textfields", 1, - focused.size()); - assertEquals( - "expected value not found, wrong cell or contents (6th column of the 3rd row expected)", - "foo 2foo", focused.get(0).getAttribute("value")); - - // ensure the selection didn't change - selected = table.findElements(By.className("v-selected")); - assertEquals("unexpected table selection size", 1, selected.size()); - cellContents = selected.get(0).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 2nd row expected)", - "red 1foo", cellContents.get(2).getText()); - - // click on a Label on that row - WebElement label = rows.get(2).findElements(By.className("v-label")) - .get(0); - assertEquals( - "expected value not found, wrong cell or contents (5th column of the 3rd row expected)", - "foo 2foo", label.getText()); - label.click(); - // ensure the focus shifted correctly - focused = table.findElements(By.className("v-textfield-focus")); - assertTrue("focused textfields found when there should be none", - focused.isEmpty()); + assertThat(focused.get(0).getAttribute("value"), is(text)); + } + + private int getSelectedRowTextValue() { + WebElement selectedRow = getSelectedRow(); - // ensure the selection changed - selected = table.findElements(By.className("v-selected")); - assertEquals("unexpected table selection size", 1, selected.size()); - cellContents = selected.get(0).findElements( + //i.e. 'red 1foo' + String text = getText(selectedRow, 2); + + return Integer.parseInt(text.substring(4, 5)); + } + + private String getText(WebElement row, int column) { + List<WebElement> cellContents = getCellContents(row); + + return cellContents.get(column).getText(); + } + + private List<WebElement> getCellContents(WebElement row) { + return row.findElements( By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 3rd row expected)", - "red 2foo", cellContents.get(2).getText()); + } + + private WebElement getSelectedRow() { + return getTable().findElement(By + .className("v-selected")); + } + + private void clickOnTextField(int row) { + WebElement textField = getTextField(row, 0); - // click on the selected row's textfield (same as earlier) textField.click(); + } + + private void clickOnReadOnlyTextField(int row) { + WebElement textField = getTextField(row, 1); - // ensure the focus shifted correctly - focused = table.findElements(By.className("v-textfield-focus")); - assertEquals("unexpected amount of focused textfields", 1, - focused.size()); - assertEquals( - "expected value not found, wrong cell or contents (6th column of the 3rd row expected)", - "foo 2foo", focused.get(0).getAttribute("value")); - - // ensure the selection didn't change - selected = table.findElements(By.className("v-selected")); - assertEquals("unexpected table selection size", 1, selected.size()); - cellContents = selected.get(0).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 3rd row expected)", - "red 2foo", cellContents.get(2).getText()); - - // find the readOnly TextField of the previously selected row - textField = rows.get(1).findElements(By.className("v-textfield")) - .get(1); - assertEquals( - "expected value not found, wrong cell or contents (7th column of the 2nd row expected)", - "foo 1foo", textField.getAttribute("value")); - assertEquals( - "expected readonly status not found, wrong cell or contents (7th column of the 2nd row expected)", - "true", textField.getAttribute("readonly")); - - // click on that TextField textField.click(); + } - // ensure the focus shifted correctly - focused = table.findElements(By.className("v-textfield-focus")); - assertTrue("focused textfields found when there should be none", - focused.isEmpty()); + private WebElement getTextField(int row, int index) { + return getElement(row, index, "v-textfield"); + } - // ensure the selection changed - selected = table.findElements(By.className("v-selected")); - assertEquals("unexpected table selection size", 1, selected.size()); - cellContents = selected.get(0).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 2nd row expected)", - "red 1foo", cellContents.get(2).getText()); - - // click the embedded icon of the other row - WebElement embedded = rows.get(2).findElement( - By.className("v-embedded")); - embedded.click(); - - // ensure the selection changed - selected = table.findElements(By.className("v-selected")); - assertEquals("unexpected table selection size", 1, selected.size()); - cellContents = selected.get(0).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 3rd row expected)", - "red 2foo", cellContents.get(2).getText()); + private WebElement getElement(int row, String className) { + return getElement(row, 0, className); + } - // check row you are about to drag - cellContents = rows.get(4).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 5th row expected)", - "red 4foo", cellContents.get(2).getText()); + private WebElement getElement(int row, int index, String className) { + return getRows() + .get(row) + .findElements(By.className(className)) + .get(index); + } - // check the row above it - cellContents = rows.get(3).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 4th row expected)", - "red 3foo", cellContents.get(2).getText()); + private List<WebElement> getRows() { + return getTable().findElement(By.className("v-table-body")) + .findElements(By.tagName("tr")); + } - // drag the row to the row that's two places above it (gets dropped - // below that) - cellContents = rows.get(4).findElements( - By.className("v-table-cell-content")); - new Actions(getDriver()).moveToElement(cellContents.get(2)) - .clickAndHold().moveToElement(rows.get(2)).release().perform(); + private void selectRow(int row) { + TableElement table = getTable(); + + table.getCell(row, 2).click(); + } - // find the current order of the rows - rows = table.findElement(By.className("v-table-body")).findElements( - By.tagName("tr")); - assertEquals("unexpected table row count", 5, rows.size()); + private TableElement getTable() { + return $(TableElement.class).first(); + } - // ensure the row got dragged - cellContents = rows.get(3).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the dragged row expected, should be on 4th row now)", - "red 4foo", cellContents.get(2).getText()); - cellContents = rows.get(4).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the previous 4th row expected, should be on 5th row now)", - "red 3foo", cellContents.get(2).getText()); - - // ensure the selection didn't change - selected = table.findElements(By.className("v-selected")); - assertEquals("unexpected table selection size", 1, selected.size()); - cellContents = selected.get(0).findElements( - By.className("v-table-cell-content")); - assertEquals( - "expected value not found, wrong cell or contents (3rd column of the 3rd row expected)", - "red 2foo", cellContents.get(2).getText()); + private void clickOnLabel(int row) { + WebElement label = getElement(row, "v-label"); + label.click(); + } + + private void clickOnEmbeddedIcon(int row) { + WebElement embeddedIcon = getElement(row, "v-embedded"); + embeddedIcon.click(); + } + + private void moveRow(int from, int to) { + List<WebElement> rows = getRows(); + List<WebElement> cellContents = getCellContents(rows.get(from)); + + new Actions(getDriver()).moveToElement(cellContents.get(2)) + .clickAndHold().moveToElement(rows.get(to)).release().perform(); } + private int getSelectedRowIndex() { + List<WebElement> rows = getRows(); + + //Unfortunately rows.getIndexOf(getSelectedRow()) doesn't work. + for(WebElement r : rows) { + if(r.getAttribute("class").contains("v-selected")) { + return rows.indexOf(r); + } + } + + return -1; + } } diff --git a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java index d9cbf007df..df06580dae 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java +++ b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRows.java @@ -11,6 +11,12 @@ import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Table; +/** + * Scroll position should be restored when removing and re-adding all rows in + * Table. + * + * @author Vaadin Ltd + */ public class TableRepairsScrollPositionOnReAddingAllRows extends AbstractTestUI { private static final long serialVersionUID = 1L; @@ -19,32 +25,130 @@ public class TableRepairsScrollPositionOnReAddingAllRows extends AbstractTestUI protected void setup(VaadinRequest request) { final BeanItemContainer<TableItem> cont = new BeanItemContainer<TableItem>( TableItem.class); - final List<TableItem> itemList = new ArrayList<TableItem>(); + final List<TableItem> restoringItemList = new ArrayList<TableItem>(); - Button button1 = new Button("ReAdd rows"); - button1.setId("button1"); - button1.addClickListener(new ClickListener() { + final Table table = new Table(); + table.setWidth("400px"); + table.setPageLength(-1); + table.setContainerDataSource(cont); + table.setSelectable(true); + + Button buttonRestore = new Button("Restore table rows"); + buttonRestore.setId("buttonRestore"); + buttonRestore.addClickListener(new ClickListener() { @Override public void buttonClick(com.vaadin.ui.Button.ClickEvent event) { cont.removeAllItems(); - cont.addAll(itemList); + cont.addAll(restoringItemList); } }); + Button buttonReAddAllViaAddAll = new Button("Re-add rows all at once"); + buttonReAddAllViaAddAll.setId("buttonReAddAllViaAddAll"); + buttonReAddAllViaAddAll.addClickListener(new ClickListener() { + + @Override + public void buttonClick(com.vaadin.ui.Button.ClickEvent event) { + List<TableItem> originalItemIds = new ArrayList<TableItem>(cont + .getItemIds()); + cont.removeAllItems(); + cont.addAll(originalItemIds); + } + }); + + Button buttonReplaceByAnotherCollectionViaAddAll = new Button( + "Replace by another items (via addAll())"); + buttonReplaceByAnotherCollectionViaAddAll + .setId("buttonReplaceByAnotherCollectionViaAddAll"); + buttonReplaceByAnotherCollectionViaAddAll + .addClickListener(new ClickListener() { + + @Override + public void buttonClick( + com.vaadin.ui.Button.ClickEvent event) { + cont.removeAllItems(); + // create new collection (of different items) with other + // size + List<TableItem> itemList = new ArrayList<TableItem>(); + for (int i = 0; i < 79; i++) { + TableItem ti = new TableItem(); + ti.setName("AnotherItem1_" + i); + itemList.add(ti); + } + cont.addAll(itemList); + } + }); + + Button buttonReplaceByAnotherCollectionViaAdd = new Button( + "Replace by another items (via add(), add()..)"); + buttonReplaceByAnotherCollectionViaAdd + .setId("buttonReplaceByAnotherCollectionViaAdd"); + buttonReplaceByAnotherCollectionViaAdd + .addClickListener(new ClickListener() { + + @Override + public void buttonClick( + com.vaadin.ui.Button.ClickEvent event) { + cont.removeAllItems(); + for (int i = 0; i < 81; i++) { + TableItem ti = new TableItem(); + ti.setName("AnotherItem2_" + i); + // add one by one in container + cont.addBean(ti); + } + } + }); + + Button buttonReplaceBySubsetOfSmallerSize = new Button( + "Replace rows by sub-set of smaller size (size not enought for restoring scroll position)"); + buttonReplaceBySubsetOfSmallerSize + .setId("buttonReplaceBySubsetOfSmallerSize"); + buttonReplaceBySubsetOfSmallerSize + .addClickListener(new ClickListener() { + + @Override + public void buttonClick( + com.vaadin.ui.Button.ClickEvent event) { + cont.removeAllItems(); + cont.addAll(restoringItemList.subList(0, 20)); + } + }); + + Button buttonReplaceByWholeSubsetPlusOnNew = new Button( + "Replace rows by whole subset plus one new item"); + buttonReplaceByWholeSubsetPlusOnNew + .setId("buttonReplaceByWholeSubsetPlusOnNew"); + buttonReplaceByWholeSubsetPlusOnNew + .addClickListener(new ClickListener() { + + @Override + public void buttonClick( + com.vaadin.ui.Button.ClickEvent event) { + cont.removeAllItems(); + + List<TableItem> list = new ArrayList<TableItem>( + restoringItemList); + TableItem ti = new TableItem(); + ti.setName("AnotherItem3_" + 80); + list.add(ti); + cont.addAll(list); + } + }); + for (int i = 0; i < 80; i++) { TableItem ti = new TableItem(); - ti.setName("Name_" + i); - itemList.add(ti); + ti.setName("Item_" + i); + restoringItemList.add(ti); cont.addBean(ti); } - final Table table = new Table(); - table.setPageLength(-1); - table.setContainerDataSource(cont); - table.setSelectable(true); - - getLayout().addComponent(button1); + getLayout().addComponent(buttonReAddAllViaAddAll); + getLayout().addComponent(buttonReplaceByAnotherCollectionViaAddAll); + getLayout().addComponent(buttonReplaceByAnotherCollectionViaAdd); + getLayout().addComponent(buttonReplaceBySubsetOfSmallerSize); + getLayout().addComponent(buttonReplaceByWholeSubsetPlusOnNew); + getLayout().addComponent(buttonRestore); getLayout().addComponent(table); } diff --git a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java index 807a80d182..a3e7f29dfe 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java +++ b/uitest/src/com/vaadin/tests/components/table/TableRepairsScrollPositionOnReAddingAllRowsTest.java @@ -15,8 +15,8 @@ */ package com.vaadin.tests.components.table; -import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.number.IsCloseTo.closeTo; import org.junit.Test; import org.openqa.selenium.By; @@ -31,6 +31,12 @@ import com.vaadin.testbench.screenshot.ImageComparison; import com.vaadin.testbench.screenshot.ReferenceNameGenerator; import com.vaadin.tests.tb3.MultiBrowserTest; +/** + * Scroll position should be restored when removing and re-adding all rows in + * Table. + * + * @author Vaadin Ltd + */ public class TableRepairsScrollPositionOnReAddingAllRowsTest extends MultiBrowserTest { @@ -39,28 +45,126 @@ public class TableRepairsScrollPositionOnReAddingAllRowsTest extends throws InterruptedException { openTestURL(); - WebElement buttonReAddRows = findElement(By.id("button1")); + WebElement row0 = $(TableElement.class).first().getCell(0, 0); + int rowLocation0 = row0.getLocation().getY(); + // case 1 scrollUp(); waitUntilNot(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver input) { - return $(TableElement.class).first().getCell(49, 0) == null; + return $(TableElement.class).first().getCell(48, 0) == null; } }, 10); - WebElement row = $(TableElement.class).first().getCell(49, 0); + WebElement row = $(TableElement.class).first().getCell(48, 0); int rowLocation = row.getLocation().getY(); - buttonReAddRows.click(); + // This button is for re-adding all rows (original itemIds) at once + // (removeAll() + addAll()) + hitButton("buttonReAddAllViaAddAll"); - row = $(TableElement.class).first().getCell(49, 0); + row = $(TableElement.class).first().getCell(48, 0); int newRowLocation = row.getLocation().getY(); + // ranged check because IE9 consistently misses the mark by 1 pixel + assertThat( + "Scroll position should be the same as before Re-Adding rows via addAll()", + (double) newRowLocation, + closeTo(rowLocation, row.getSize().height + 1)); + + // case 2 + scrollUp(); + + waitUntilNot(new ExpectedCondition<Boolean>() { + @Override + public Boolean apply(WebDriver input) { + return $(TableElement.class).first().getCell(48, 0) == null; + } + }, 10); + + row = $(TableElement.class).first().getCell(48, 0); + rowLocation = row.getLocation().getY(); + + // This button is for replacing all rows at once (removeAll() + + // addAll()) + hitButton("buttonReplaceByAnotherCollectionViaAddAll"); + + row = $(TableElement.class).first().getCell(48, 0); + newRowLocation = row.getLocation().getY(); + + // ranged check because IE9 consistently misses the mark by 1 pixel assertThat( - "Scroll position should be the same as before Re-Adding all rows", - rowLocation == newRowLocation, is(true)); + "Scroll position should be the same as before Replacing rows via addAll()", + (double) newRowLocation, + closeTo(rowLocation, row.getSize().height + 1)); + + // case 3 + // This button is for replacing all rows one by one (removeAll() + add() + // + add()..) + hitButton("buttonReplaceByAnotherCollectionViaAdd"); + + row = $(TableElement.class).first().getCell(0, 0); + newRowLocation = row.getLocation().getY(); + + // ranged check because IE9 consistently misses the mark by 1 pixel + assertThat("Scroll position should be 0", (double) newRowLocation, + closeTo(rowLocation0, 1)); + + // case 4 + // This button is for restoring initial list and for scrolling to 0 + // position + hitButton("buttonRestore"); + scrollUp(); + + waitUntilNot(new ExpectedCondition<Boolean>() { + @Override + public Boolean apply(WebDriver input) { + return $(TableElement.class).first().getCell(48, 0) == null; + } + }, 10); + + // This button is for replacing all rows at once but the count of rows + // is less then first index to scroll + hitButton("buttonReplaceBySubsetOfSmallerSize"); + + row = $(TableElement.class).first().getCell(5, 0); + + newRowLocation = row.getLocation().getY(); + + // ranged check because IE9 consistently misses the mark by 1 pixel + assertThat("Scroll position should be 0", (double) newRowLocation, + closeTo(rowLocation0, 1)); + + // case 5 + // This button is for restoring initial list and for scrolling to 0 + // position + hitButton("buttonRestore"); + scrollUp(); + + waitUntilNot(new ExpectedCondition<Boolean>() { + @Override + public Boolean apply(WebDriver input) { + return $(TableElement.class).first().getCell(48, 0) == null; + } + }, 10); + + row = $(TableElement.class).first().getCell(48, 0); + rowLocation = row.getLocation().getY(); + + // This button is for replacing by whole original sub-set of items plus + // one new + hitButton("buttonReplaceByWholeSubsetPlusOnNew"); + + row = $(TableElement.class).first().getCell(48, 0); + newRowLocation = row.getLocation().getY(); + + // ranged check because IE9 consistently misses the mark by 1 pixel + assertThat("Scroll position should be the same as before Replacing", + (double) newRowLocation, + closeTo(rowLocation, row.getSize().height + 1)); + } private void scrollUp() { @@ -68,6 +172,6 @@ public class TableRepairsScrollPositionOnReAddingAllRowsTest extends By.className("v-table-body-wrapper")); JavascriptExecutor js = new TestBenchCommandExecutor(getDriver(), new ImageComparison(), new ReferenceNameGenerator()); - js.executeScript("arguments[0].scrollTop = " + 1200, actualElement); + js.executeScript("arguments[0].scrollTop = " + 1205, actualElement); } } diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServer.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServer.java new file mode 100644 index 0000000000..b51a8dde08 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServer.java @@ -0,0 +1,83 @@ +package com.vaadin.tests.components.tabsheet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Component; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.SelectedTabChangeEvent; +import com.vaadin.ui.TabSheet.SelectedTabChangeListener; + +/** + * TabSheet test in case user selects a tab and on the selection listener the + * selected tab is changed to another one. + * + * This test used to cause nonfunctional TabSheet if the current tab was 1, user + * selects 5, then the selection listener will revert the selected tab to 1. + * + * @since + * @author Vaadin Ltd + */ +public class TabSelectionRevertedByServer extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + final TabSheet tabsheet = new TabSheet(); + tabsheet.setWidth("400px"); + + Component lastLabel = null; + + for (int i = 1; i <= 5; i++) { + String caption = "Tab " + i; + Label label = new Label(caption); + tabsheet.addTab(label, caption); + + lastLabel = label; + } + + tabsheet.setSelectedTab(0); + + final Component lastTab = lastLabel; + + tabsheet.addSelectedTabChangeListener(new SelectedTabChangeListener() { + + @Override + public void selectedTabChange(SelectedTabChangeEvent event) { + if (tabsheet.getSelectedTab().equals(lastTab)) { + + // Set focus back to first tab in tabsheet + tabsheet.setSelectedTab(0); + Notification.show("Focus set back to tab at position 0"); + } + } + }); + + addComponent(tabsheet); + + Button button = new Button("Select Last Tab"); + button.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + tabsheet.setSelectedTab(lastTab); + } + }); + addComponent(button); + } + + @Override + protected String getTestDescription() { + return "Clicking on Tab 5 will revert to Tab 1. The action is handled on the server side and will set the selected tab to 1 if Tab 5 is selected."; + } + + @Override + protected Integer getTicketNumber() { + return 14710; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServerTest.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServerTest.java new file mode 100644 index 0000000000..64aee8768b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSelectionRevertedByServerTest.java @@ -0,0 +1,112 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.tabsheet; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * If user selected the last tab the test will change it back to the first one + * from a server side selection listener. This test makes sure that actually + * happen. + * + * @since + * @author Vaadin Ltd + */ +public class TabSelectionRevertedByServerTest extends MultiBrowserTest { + + @Test + public void testFocus() throws InterruptedException, IOException { + openTestURL(); + + // Selects Tab 4 which should be selected. + click(4); + assertSelection(4, 1); + + // Select Tab 5 which should revert to Tab 1. + click(5); + assertSelection(1, 5); + + // Make sure after reverting the selection the tab selection still + // works. + click(3); + assertSelection(3, 1); + + } + + private void assertSelection(int expectedIndex, int wrongIndex) { + TestBenchElement tabExpected = tab(expectedIndex); + String attributeClassExpected = tabExpected.getAttribute("class"); + + Assert.assertTrue("Tab " + expectedIndex + " should be selected.", + attributeClassExpected + .contains("v-tabsheet-tabitemcell-selected")); + + TestBenchElement tabWrong = tab(wrongIndex); + String attributeClassWrong = tabWrong.getAttribute("class"); + + Assert.assertTrue("Tab " + wrongIndex + + " should be selected when click on Tab 4", + !attributeClassWrong + .contains("v-tabsheet-tabitemcell-selected")); + } + + /* + * Click on the element. + */ + private void click(int tabIndex) throws InterruptedException { + click(tab(tabIndex)); + } + + /* + * Click on the element. + */ + private void click(TestBenchElement element) throws InterruptedException { + + element.click(10, 10); + if (DELAY > 0) { + sleep(DELAY); + } + } + + /* + * Delay for PhantomJS. + */ + private final static int DELAY = 10; + + /* + * Provide the tab at specified index. + */ + private TestBenchElement tab(int index) { + By by = By.className("v-tabsheet-tabitemcell"); + + TestBenchElement element = (TestBenchElement) getDriver().findElements( + by).get(index - 1); + + String expected = "Tab " + index; + Assert.assertEquals(expected, + element.getText().substring(0, expected.length())); + + return element; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/textfield/EnumTextField.java b/uitest/src/com/vaadin/tests/components/textfield/EnumTextField.java new file mode 100644 index 0000000000..67b3b84688 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/EnumTextField.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.textfield; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.util.ObjectProperty; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.TextField; + +public class EnumTextField extends AbstractTestUIWithLog { + + public enum MyEnum { + FIRST_VALUE, VALUE, THE_LAST_VALUE; + } + + @Override + protected void setup(VaadinRequest request) { + final TextField tf = new TextField(); + tf.addValueChangeListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + if (tf.isValid()) { + log(tf.getValue() + " (valid)"); + } else { + log(tf.getValue() + " (INVALID)"); + } + } + }); + + tf.setPropertyDataSource(new ObjectProperty<Enum>(MyEnum.FIRST_VALUE)); + addComponent(tf); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/textfield/EnumTextFieldTest.java b/uitest/src/com/vaadin/tests/components/textfield/EnumTextFieldTest.java new file mode 100644 index 0000000000..113acee3a2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/EnumTextFieldTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.textfield; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class EnumTextFieldTest extends SingleBrowserTest { + @Test + public void validValues() { + openTestURL(); + $(TextFieldElement.class).first().clear(); + $(TextFieldElement.class).first().sendKeys("Value"); + $(TextFieldElement.class).first().sendKeys(Keys.TAB); + Assert.assertEquals("3. Value (valid)", getLogRow(0)); + + $(TextFieldElement.class).first().clear(); + $(TextFieldElement.class).first().sendKeys("VaLuE"); + $(TextFieldElement.class).first().sendKeys(Keys.TAB); + Assert.assertEquals("5. Value (valid)", getLogRow(0)); + + $(TextFieldElement.class).first().clear(); + $(TextFieldElement.class).first().sendKeys("The last value"); + $(TextFieldElement.class).first().sendKeys(Keys.TAB); + Assert.assertEquals("7. The last value (valid)", getLogRow(0)); + + } + + @Test + public void invalidValue() { + openTestURL(); + $(TextFieldElement.class).first().clear(); + Assert.assertEquals("2. (INVALID)", getLogRow(0)); + + $(TextFieldElement.class).first().sendKeys("bar"); + $(TextFieldElement.class).first().sendKeys(Keys.TAB); + Assert.assertEquals("3. bar (INVALID)", getLogRow(0)); + + } +} diff --git a/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java b/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java new file mode 100644 index 0000000000..a1cabe914e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.components.textfield; + + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.TextField; + +import java.math.BigDecimal; +import java.util.Locale; + +public class LocaleChangeOnReadOnlyField extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final TextField textField = getReadOnlyTextField(); + addComponent(textField); + + Button changeLocaleButton = addLocaleChangeButton(textField); + addComponent(changeLocaleButton); + } + + private TextField getReadOnlyTextField() { + final TextField textField = new TextField(); + + textField.setConverter(BigDecimal.class); + textField.setLocale(Locale.US); + textField.setValue("1024000"); + textField.setReadOnly(true); + + return textField; + } + + private Button addLocaleChangeButton(final TextField textField) { + Button changeLocaleButton = new Button(); + changeLocaleButton.setCaption("Change Locale"); + changeLocaleButton.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + textField.setLocale(Locale.GERMANY); + } + }); + + return changeLocaleButton; + } + + @Override + protected String getTestDescription() { + return "Read-only fields throw exception when setting converted value in localeMightHaveChanged()"; + } + + @Override + protected Integer getTicketNumber() { + return 14400; + } +} diff --git a/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java b/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java new file mode 100644 index 0000000000..03f490c73c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java @@ -0,0 +1,24 @@ +package com.vaadin.tests.components.textfield; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +public class LocaleChangeOnReadOnlyFieldTest extends MultiBrowserTest { + + @Test + public void localeIsChangedOnReadOnlyField() { + openTestURL(); + + TextFieldElement textField = $(TextFieldElement.class).first(); + assertThat(textField.getValue(), is("1,024,000")); + + $(ButtonElement.class).caption("Change Locale").first().click(); + assertThat(textField.getValue(), is("1.024.000")); + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/textfield/RequiredTextField.java b/uitest/src/com/vaadin/tests/components/textfield/RequiredTextField.java new file mode 100644 index 0000000000..79f5a7e83b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/RequiredTextField.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.textfield; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.TextField; + +/** + * Test for required text field. + * + * @author Vaadin Ltd + */ +public class RequiredTextField extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final TextField field = new TextField(); + + addComponent(field); + + Button button = new Button("Set/unset required", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + field.setRequired(!field.isRequired()); + } + }); + addComponent(button); + } + + @Override + protected String getTestDescription() { + return "Add .v-required style when setRequired() is used"; + } + + @Override + protected Integer getTicketNumber() { + return 10201; + } +} diff --git a/uitest/src/com/vaadin/tests/components/textfield/RequiredTextFieldTest.java b/uitest/src/com/vaadin/tests/components/textfield/RequiredTextFieldTest.java new file mode 100644 index 0000000000..c6ed6c1a58 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/RequiredTextFieldTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.textfield; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for .v-required style + * + * @author Vaadin Ltd + */ +public class RequiredTextFieldTest extends MultiBrowserTest { + + @Test + public void testRequiredStyleName() { + openTestURL(); + + $(ButtonElement.class).first().click(); + + Assert.assertTrue("Text field doesn't contain .v-required style", + getStyles().contains("v-required")); + + $(ButtonElement.class).first().click(); + + Assert.assertFalse( + "Text field contains .v-required style for non-required field", + getStyles().contains("v-required")); + } + + private String getStyles() { + return $(TextFieldElement.class).first().getAttribute("class"); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClick.java b/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClick.java new file mode 100644 index 0000000000..8b7890e63c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClick.java @@ -0,0 +1,61 @@ +package com.vaadin.tests.components.tree; + +import com.vaadin.event.ItemClickEvent; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Tree; + +public class TreeItemDoubleClick extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final Tree tree = new Tree("Immediate With ItemClickListener"); + tree.setImmediate(true); + tree.setNullSelectionAllowed(false); + + for (int i = 1; i < 6; i++) { + tree.addItem("Tree Item " + i); + } + + ItemClickEvent.ItemClickListener listener = new ItemClickEvent.ItemClickListener() { + @Override + public void itemClick(ItemClickEvent event) { + if (event.isDoubleClick()) { + log.log("Double Click " + event.getItemId()); + } + } + }; + + tree.addItemClickListener(listener); + + addComponent(tree); + + Button button = new Button("Change immediate flag"); + button.addClickListener(new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + // this wouldn't work if tree had a value change listener + tree.setImmediate(!tree.isImmediate()); + log.log("tree.isImmediate() is now " + tree.isImmediate()); + } + + }); + + addComponent(button); + + } + + @Override + protected String getTestDescription() { + return "Tests that double click is fired"; + } + + @Override + protected Integer getTicketNumber() { + return 14745; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClickTest.java b/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClickTest.java new file mode 100644 index 0000000000..95a3f02d60 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tree/TreeItemDoubleClickTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.tree; + +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TreeItemDoubleClickTest extends MultiBrowserTest { + + @Test + public void test() throws InterruptedException { + openTestURL(); + String caption = "Tree Item 2"; + doubleClick(getTreeNodeByCaption(caption)); + assertLogText("Double Click " + caption); + + changeImmediate(); + + caption = "Tree Item 3"; + doubleClick(getTreeNodeByCaption(caption)); + assertLogText("Double Click " + caption); + } + + private void changeImmediate() { + $(ButtonElement.class).caption("Change immediate flag").first().click(); + assertLogText("tree.isImmediate() is now"); + } + + private WebElement getTreeNodeByCaption(String caption) { + return getDriver().findElement( + By.xpath("//span[text() = '" + caption + "']")); + } + + private void doubleClick(WebElement element) { + new Actions(getDriver()).doubleClick(element).build().perform(); + + } + + private void assertLogText(String text) { + assertThat( + String.format("Couldn't find text '%s' from the log.", text), + logContainsText(text)); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableRowIcons.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTableRowIcons.java new file mode 100644 index 0000000000..0668a6aeeb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableRowIcons.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.components.treetable; + +import static com.vaadin.server.Sizeable.Unit.PIXELS; + +import com.vaadin.server.FontAwesome; +import com.vaadin.server.Resource; +import com.vaadin.server.ThemeResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.TreeTable; + +public class TreeTableRowIcons extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + HorizontalLayout layout = new HorizontalLayout(); + layout.setSpacing(true); + addComponent(layout); + + layout.addComponent(createTreeTableAndPopulate(new ThemeResource( + "../runo/icons/16/ok.png"))); + layout.addComponent(createTreeTableAndPopulate(FontAwesome.ANDROID)); + } + + private TreeTable createTreeTableAndPopulate(Resource icon) { + TreeTable tt = new TreeTable(); + tt.addContainerProperty("Foo", String.class, ""); + tt.setColumnWidth("Foo", 100); + tt.addContainerProperty("Bar", String.class, ""); + tt.setColumnWidth("Bar", 100); + tt.setIcon(icon); + tt.setHeight(400, PIXELS); + + Object item1 = tt.addItem(new Object[] { "Foo", "Bar" }, null); + Object item2 = tt.addItem(new Object[] { "Foo2", "Bar2" }, null); + tt.setItemIcon(item1, icon); + tt.setItemIcon(item2, icon); + + tt.setParent(item2, item1); + + tt.setCollapsed(item1, false); + + return tt; + } + + @Override + protected String getTestDescription() { + return "TreeTable should support font icons for items"; + } + + @Override + protected Integer getTicketNumber() { + return 14077; + } + +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableRowIconsTest.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTableRowIconsTest.java new file mode 100644 index 0000000000..2e299d62ea --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableRowIconsTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.treetable; + +import java.io.IOException; + +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TreeTableRowIconsTest extends MultiBrowserTest { + + public final String SCREENSHOT_NAME = "TreeTableRowIcons"; + + @Test + public void checkScreenshot() throws IOException { + openTestURL(); + compareScreen(SCREENSHOT_NAME); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/ui/ComboboxSelectedItemTextTest.java b/uitest/src/com/vaadin/tests/components/ui/ComboboxSelectedItemTextTest.java index f826654022..ab398035ac 100644 --- a/uitest/src/com/vaadin/tests/components/ui/ComboboxSelectedItemTextTest.java +++ b/uitest/src/com/vaadin/tests/components/ui/ComboboxSelectedItemTextTest.java @@ -18,9 +18,11 @@ package com.vaadin.tests.components.ui; import java.io.IOException; import org.junit.Test; -import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; +import com.vaadin.testbench.By; import com.vaadin.tests.tb3.MultiBrowserTest; /** @@ -59,24 +61,26 @@ public class ComboboxSelectedItemTextTest extends MultiBrowserTest { WebElement comboBoxFocus = vaadinElement("/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[" + indexToFocus + "]/VFilterSelect[0]"); - // Select an element from the first (editable) combobox. + // Select an element from the first (to test) combobox. comboBox.findElement(By.className("v-filterselect-button")).click(); + waitForPopup(comboBox); WebElement comboBoxPopup = vaadinElement("/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[" + indexToTest + "]/VFilterSelect[0]#popup"); comboBoxPopup.findElements(By.tagName("td")).get(2).click(); - // Select an element from the second (non-editable combobox) to remove + // Select an element from the second (to focus) combobox to remove // focus from the first combobox comboBoxFocus.findElement(By.className("v-filterselect-button")) .click(); + waitForPopup(comboBoxFocus); comboBoxPopup = vaadinElement("/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[" + indexToFocus + "]/VFilterSelect[0]#popup"); comboBoxPopup.findElements(By.tagName("td")).get(2).click(); - // click the popup on the first combobox. This would reveal the unwanted - // behaviour. + // click the button of the first combobox. This would reveal the + // unwanted behaviour. comboBox.findElement(By.className("v-filterselect-button")).click(); @@ -87,4 +91,13 @@ public class ComboboxSelectedItemTextTest extends MultiBrowserTest { } + private void waitForPopup(final WebElement comboBox) { + waitUntilNot(new ExpectedCondition<Boolean>() { + @Override + public Boolean apply(WebDriver input) { + return comboBox.findElements(By.vaadin("#popup")).isEmpty(); + } + }, 10); + } + }
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleName.java b/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleName.java new file mode 100644 index 0000000000..35dc4cd325 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleName.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.ui; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; + +/** + * Empty test ui to check auto-generated style name for UI. + * + * @author Vaadin Ltd + */ +public class UIAutoGeneratedStyleName extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + } + + @Override + protected String getTestDescription() { + return "Add UI specific autogenerated style name to ui div element" + + " and overlays container"; + } + + @Override + protected Integer getTicketNumber() { + return 14670; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleNameTest.java b/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleNameTest.java new file mode 100644 index 0000000000..73e0a7f6b9 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleNameTest.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.components.ui; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.Locale; + +/** + * Test to check auto-generated style name for UI div and overlays div. + * + * @author Vaadin Ltd + */ +public class UIAutoGeneratedStyleNameTest extends MultiBrowserTest { + + @Test + public void testUiStyleName() { + openTestURL(); + + Assert.assertTrue( + "UI div element doesn't contain autogenerated style name", + containsStyle(getDriver().findElement(By.className("v-app")), + UIAutoGeneratedStyleName.class.getSimpleName() + .toLowerCase(Locale.ENGLISH))); + + Assert.assertTrue( + "Overlays div element doesn't contain autogenerated style name", + containsStyle( + getDriver().findElement( + By.className("v-overlay-container")), + UIAutoGeneratedStyleName.class.getSimpleName() + .toLowerCase(Locale.ENGLISH))); + } + + private boolean containsStyle(WebElement element, String style) { + return element.getAttribute("class").contains(style); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java b/uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java index cbe4dbdf29..2b6ba40e8c 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java +++ b/uitest/src/com/vaadin/tests/components/ui/UISerializationTest.java @@ -1,18 +1,17 @@ package com.vaadin.tests.components.ui; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; - -import org.junit.Test; - import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.tests.tb3.SingleBrowserTest; +import org.junit.Ignore; +import org.junit.Test; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertThat; public class UISerializationTest extends SingleBrowserTest { + @Test + @Ignore //Broken on all browsers since 9696e6c3e7e952b66ac3f5c9ddc3dfca4233451e public void tb2test() throws Exception { openTestURL(); $(ButtonElement.class).first().click(); diff --git a/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAriaTest.java b/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAriaTest.java index 44aea3522a..4ec1dc5c98 100644 --- a/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAriaTest.java +++ b/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAriaTest.java @@ -47,26 +47,26 @@ public class ExtraWindowShownWaiAriaTest extends MultiBrowserTest { assertFalse(buttons.isEmpty()); // open alert dialog - buttons.get(0).click(); + ButtonElement button = buttons.get(0); + button.click(); // ensure dialog opened - List<WindowElement> windows = $(WindowElement.class).all(); - assertFalse(windows.isEmpty()); + waitForElementPresent(By.className("v-window")); + WindowElement window = $(WindowElement.class).first(); // ensure correct attributes - assertEquals("alertdialog", windows.get(0).getAttribute("role")); + assertEquals("alertdialog", window.getAttribute("role")); - WebElement header = windows.get(0).findElement( - By.className("v-window-header")); + WebElement header = window.findElement(By.className("v-window-header")); assertEquals(header.getAttribute("id"), - windows.get(0).getAttribute("aria-labelledby")); + window.getAttribute("aria-labelledby")); - WebElement label = windows.get(0).findElement(By.className("v-label")); + WebElement label = window.findElement(By.className("v-label")); assertEquals(label.getAttribute("id"), - windows.get(0).getAttribute("aria-describedby")); + window.getAttribute("aria-describedby")); - List<WebElement> wButtons = windows.get(0).findElements( - By.className("v-button")); + List<WebElement> wButtons = window.findElements(By + .className("v-button")); assertEquals("button", wButtons.get(0).getAttribute("role")); assertEquals("button", wButtons.get(1).getAttribute("role")); @@ -74,7 +74,7 @@ public class ExtraWindowShownWaiAriaTest extends MultiBrowserTest { wButtons.get(0).click(); // ensure dialog closed - windows = $(WindowElement.class).all(); + List<WindowElement> windows = $(WindowElement.class).all(); assertTrue(windows.isEmpty()); // check additional description (second checkbox on the page) @@ -87,19 +87,20 @@ public class ExtraWindowShownWaiAriaTest extends MultiBrowserTest { assertEquals("true", input.getAttribute("checked")); // open alert dialog - buttons = $(ButtonElement.class).all(); - buttons.get(0).click(); + button = $(ButtonElement.class).first(); + button.click(); + + waitForElementPresent(By.className("v-window")); // ensure correct attributes - windows = $(WindowElement.class).all(); - List<WebElement> labels = windows.get(0).findElements( - By.className("v-label")); + window = $(WindowElement.class).first(); + List<WebElement> labels = window.findElements(By.className("v-label")); assertEquals(labels.get(0).getAttribute("id") + " " - + labels.get(1).getAttribute("id"), windows.get(0) - .getAttribute("aria-describedby")); + + labels.get(1).getAttribute("id"), + window.getAttribute("aria-describedby")); // close dialog - wButtons = windows.get(0).findElements(By.className("v-button")); + wButtons = window.findElements(By.className("v-button")); wButtons.get(0).click(); // ensure dialog closed @@ -112,12 +113,14 @@ public class ExtraWindowShownWaiAriaTest extends MultiBrowserTest { textFields.get(1).sendKeys(" - do ASAP"); // open alert dialog - buttons = $(ButtonElement.class).all(); - buttons.get(0).click(); + button = $(ButtonElement.class).first(); + button.click(); + + waitForElementPresent(By.className("v-window")); // ensure the assistive spans have been added to the header - windows = $(WindowElement.class).all(); - header = windows.get(0).findElement(By.className("v-window-header")); + window = $(WindowElement.class).first(); + header = window.findElement(By.className("v-window-header")); List<WebElement> assistiveElements = header.findElements(By .className("v-assistive-device-only")); assertEquals("Important", diff --git a/uitest/src/com/vaadin/tests/components/window/WindowWithIcon.java b/uitest/src/com/vaadin/tests/components/window/WindowWithIcon.java new file mode 100644 index 0000000000..15ceb569b4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowWithIcon.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.components.window; + +import com.vaadin.server.FontAwesome; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Window; + +public class WindowWithIcon extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Window window = new Window("Window Caption"); + window.setIcon(FontAwesome.ROCKET); + addWindow(window); + } + + @Override + protected String getTestDescription() { + return "Window should work properly with font icons."; + } + + @Override + protected Integer getTicketNumber() { + return 14481; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/window/WindowWithIconTest.java b/uitest/src/com/vaadin/tests/components/window/WindowWithIconTest.java new file mode 100644 index 0000000000..25c7f57238 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowWithIconTest.java @@ -0,0 +1,16 @@ +package com.vaadin.tests.components.window; + +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class WindowWithIconTest extends MultiBrowserTest { + + @Test + public void testWindowWithIcon() throws Exception { + openTestURL(); + + compareScreen("icon-rendered-properly"); + } + +} diff --git a/uitest/src/com/vaadin/tests/fonticon/FontIconsTest.java b/uitest/src/com/vaadin/tests/fonticon/FontIconsTest.java index 61a38bf552..948c3c13b2 100644 --- a/uitest/src/com/vaadin/tests/fonticon/FontIconsTest.java +++ b/uitest/src/com/vaadin/tests/fonticon/FontIconsTest.java @@ -15,9 +15,14 @@ */ package com.vaadin.tests.fonticon; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; import com.vaadin.tests.tb3.MultiBrowserTest; @@ -28,4 +33,33 @@ public class FontIconsTest extends MultiBrowserTest { openTestURL(); compareScreen("all"); } + + @Test + public void comboBoxItemIconsOnKeyboardNavigation() throws Exception { + openTestURL(); + WebElement comboBoxInput = getDriver().findElement( + By.className("v-filterselect-input")); + + // No initial value. + assertEquals("", comboBoxInput.getText()); + + // Navigate to the first item with keyboard navigation. + sendKeys(comboBoxInput, Keys.ARROW_DOWN, Keys.ARROW_DOWN, + Keys.ARROW_DOWN); + + // Value must be "One" without any extra characters. + // See ticket #14660 + assertEquals("One", comboBoxInput.getAttribute("value")); + + // Check also the second item. + sendKeys(comboBoxInput, Keys.ARROW_DOWN); + assertEquals("Two", comboBoxInput.getAttribute("value")); + } + + private void sendKeys(WebElement element, Keys... keys) throws Exception { + for (Keys key : keys) { + element.sendKeys(key); + sleep(10); // For PhantomJS. + } + } } diff --git a/uitest/src/com/vaadin/tests/push/ReconnectLongPollingTest.java b/uitest/src/com/vaadin/tests/push/ReconnectLongPollingTest.java index 28ef30a04a..22d020b631 100644 --- a/uitest/src/com/vaadin/tests/push/ReconnectLongPollingTest.java +++ b/uitest/src/com/vaadin/tests/push/ReconnectLongPollingTest.java @@ -15,9 +15,22 @@ */ package com.vaadin.tests.push; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.util.List; + public class ReconnectLongPollingTest extends ReconnectTest { @Override + public List<DesiredCapabilities> getBrowsersToTest() { + + // PhantomJS doesn't seem to detect disconnection on + // Long-Polling/Streaming: + // https://github.com/ariya/phantomjs/issues/11938 + return getBrowsersExcludingPhantomJS(); + } + + @Override protected Class<?> getUIClass() { return BasicPushLongPolling.class; } diff --git a/uitest/src/com/vaadin/tests/push/ReconnectStreamingTest.java b/uitest/src/com/vaadin/tests/push/ReconnectStreamingTest.java index 0a0275c4d0..4a669e723c 100755 --- a/uitest/src/com/vaadin/tests/push/ReconnectStreamingTest.java +++ b/uitest/src/com/vaadin/tests/push/ReconnectStreamingTest.java @@ -15,9 +15,22 @@ */ package com.vaadin.tests.push; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.util.List; + public class ReconnectStreamingTest extends ReconnectTest { @Override + public List<DesiredCapabilities> getBrowsersToTest() { + + // PhantomJS doesn't seem to detect disconnection on + // Long-Polling/Streaming: + // https://github.com/ariya/phantomjs/issues/11938 + return getBrowsersExcludingPhantomJS(); + } + + @Override protected Class<?> getUIClass() { return BasicPushStreaming.class; } diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 1d03a7df76..76b851fd23 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -40,6 +40,7 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicHttpEntityEnclosingRequest; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -94,6 +95,10 @@ import elemental.json.impl.JsonUtil; */ @RunWith(value = TB3Runner.class) public abstract class AbstractTB3Test extends TestBenchTestCase { + + @Rule + public RetryOnFail retry = new RetryOnFail(); + /** * Height of the screenshots we want to capture */ diff --git a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java index 72fb2c18d1..d6eed3e5c8 100644 --- a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java +++ b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java @@ -40,6 +40,14 @@ import org.openqa.selenium.remote.DesiredCapabilities; */ public abstract class MultiBrowserTest extends PrivateTB3Configuration { + protected List<DesiredCapabilities> getBrowsersExcludingPhantomJS() { + List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>(getAllBrowsers()); + + browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities()); + + return browsers; + } + protected List<DesiredCapabilities> getBrowsersExcludingIE() { List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>(getAllBrowsers()); browsers.remove(Browser.IE8.getDesiredCapabilities()); @@ -50,7 +58,6 @@ public abstract class MultiBrowserTest extends PrivateTB3Configuration { return browsers; } - protected List<DesiredCapabilities> getBrowsersSupportingShiftClick() { List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>(getAllBrowsers()); diff --git a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java index ff824ad98a..a4bb85bb53 100644 --- a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java +++ b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java @@ -49,6 +49,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { private static final String RUN_LOCALLY_PROPERTY = "com.vaadin.testbench.runLocally"; private static final String HOSTNAME_PROPERTY = "com.vaadin.testbench.deployment.hostname"; private static final String PORT_PROPERTY = "com.vaadin.testbench.deployment.port"; + private static final String DEPLOYMENT_PROPERTY = "com.vaadin.testbench.deployment.url"; private static final Properties properties = new Properties(); private static final File propertiesFile = new File("work", "eclipse-run-selected-test.properties"); @@ -97,6 +98,15 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { } @Override + protected String getBaseURL() { + String url = getProperty(DEPLOYMENT_PROPERTY); + if (url == null || url.trim().isEmpty()) { + return super.getBaseURL(); + } + return url; + } + + @Override protected String getDeploymentHostname() { if (getRunLocallyBrowser() != null) { return "localhost"; @@ -180,7 +190,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { /* * (non-Javadoc) - * + * * @see com.vaadin.tests.tb3.AbstractTB3Test#setupLocalDriver() */ @Override diff --git a/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java b/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java index 9c12147314..3c22057863 100644 --- a/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java +++ b/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java @@ -19,20 +19,7 @@ import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -/** - * <strong>ALWAYS</strong> declare the reason for using this test rule in a - * test. - * - * <p> - * Violators and abusers of this rule will be punished. - * </p> - * - * @since 7.1.14 - * @author Vaadin Ltd - */ public class RetryOnFail implements TestRule { - private int retryCount = 1; - @Override public Statement apply(Statement base, Description description) { return statement(base, description); @@ -44,6 +31,7 @@ public class RetryOnFail implements TestRule { @Override public void evaluate() throws Throwable { Throwable caughtThrowable = null; + int retryCount = getRetryCount(); for (int i = 0; i <= retryCount; i++) { try { @@ -60,6 +48,16 @@ public class RetryOnFail implements TestRule { } throw caughtThrowable; } + + private int getRetryCount() { + String retryCount = System.getProperty("com.vaadin.testbench.max.retries"); + + if(retryCount != null && retryCount != "") { + return Integer.parseInt(retryCount); + } + + return 0; + } }; } } diff --git a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java index a99eea9bf6..ed5a2ed8aa 100644 --- a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java @@ -68,13 +68,15 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { * Contains a list of screenshot identifiers for which * {@link #compareScreen(String)} has failed during the test */ - private List<String> screenshotFailures = new ArrayList<String>(); + private List<String> screenshotFailures; /** * Defines TestBench screen comparison parameters before each test run */ @Before public void setupScreenComparisonParameters() { + screenshotFailures = new ArrayList<String>(); + Parameters.setScreenshotErrorDirectory(getScreenshotErrorDirectory()); Parameters .setScreenshotReferenceDirectory(getScreenshotReferenceDirectory()); diff --git a/uitest/src/com/vaadin/tests/themes/FaviconTest.java b/uitest/src/com/vaadin/tests/themes/FaviconTest.java new file mode 100644 index 0000000000..31134f656f --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/FaviconTest.java @@ -0,0 +1,60 @@ +package com.vaadin.tests.themes; + +import com.vaadin.tests.tb3.SingleBrowserTest; +import org.junit.Test; + +import java.net.HttpURLConnection; +import java.net.URL; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.fail; + +//Extending SingleBrowserTest just to include the test into our test suites. +public class FaviconTest extends SingleBrowserTest { + + @Test + public void chameleonHasFavicon() { + assertThatThemeHasFavicon("chameleon"); + } + + @Test + public void liferayHasFavicon() { + assertThatThemeHasFavicon("liferay"); + } + + @Test + public void runoHasFavicon() { + assertThatThemeHasFavicon("runo"); + } + + @Test + public void reindeerHasFavicon() { + assertThatThemeHasFavicon("reindeer"); + } + + @Test + public void valoHasFavicon() { + assertThatThemeHasFavicon("valo"); + } + + private void assertThatThemeHasFavicon(String theme) { + assertThat(getResponseCode(theme), is(200)); + } + + private int getResponseCode(String theme) { + try { + URL url = new URL(String.format("%s/VAADIN/themes/%s/favicon.ico", getBaseURL(), theme)); + HttpURLConnection connection = (HttpURLConnection)url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + + return connection.getResponseCode(); + + } catch (Exception e) { + fail(e.getMessage()); + } + + return 0; + } +} diff --git a/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFlyTest.java b/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFlyTest.java index eb010e82ee..a5657c4eec 100644 --- a/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFlyTest.java +++ b/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFlyTest.java @@ -15,10 +15,8 @@ */ package com.vaadin.tests.themes; -import java.io.IOException; -import java.util.List; - -import org.junit.Assert; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; @@ -26,8 +24,11 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedCondition; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.tests.tb3.MultiBrowserTest; +import java.io.IOException; +import java.util.List; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; public class ThemeChangeOnTheFlyTest extends MultiBrowserTest { @@ -100,9 +101,8 @@ public class ThemeChangeOnTheFlyTest extends MultiBrowserTest { @Override public Boolean apply(WebDriver input) { String rootClass = rootDiv.getAttribute("class").trim(); - String expected = "v-app " + theme; - expected = expected.trim(); - return rootClass.equals(expected); + + return rootClass.contains(theme); } }, 30); } @@ -110,12 +110,9 @@ public class ThemeChangeOnTheFlyTest extends MultiBrowserTest { private void assertOverlayTheme(String theme) { final WebElement overlayContainerDiv = findElement(By .xpath("//div[contains(@class,'v-overlay-container')]")); - String expected = "v-app v-overlay-container " + theme; - expected = expected.trim(); - String overlayClass = overlayContainerDiv.getAttribute("class").trim(); - Assert.assertEquals(expected, overlayClass); + assertThat(overlayClass, containsString(theme)); } } diff --git a/uitest/src/com/vaadin/tests/themes/valo/DateFields.java b/uitest/src/com/vaadin/tests/themes/valo/DateFields.java index 5dca5ab9af..5a752cd985 100644 --- a/uitest/src/com/vaadin/tests/themes/valo/DateFields.java +++ b/uitest/src/com/vaadin/tests/themes/valo/DateFields.java @@ -190,6 +190,7 @@ public class DateFields extends VerticalLayout implements View { date = new InlineDateField("Date picker"); setDate(date); + setDateRange(date); row.addComponent(date); date = new InlineDateField("Date picker with week numbers"); @@ -211,6 +212,14 @@ public class DateFields extends VerticalLayout implements View { row.addComponent(form); } + private void setDateRange(DateField date) { + date.setRangeStart(getDefaultDate()); + + Date endDate = getDefaultDate(); + endDate.setMonth(endDate.getMonth() + 1); + date.setRangeEnd(endDate); + } + private void setDate(DateField date) { date.setValue(getDefaultDate()); } diff --git a/uitest/src/com/vaadin/tests/themes/valo/TableWithEmptyCaption.java b/uitest/src/com/vaadin/tests/themes/valo/TableWithEmptyCaption.java new file mode 100644 index 0000000000..a3a81b3798 --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/valo/TableWithEmptyCaption.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.themes.valo; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.Table; + +@Theme("valo") +public class TableWithEmptyCaption extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Table table = new Table(); + table.addContainerProperty("first", String.class, ""); + table.addContainerProperty("last", String.class, ""); + table.addContainerProperty("actions", Component.class, null); + + table.addItem(new Object[] { "Teemu", "Test", new Button("Edit") }, 1); + table.addItem(new Object[] { "Dummy", "Test", new Button("Edit") }, 2); + + table.setPageLength(0); + table.setColumnHeaders("First Name", "Last Name", ""); + + table.setFooterVisible(true); + table.setColumnFooter("first", "Footer"); + table.setColumnFooter("last", ""); + table.setColumnFooter("actions", ""); + addComponent(table); + } + + @Override + protected String getTestDescription() { + return "Test that column headers (and footers) work properly with empty captions."; + } + + @Override + protected Integer getTicketNumber() { + return 14812; + } +} diff --git a/uitest/src/com/vaadin/tests/themes/valo/TableWithEmptyCaptionTest.java b/uitest/src/com/vaadin/tests/themes/valo/TableWithEmptyCaptionTest.java new file mode 100644 index 0000000000..04de8b498c --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/valo/TableWithEmptyCaptionTest.java @@ -0,0 +1,42 @@ +/* + * 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.themes.valo; + +import org.junit.Test; +import org.openqa.selenium.TimeoutException; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableWithEmptyCaptionTest extends MultiBrowserTest { + + @Test + public void testEmptyCaption() throws Exception { + openTestURL(); + + // Wait for the loading bar to disappear before taking the screenshot. + try { + waitUntil(ExpectedConditions.invisibilityOfElementLocated(By + .className("v-loading-indicator")), 5); + } catch (TimeoutException e) { + // Just take the screenshot, PhantomJS always times out. + } + + compareScreen("table-empty-caption"); + } + +} diff --git a/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java b/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java index 20c74bff5e..d4ddf2dcf9 100644 --- a/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java +++ b/uitest/src/com/vaadin/tests/themes/valo/ValoThemeUITest.java @@ -64,7 +64,7 @@ public class ValoThemeUITest extends MultiBrowserTest { // Note that this can look broken in IE9 because of some browser // rendering issue... The problem seems to be in the customized // horizontal layout in the test app - compareScreen("datefields-with-disabled"); + compareScreen("datefields-with-range"); } @Test |