summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-09-01 13:08:07 +0300
committerArtur Signell <artur@vaadin.com>2015-09-02 16:54:47 +0300
commit1c45292021467d41ac8afecd0ece1f2d98a3962a (patch)
tree5780fece2208943ffff1fd59115c00b508b7c8f3 /uitest
parent50c3190131f0cf003401d78e8b374f6fe36a0984 (diff)
downloadvaadin-framework-1c45292021467d41ac8afecd0ece1f2d98a3962a.tar.gz
vaadin-framework-1c45292021467d41ac8afecd0ece1f2d98a3962a.zip
Reconnect dialog theme and functionality tests (#11733)
Change-Id: Ie4a940ba2488f0a7739492a1d3967957cdd41099
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/application/ReconnectDialogUI.java46
-rw-r--r--uitest/src/com/vaadin/tests/application/ReconnectDialogUITest.java82
-rw-r--r--uitest/src/com/vaadin/tests/application/ReconnectDialogUIThemeTest.java140
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridDetailsLocationTest.java5
-rw-r--r--uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java13
-rw-r--r--uitest/src/com/vaadin/tests/tb3/CustomTestBenchCommandExecutor.java2
-rw-r--r--uitest/src/com/vaadin/tests/tb3/MultiBrowserThemeTestWithProxy.java51
7 files changed, 331 insertions, 8 deletions
diff --git a/uitest/src/com/vaadin/tests/application/ReconnectDialogUI.java b/uitest/src/com/vaadin/tests/application/ReconnectDialogUI.java
new file mode 100644
index 0000000000..62de2d49c5
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/application/ReconnectDialogUI.java
@@ -0,0 +1,46 @@
+/*
+ * 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.application;
+
+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.Button.ClickListener;
+
+public class ReconnectDialogUI extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ if (request.getParameter("reconnectAttempts") != null) {
+ getReconnectDialogConfiguration()
+ .setReconnectAttempts(
+ Integer.parseInt(request
+ .getParameter("reconnectAttempts")));
+ }
+ Button b = new Button("Say hello");
+ b.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log("Hello from the server");
+ }
+ });
+
+ addComponent(b);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/application/ReconnectDialogUITest.java b/uitest/src/com/vaadin/tests/application/ReconnectDialogUITest.java
new file mode 100644
index 0000000000..41f558091c
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/application/ReconnectDialogUITest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.application;
+
+import org.junit.Assert;
+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.jcraft.jsch.JSchException;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.MultiBrowserTestWithProxy;
+
+public class ReconnectDialogUITest extends MultiBrowserTestWithProxy {
+
+ @Test
+ public void reconnectDialogShownAndDisappears() throws JSchException {
+ openTestURL();
+ getButton().click();
+ Assert.assertEquals("1. Hello from the server", getLogRow(0));
+ disconnectProxy();
+ getButton().click();
+ waitForReconnectDialogWithText("Server connection lost, trying to reconnect...");
+ connectProxy();
+ waitForReconnectDialogToDisappear();
+ Assert.assertEquals("2. Hello from the server", getLogRow(0));
+ }
+
+ @Test
+ public void gaveUpMessageShown() {
+ openTestURL("reconnectAttempts=3");
+ getButton().click();
+ Assert.assertEquals("1. Hello from the server", getLogRow(0));
+
+ disconnectProxy();
+ getButton().click();
+
+ waitForReconnectDialogWithText("Server connection lost.");
+ }
+
+ private void waitForReconnectDialogWithText(final String text) {
+ waitForReconnectDialogPresent();
+ final WebElement reconnectDialog = findElement(ReconnectDialogUIThemeTest.reconnectDialogBy);
+ waitUntil(new ExpectedCondition<Boolean>() {
+ @Override
+ public Boolean apply(WebDriver input) {
+ return reconnectDialog.findElement(By.className("text"))
+ .getText().equals(text);
+ }
+ }, 10);
+
+ }
+
+ private void waitForReconnectDialogToDisappear() {
+ waitForElementNotPresent(ReconnectDialogUIThemeTest.reconnectDialogBy);
+
+ }
+
+ private void waitForReconnectDialogPresent() {
+ waitForElementPresent(ReconnectDialogUIThemeTest.reconnectDialogBy);
+ }
+
+ private WebElement getButton() {
+ return $(ButtonElement.class).first();
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/application/ReconnectDialogUIThemeTest.java b/uitest/src/com/vaadin/tests/application/ReconnectDialogUIThemeTest.java
new file mode 100644
index 0000000000..ac3c664d1d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/application/ReconnectDialogUIThemeTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.application;
+
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.OutputType;
+import org.openqa.selenium.TakesScreenshot;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.parallel.BrowserUtil;
+import com.vaadin.tests.tb3.CustomTestBenchCommandExecutor;
+import com.vaadin.tests.tb3.MultiBrowserThemeTestWithProxy;
+
+public abstract class ReconnectDialogUIThemeTest extends
+ MultiBrowserThemeTestWithProxy {
+
+ public static class ValoReconnectDialogTest extends
+ ReconnectDialogUIThemeTest {
+ @Override
+ protected String getTheme() {
+ return "valo";
+ }
+ }
+
+ public static class ReindeerReconnectDialogTest extends
+ ReconnectDialogUIThemeTest {
+ @Override
+ protected String getTheme() {
+ return "reindeer";
+ }
+ }
+
+ public static class RunoReconnectDialogTest extends
+ ReconnectDialogUIThemeTest {
+ @Override
+ protected String getTheme() {
+ return "runo";
+ }
+ }
+
+ public static class ChameleonReconnectDialogTest extends
+ ReconnectDialogUIThemeTest {
+ @Override
+ protected String getTheme() {
+ return "chameleon";
+ }
+ }
+
+ public static class BaseReconnectDialogTest extends
+ ReconnectDialogUIThemeTest {
+ @Override
+ protected String getTheme() {
+ return "base";
+ }
+ }
+
+ static By reconnectDialogBy = By.className("v-reconnect-dialog");
+
+ @Test
+ public void reconnectDialogTheme() throws IOException {
+ openTestURL();
+ ButtonElement helloButton = $(ButtonElement.class).caption("Say hello")
+ .first();
+ helloButton.click();
+ Assert.assertEquals("1. Hello from the server", getLogRow(0));
+ disconnectProxy();
+ helloButton.click();
+ testBench().disableWaitForVaadin();
+ waitUntil(new ExpectedCondition<Boolean>() {
+
+ @Override
+ public Boolean apply(WebDriver input) {
+ boolean present = isElementPresent(reconnectDialogBy);
+ return present;
+ }
+ });
+
+ WebElement dialog = findElement(reconnectDialogBy);
+ WebElement spinner = dialog.findElement(By.className("spinner"));
+
+ // Hide spinner to make screenshot stable
+ executeScript("arguments[0].style.visibility='hidden';", spinner);
+ compareScreen("onscreen-without-spinner");
+
+ // Show spinner and make sure it is shown by comparing to the screenshot
+ // without a spinner
+ executeScript("arguments[0].style.visibility='visible';", spinner);
+ BufferedImage fullScreen = ImageIO.read(new ByteArrayInputStream(
+ ((TakesScreenshot) getDriver())
+ .getScreenshotAs(OutputType.BYTES)));
+ BufferedImage spinnerImage = CustomTestBenchCommandExecutor
+ .cropToElement(spinner, fullScreen,
+ BrowserUtil.isIE8(getDesiredCapabilities()));
+ assertHasManyColors("Spinner is not shown", spinnerImage);
+
+ }
+
+ private void assertHasManyColors(String message, BufferedImage spinnerImage) {
+ int backgroundColor = spinnerImage.getRGB(0, 0);
+ for (int x = 0; x < spinnerImage.getWidth(); x++) {
+ for (int y = 0; y < spinnerImage.getHeight(); y++) {
+ if (Math.abs(spinnerImage.getRGB(x, y) - backgroundColor) > 50) {
+ return;
+ }
+ }
+ }
+ Assert.fail(message);
+
+ }
+
+ @Override
+ protected Class<?> getUIClass() {
+ return ReconnectDialogUI.class;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsLocationTest.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsLocationTest.java
index f20cc0f6f4..33f66d35be 100644
--- a/uitest/src/com/vaadin/tests/components/grid/GridDetailsLocationTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsLocationTest.java
@@ -23,7 +23,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
-import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
@@ -313,10 +312,6 @@ public class GridDetailsLocationTest extends MultiBrowserTest {
checkBoxElement.click(5, 5);
}
- private Object executeScript(String string, Object... param) {
- return ((JavascriptExecutor) getDriver()).executeScript(string, param);
- }
-
private void scrollAndToggle(int row) {
setRow(row);
getScrollAndToggle().click();
diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
index 842fcbb859..385a4477e1 100644
--- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
+++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
@@ -368,8 +368,8 @@ public abstract class AbstractTB3Test extends ParallelTest {
* {@link org.openqa.selenium.JavascriptExecutor#executeScript(String, Object...)}
* returns
*/
- protected Object executeScript(String script) {
- return ((JavascriptExecutor) getDriver()).executeScript(script);
+ protected Object executeScript(String script, Object... args) {
+ return ((JavascriptExecutor) getDriver()).executeScript(script, args);
}
/**
@@ -464,6 +464,15 @@ public abstract class AbstractTB3Test extends ParallelTest {
waitUntil(ExpectedConditions.presenceOfElementLocated(by));
}
+ protected void waitForElementNotPresent(final By by) {
+ waitUntil(new ExpectedCondition<Boolean>() {
+ @Override
+ public Boolean apply(WebDriver input) {
+ return input.findElements(by).isEmpty();
+ }
+ });
+ }
+
protected void waitForElementVisible(final By by) {
waitUntil(ExpectedConditions.visibilityOfElementLocated(by));
}
diff --git a/uitest/src/com/vaadin/tests/tb3/CustomTestBenchCommandExecutor.java b/uitest/src/com/vaadin/tests/tb3/CustomTestBenchCommandExecutor.java
index a70eeeeb49..00d7788f8b 100644
--- a/uitest/src/com/vaadin/tests/tb3/CustomTestBenchCommandExecutor.java
+++ b/uitest/src/com/vaadin/tests/tb3/CustomTestBenchCommandExecutor.java
@@ -118,7 +118,7 @@ public class CustomTestBenchCommandExecutor {
* @return
* @throws IOException
*/
- private BufferedImage cropToElement(WebElement element,
+ public static BufferedImage cropToElement(WebElement element,
BufferedImage fullScreen, boolean isIE8) throws IOException {
Point loc = element.getLocation();
Dimension size = element.getSize();
diff --git a/uitest/src/com/vaadin/tests/tb3/MultiBrowserThemeTestWithProxy.java b/uitest/src/com/vaadin/tests/tb3/MultiBrowserThemeTestWithProxy.java
new file mode 100644
index 0000000000..142aa0ccc6
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/tb3/MultiBrowserThemeTestWithProxy.java
@@ -0,0 +1,51 @@
+/*
+ * 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.tb3;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+/**
+ * Test which uses theme returned by {@link #getTheme()} for running the test
+ */
+public abstract class MultiBrowserThemeTestWithProxy extends
+ MultiBrowserTestWithProxy {
+
+ protected abstract String getTheme();
+
+ @Override
+ protected boolean requireWindowFocusForIE() {
+ return true;
+ }
+
+ @Override
+ protected void openTestURL(Class<?> uiClass, String... parameters) {
+ Set<String> params = new HashSet<String>(Arrays.asList(parameters));
+ params.add("theme=" + getTheme());
+ super.openTestURL(uiClass, params.toArray(new String[params.size()]));
+ }
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ List<DesiredCapabilities> browsersToTest = getBrowsersExcludingPhantomJS();
+ browsersToTest.add(PHANTOMJS2());
+ return browsersToTest;
+ }
+}