From 8d0c6ff3404fc6fb7703b67333955206970f44a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sauli=20T=C3=A4hk=C3=A4p=C3=A4=C3=A4?= Date: Fri, 13 Feb 2015 15:57:03 +0200 Subject: [PATCH] Add overload to openTestURL for giving UI class as a parameter. Change-Id: Ia964bb1bd185f5b78af1581c58f3f9247fad281c --- .../UIProviderInitParameterTest.java | 15 ++++--- .../BeanItemContainerLongEventTest.java | 5 +++ .../components/grid/GridClientRenderers.java | 4 +- .../com/vaadin/tests/tb3/AbstractTB3Test.java | 40 ++++++++++++------- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameterTest.java b/uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameterTest.java index 8197bbe8b8..7f9a375440 100644 --- a/uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameterTest.java +++ b/uitest/src/com/vaadin/tests/applicationservlet/UIProviderInitParameterTest.java @@ -27,6 +27,16 @@ import com.vaadin.tests.tb3.MultiBrowserTest; public class UIProviderInitParameterTest extends MultiBrowserTest { + @Override + protected void openTestURL(String... parameters) { + driver.get(getTestUrl()); + } + + @Override + protected String getDeploymentPath() { + return "/uiprovider"; + } + @Test public void testDefault() { // Test that UI parameter is used by default @@ -50,9 +60,4 @@ public class UIProviderInitParameterTest extends MultiBrowserTest { assertEquals("unexpected text found", message, label.getText()); } - @Override - protected String getDeploymentPath() { - return "/uiprovider"; - } - } diff --git a/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerLongEventTest.java b/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerLongEventTest.java index 0ec196f266..740d451b0f 100644 --- a/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerLongEventTest.java +++ b/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerLongEventTest.java @@ -32,6 +32,11 @@ public class BeanItemContainerLongEventTest extends MultiBrowserTest { return "/run/BeanItemContainerTestUI?restartApplication"; } + @Override + protected void openTestURL(String... parameters) { + driver.get(getTestUrl()); + } + @Test public void testEventDisplayedInWeekView() { openTestURL(); diff --git a/uitest/src/com/vaadin/tests/components/grid/GridClientRenderers.java b/uitest/src/com/vaadin/tests/components/grid/GridClientRenderers.java index 00db02bef3..953e2a24c7 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridClientRenderers.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridClientRenderers.java @@ -57,8 +57,8 @@ public class GridClientRenderers extends MultiBrowserTest { } @Override - protected String getDeploymentPath() { - String path = super.getDeploymentPath(); + protected String getDeploymentPath(Class uiClass) { + String path = super.getDeploymentPath(uiClass); if (latency > 0) { path += (path.contains("?") ? "&" : "?") + "latency=" + latency; } diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index cd89579c31..3cec3a7bd5 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.NoSuchElementException; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.impl.client.DefaultHttpClient; @@ -60,6 +61,7 @@ import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; +import com.google.gwt.thirdparty.guava.common.base.Joiner; import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium; import com.vaadin.server.LegacyApplication; import com.vaadin.server.UIProvider; @@ -320,8 +322,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * debug window and/or push (depending on {@link #isDebug()} and * {@link #isPush()}. */ - protected void openTestURL() { - openTestURL(""); + protected void openTestURL(String... parameters) { + openTestURL(getUIClass(), parameters); } /** @@ -329,13 +331,13 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * 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; + protected void openTestURL(Class uiClass, String... parameters) { + String url = getTestURL(uiClass); + + if(parameters.length > 0) { + url += "?" + Joiner.on("&").join(parameters); } + driver.get(url); } @@ -345,12 +347,16 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * @return the full URL for the test */ protected String getTestUrl() { - String baseUrl = getBaseURL(); - if (baseUrl.endsWith("/")) { - baseUrl = baseUrl.substring(0, baseUrl.length() - 1); - } + return StringUtils.strip(getBaseURL(), "/") + getDeploymentPath(); + } - return baseUrl + getDeploymentPath(); + /** + * Returns the full URL to be used for the test for the provided UI class. + * + * @return the full URL for the test + */ + protected String getTestURL(Class uiClass) { + return StringUtils.strip(getBaseURL(), "/") + getDeploymentPath(uiClass); } /** @@ -434,7 +440,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { public void tearDown() throws Exception { if (driver != null) { try { - openTestURL("&closeApplication"); + closeApplication(); } catch (Exception e) { e.printStackTrace(); } @@ -443,6 +449,10 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { driver = null; } + protected void closeApplication() { + openTestURL("closeApplication"); + } + /** * Finds an element based on the part of a TB2 style locator following the * :: (e.g. vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] -> @@ -833,7 +843,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * true if /run-push should be used instead of /run * @return The path to the given UI class */ - private String getDeploymentPath(Class uiClass) { + protected String getDeploymentPath(Class uiClass) { String runPath = "/run"; if (isPush()) { runPath = "/run-push"; -- 2.39.5