summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorJouni Koivuviita <jouni@vaadin.com>2014-06-27 10:47:29 +0300
committerJouni Koivuviita <jouni@vaadin.com>2014-06-27 10:48:01 +0300
commitc3e4b560f226b4c544cdab455ecabecd5c85d02c (patch)
tree4992698626695929fb158282f6a423f0de584891 /uitest
parentb20adbbded1f0b04dcbc7074b166339eb884dcc1 (diff)
parent2f18ad6f186051f9540cf13784c0936683b11bae (diff)
downloadvaadin-framework-c3e4b560f226b4c544cdab455ecabecd5c85d02c.tar.gz
vaadin-framework-c3e4b560f226b4c544cdab455ecabecd5c85d02c.zip
Merge branch 'master' into valo
Change-Id: Iffe877e047ee29dbd4e5b3a6098f82da3d0a47cc
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java1
-rw-r--r--uitest/src/com/vaadin/tests/components/combobox/ComboBoxOnSmallScreen.java64
-rw-r--r--uitest/src/com/vaadin/tests/components/combobox/ComboBoxOnSmallScreenTest.java108
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java2
-rw-r--r--uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptPreloading.java65
-rw-r--r--uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptPreloadingTest.java74
-rwxr-xr-xuitest/src/com/vaadin/tests/components/javascriptcomponent/js_label.js11
-rwxr-xr-xuitest/src/com/vaadin/tests/components/javascriptcomponent/wholly_different.js3
-rw-r--r--uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java26
-rw-r--r--uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java103
-rw-r--r--uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFlyTest.java110
11 files changed, 389 insertions, 178 deletions
diff --git a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
index d94518ca9c..e6e54a57a6 100644
--- a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
+++ b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
@@ -142,6 +142,7 @@ public class DevelopmentServerLauncher {
assignDefault(serverArgs, "webroot", "WebContent");
assignDefault(serverArgs, "httpPort", "" + serverPort);
assignDefault(serverArgs, "context", "");
+ assignDefault(serverArgs, "slowdown", "/run/APP/PUBLISHED/js_label.js");
int port = serverPort;
try {
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxOnSmallScreen.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxOnSmallScreen.java
deleted file mode 100644
index c50e483c44..0000000000
--- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxOnSmallScreen.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.components.combobox;
-
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUI;
-import com.vaadin.ui.Alignment;
-import com.vaadin.ui.ComboBox;
-import com.vaadin.ui.VerticalLayout;
-
-/**
- * Test UI for issue #11929 where ComboBox suggestion popup hides the ComboBox
- * itself obscuring the text input field.
- *
- * @author Vaadin Ltd
- */
-public class ComboBoxOnSmallScreen extends AbstractTestUI {
-
- private static final String PID = "captionPID";
-
- @Override
- protected void setup(VaadinRequest request) {
- addComponents(createComboBox(), createComboBox());
- VerticalLayout vl = getLayout();
- vl.setHeight(300, Unit.PIXELS);
- vl.setComponentAlignment(vl.getComponent(1), Alignment.BOTTOM_LEFT);
- }
-
- @Override
- protected String getTestDescription() {
- return "Combobox hides what you are typing on small screen";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return 11929;
- }
-
- private ComboBox createComboBox() {
- ComboBox cb = new ComboBox();
- cb.addContainerProperty(PID, String.class, "");
- cb.setItemCaptionPropertyId(PID);
-
- for (int i = 1; i < 21; ++i) {
- final String v = "Item #" + i;
- cb.getItem(cb.addItem()).getItemProperty(PID).setValue(v);
- }
-
- return cb;
- }
-}
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxOnSmallScreenTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxOnSmallScreenTest.java
deleted file mode 100644
index c45168aa6d..0000000000
--- a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxOnSmallScreenTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.components.combobox;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-import org.junit.Test;
-import org.openqa.selenium.By;
-import org.openqa.selenium.Dimension;
-import org.openqa.selenium.WebDriver.Window;
-import org.openqa.selenium.WebElement;
-
-import com.vaadin.client.ui.VFilterSelect;
-import com.vaadin.testbench.elements.ComboBoxElement;
-import com.vaadin.tests.tb3.MultiBrowserTest;
-
-/**
- * ComboBox suggestion popup should not obscure the text input box.
- *
- * @author Vaadin Ltd
- */
-public class ComboBoxOnSmallScreenTest extends MultiBrowserTest {
-
- private static final Dimension TARGETSIZE = new Dimension(600, 300);
- private static final String POPUPCLASSNAME = VFilterSelect.CLASSNAME
- + "-suggestpopup";
-
- @Override
- public void setup() throws Exception {
- super.setup();
-
- openTestURL();
-
- getWindow().setSize(TARGETSIZE);
- }
-
- @Test
- public void testUpperSuggestionPopupOverlayPosition() {
- ComboBoxElement cb = getComboBoxAndOpenPopup(0);
- assertOverlayPosition(cb, getPopup());
- }
-
- @Test
- public void testUpperSuggestionPopupOverlaySize() {
- ComboBoxElement cb = getComboBoxAndOpenPopup(0);
- assertOverlaySize(cb, getPopup());
- }
-
- @Test
- public void testLowerSuggestionPopupOverlayPosition() {
- ComboBoxElement cb = getComboBoxAndOpenPopup(1);
- assertOverlayPosition(cb, getPopup());
- }
-
- @Test
- public void testLowerSuggestionPopupOverlaySize() {
- ComboBoxElement cb = getComboBoxAndOpenPopup(1);
- assertOverlaySize(cb, getPopup());
- }
-
- private void assertOverlayPosition(WebElement combobox, WebElement popup) {
- final int popupTop = popup.getLocation().y;
- final int popupBottom = popupTop + popup.getSize().getHeight();
- final int cbTop = combobox.getLocation().y;
- final int cbBottom = cbTop + combobox.getSize().getHeight();
-
- assertThat("Popup overlay does not overlap with the textbox",
- popupTop >= cbBottom || popupBottom <= cbTop, is(true));
- }
-
- private void assertOverlaySize(WebElement combobox, WebElement popup) {
- final int popupTop = popup.getLocation().y;
- final int popupBottom = popupTop + popup.getSize().getHeight();
- final int rootHeight = findElement(By.tagName("body")).getSize().height;
-
- assertThat("Popup overlay inside the viewport", popupTop < 0
- || popupBottom > rootHeight, is(false));
- }
-
- private ComboBoxElement getComboBoxAndOpenPopup(int comboboxIndex) {
- ComboBoxElement cb = $(ComboBoxElement.class).get(comboboxIndex);
- cb.openPopup();
- return cb;
- }
-
- private WebElement getPopup() {
- return findElement(By.className(POPUPCLASSNAME));
- }
-
- private Window getWindow() {
- return getDriver().manage().window();
- }
-
-}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java
index 96e17344ec..289a5988ee 100644
--- a/uitest/src/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java
+++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java
@@ -17,7 +17,7 @@ public class DateFieldReadOnlyTest extends MultiBrowserTest {
public void readOnlyDateFieldPopupShouldNotOpen() throws IOException, InterruptedException {
openTestURL();
- compareScreen("readonly");
+ compareScreen("initial");
toggleReadOnly();
openPopup();
diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptPreloading.java b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptPreloading.java
new file mode 100644
index 0000000000..f9ef4c98cb
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptPreloading.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.javascriptcomponent;
+
+import com.vaadin.annotations.JavaScript;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.JavaScriptComponentState;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.util.Log;
+import com.vaadin.ui.AbstractJavaScriptComponent;
+
+public class JavaScriptPreloading extends AbstractTestUI {
+
+ public static class JsLabelState extends JavaScriptComponentState {
+ public String xhtml;
+ }
+
+ @JavaScript({ "js_label.js", "wholly_different.js" })
+ public class JsLabel extends AbstractJavaScriptComponent {
+
+ public JsLabel(final String xhtml) {
+ getState().xhtml = xhtml;
+ }
+
+ @Override
+ protected JsLabelState getState() {
+ return (JsLabelState) super.getState();
+ }
+ }
+
+ private final Log log = new Log(5);
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(log);
+
+ final JsLabel c = new JsLabel("Hello World!");
+ c.setId("js-component");
+ addComponent(c);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Loading javascript component with multiple sourcefiles should not break IE11";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return Integer.valueOf(13956);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptPreloadingTest.java b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptPreloadingTest.java
new file mode 100644
index 0000000000..a9e7a1bca7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/JavaScriptPreloadingTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.javascriptcomponent;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.Alert;
+import org.openqa.selenium.TimeoutException;
+import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class JavaScriptPreloadingTest extends MultiBrowserTest {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.tb3.MultiBrowserTest#getBrowsersToTest()
+ */
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ List<DesiredCapabilities> browsers = super.getBrowsersToTest();
+ browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities());
+ return browsers;
+ }
+
+ @Test
+ public void scriptsShouldPreloadAndExecuteInCorrectOrder()
+ throws InterruptedException {
+ openTestURL();
+
+ try {
+ new WebDriverWait(driver, 10).until(ExpectedConditions
+ .alertIsPresent());
+ Alert alert = driver.switchTo().alert();
+ assertEquals("First", alert.getText());
+ alert.accept();
+
+ new WebDriverWait(driver, 10).until(ExpectedConditions
+ .alertIsPresent());
+ alert = driver.switchTo().alert();
+ assertEquals("Second", alert.getText());
+ alert.accept();
+
+ } catch (TimeoutException te) {
+ fail("@Javascript widget loading halted.");
+ }
+
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/js_label.js b/uitest/src/com/vaadin/tests/components/javascriptcomponent/js_label.js
new file mode 100755
index 0000000000..c4900daa81
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/js_label.js
@@ -0,0 +1,11 @@
+window.com_vaadin_tests_components_javascriptcomponent_JavaScriptPreloading_JsLabel = function() {
+ var e = this.getElement();
+
+ (function() {
+ e.innerHTML = "Widget executed javascript";
+ })();
+};
+
+(function() {
+ window.alert("First");
+})();
diff --git a/uitest/src/com/vaadin/tests/components/javascriptcomponent/wholly_different.js b/uitest/src/com/vaadin/tests/components/javascriptcomponent/wholly_different.js
new file mode 100755
index 0000000000..f22ef13a76
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/javascriptcomponent/wholly_different.js
@@ -0,0 +1,3 @@
+(function() {
+ window.alert("Second");
+})();
diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
index 406f1fe27c..14be226de6 100644
--- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
+++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
@@ -16,6 +16,8 @@
package com.vaadin.tests.tb3;
+import static com.vaadin.tests.tb3.TB3Runner.localWebDriverIsUsed;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -24,7 +26,6 @@ import java.net.URL;
import java.util.Collections;
import java.util.List;
-import com.vaadin.testbench.TestBenchElement;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
@@ -49,13 +50,12 @@ import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
import com.vaadin.server.LegacyApplication;
import com.vaadin.server.UIProvider;
import com.vaadin.testbench.TestBench;
+import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.TestBenchTestCase;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
import com.vaadin.ui.UI;
-import static com.vaadin.tests.tb3.TB3Runner.localWebDriverIsUsed;
-
/**
* Base class for TestBench 3+ tests. All TB3+ tests in the project should
* extend this class.
@@ -157,7 +157,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
}
protected WebElement getTooltipElement() {
- return getDriver().findElement(com.vaadin.testbench.By.className("v-tooltip-text"));
+ return getDriver().findElement(
+ com.vaadin.testbench.By.className("v-tooltip-text"));
}
protected Coordinates getCoordinates(TestBenchElement element) {
@@ -184,7 +185,22 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
* {@link #isPush()}.
*/
protected void openTestURL() {
- driver.get(getTestUrl());
+ openTestURL("");
+ }
+
+ /**
+ * Opens the given test (defined by {@link #getTestUrl()}, optionally with
+ * debug window and/or push (depending on {@link #isDebug()} and
+ * {@link #isPush()}.
+ */
+ protected void openTestURL(String extraParameters) {
+ String url = getTestUrl();
+ if (url.contains("?")) {
+ url = url + "&" + extraParameters;
+ } else {
+ url = url + "?" + extraParameters;
+ }
+ driver.get(url);
}
/**
diff --git a/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java b/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java
new file mode 100644
index 0000000000..8989d88164
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFly.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2000-2013 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;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.server.ThemeResource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.util.PersonContainer;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Image;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+
+@Theme("reindeer")
+public class ThemeChangeOnTheFly extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Button inject = new Button("Inject blue background");
+ inject.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ getPage().getStyles().add(
+ ".v-app { background: blue !important;}");
+
+ }
+ });
+ addComponent(inject);
+
+ GridLayout gl = new GridLayout(2, 4);
+ gl.setCaption("Change theme by clicking a button");
+ for (final String theme : new String[] { "reindeer", "runo",
+ "chameleon", "base", null }) {
+ Button b = new Button(theme);
+ b.setId(theme + "");
+ b.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ getUI().setTheme(theme);
+ }
+ });
+ gl.addComponent(b);
+ }
+
+ Table t = new Table();
+ PersonContainer pc = PersonContainer.createWithTestData();
+ pc.addNestedContainerBean("address");
+ t.setContainerDataSource(pc);
+ gl.addComponent(t, 0, 3, 1, 3);
+ gl.setRowExpandRatio(3, 1);
+
+ gl.setWidth("500px");
+ gl.setHeight("800px");
+
+ HorizontalLayout images = new HorizontalLayout();
+ images.setSpacing(true);
+
+ Label l = new Label("Chameleon theme image in caption");
+ l.setIcon(new ThemeResource("img/magnifier.png"));
+ images.addComponent(l);
+ Image image = new Image("Runo theme image", new ThemeResource(
+ "icons/64/ok.png"));
+ images.addComponent(image);
+ image = new Image("Reindeer theme image", new ThemeResource(
+ "button/img/left-focus.png"));
+ images.addComponent(image);
+ addComponent(images);
+ addComponent(gl);
+
+ getLayout().setSpacing(true);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Test that you can change theme on the fly";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 2874;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFlyTest.java b/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFlyTest.java
new file mode 100644
index 0000000000..681a7d762b
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/themes/ThemeChangeOnTheFlyTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2000-2013 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;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+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;
+
+public class ThemeChangeOnTheFlyTest extends MultiBrowserTest {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.tb3.MultiBrowserTest#getBrowsersToTest()
+ */
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ // Seems like stylesheet onload is not fired on PhantomJS
+ List<DesiredCapabilities> l = super.getBrowsersToTest();
+ l.remove(Browser.PHANTOMJS.getDesiredCapabilities());
+ return l;
+ }
+
+ @Test
+ public void injectedStyleAndThemeChange() throws IOException {
+ openTestURL();
+ $(ButtonElement.class).caption("Inject blue background").first()
+ .click();
+ changeTheme("runo");
+ compareScreen("runo-blue-background");
+ }
+
+ @Test
+ public void reindeerToOthers() throws IOException {
+ openTestURL();
+ compareScreen("reindeer");
+
+ changeThemeAndCompare("runo");
+ changeThemeAndCompare("chameleon");
+ changeThemeAndCompare("base");
+
+ }
+
+ @Test
+ public void runoToReindeer() throws IOException {
+ openTestURL("theme=runo");
+ compareScreen("runo");
+ changeThemeAndCompare("reindeer");
+ }
+
+ @Test
+ public void reindeerToNullToReindeer() throws IOException {
+ openTestURL();
+
+ changeThemeAndCompare("null");
+ changeThemeAndCompare("reindeer");
+ }
+
+ private void changeThemeAndCompare(String theme) throws IOException {
+ changeTheme(theme);
+ compareScreen(theme);
+ }
+
+ private void changeTheme(String theme) {
+ $(ButtonElement.class).id(theme).click();
+ if (theme.equals("null")) {
+ waitForThemeToChange("");
+ } else {
+ waitForThemeToChange(theme);
+ }
+ }
+
+ private void waitForThemeToChange(final String theme) {
+
+ final WebElement rootDiv = findElement(By
+ .xpath("//div[contains(@class,'v-app')]"));
+ waitUntil(new ExpectedCondition<Boolean>() {
+
+ @Override
+ public Boolean apply(WebDriver input) {
+ String rootClass = rootDiv.getAttribute("class").trim();
+ String expected = "v-app " + theme;
+ expected = expected.trim();
+ return rootClass.equals(expected);
+ }
+ }, 30);
+ }
+}