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;
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;
* debug window and/or push (depending on {@link #isDebug()} and
* {@link #isPush()}.
*/
- protected void openTestURL() {
- openTestURL("");
+ protected void openTestURL(String... parameters) {
+ openTestURL(getUIClass(), parameters);
}
/**
* 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);
}
* @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);
}
/**
public void tearDown() throws Exception {
if (driver != null) {
try {
- openTestURL("&closeApplication");
+ closeApplication();
} catch (Exception e) {
e.printStackTrace();
}
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] ->
* 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";