Skip to content

Commit

Permalink
Remove vaadin-uitest-common dependency from server tests (#8551)
Browse files Browse the repository at this point in the history
Uses custom reference and error files in test project.
  • Loading branch information
tsuoanttila authored and hesara committed Feb 15, 2017
1 parent 21544c9 commit a2d3155
Show file tree
Hide file tree
Showing 17 changed files with 350 additions and 402 deletions.
22 changes: 16 additions & 6 deletions test/servlet-containers/generic/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.vaadin</groupId> <groupId>com.vaadin</groupId>
Expand All @@ -13,6 +13,7 @@
<packaging>war</packaging> <packaging>war</packaging>
<properties> <properties>
<osgi.bundle.version>8.0.0</osgi.bundle.version> <osgi.bundle.version>8.0.0</osgi.bundle.version>
<jetty.skip>true</jetty.skip>
</properties> </properties>


<dependencies> <dependencies>
Expand Down Expand Up @@ -41,8 +42,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.vaadin</groupId> <groupId>com.vaadin</groupId>
<artifactId>vaadin-uitest-common</artifactId> <artifactId>vaadin-testbench-api</artifactId>
<version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
Expand All @@ -51,13 +51,15 @@
<build> <build>


<plugins> <plugins>
<!--TODO run this on different servers--> <!--TODO run this on different servers -->
<plugin> <plugin>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId> <artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version> <version>${jetty.version}</version>
<configuration> <configuration>
<skip>true</skip> <webApp>
<contextPath>/demo</contextPath>
</webApp>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
Expand All @@ -72,14 +74,22 @@
<skip>true</skip> <skip>true</skip>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<!-- Currently tested using an Ant script. -->
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin> <plugin>
<artifactId>maven-war-plugin</artifactId> <artifactId>maven-war-plugin</artifactId>
<configuration> <configuration>
<archive> <archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive> </archive>
</configuration> </configuration>
<!-- This execution builds an additional .war file with JBoss 6 specific descriptor --> <!-- This execution builds an additional .war file with JBoss
6 specific descriptor -->
<executions> <executions>
<execution> <execution>
<id>jboss6-war</id> <id>jboss6-war</id>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,37 +1,91 @@
/*
* Copyright 2000-2016 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.integration; package com.vaadin.tests.integration;


import com.vaadin.testbench.By; import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.imageio.ImageIO;

import org.junit.After;
import org.junit.runner.RunWith;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.vaadin.testbench.annotations.BrowserConfiguration;
import com.vaadin.testbench.annotations.BrowserFactory;
import com.vaadin.testbench.annotations.RunOnHub;
import com.vaadin.testbench.elements.UIElement; import com.vaadin.testbench.elements.UIElement;
import com.vaadin.testbench.parallel.Browser;
import com.vaadin.testbench.parallel.BrowserUtil;
import com.vaadin.testbench.parallel.ParallelRunner;
import com.vaadin.testbench.parallel.ParallelTest;
import com.vaadin.testbench.parallel.TestNameSuffix; import com.vaadin.testbench.parallel.TestNameSuffix;
import com.vaadin.tests.tb3.SingleBrowserTestPhantomJS2; import com.vaadin.testbench.screenshot.ImageFileUtil;


/** @RunOnHub("tb3-hub.intra.itmill.com")
* Base class for integration tests. Integration tests use the @RunWith(ParallelRunner.class)
* {@literal deployment.url} parameter to determine the base deployment url @BrowserFactory(CustomBrowserFactory.class)
* (http://hostname:123)
*
* @author Vaadin Ltd
*/
@TestNameSuffix(property = "server-name") @TestNameSuffix(property = "server-name")
public abstract class AbstractIntegrationTest public abstract class AbstractIntegrationTest extends ParallelTest {
extends SingleBrowserTestPhantomJS2 {
/**
* Height of the screenshots we want to capture
*/
private static final int SCREENSHOT_HEIGHT = 850;

/**
* Width of the screenshots we want to capture
*/
private static final int SCREENSHOT_WIDTH = 1500;

private boolean screenshotErrors;

@BrowserConfiguration
public final List<DesiredCapabilities> getBrowsersToTest() {
return getBrowsers().map(BrowserUtil.getBrowserFactory()::create)
.collect(Collectors.toList());
}

protected Stream<Browser> getBrowsers() {
return Stream.of(Browser.PHANTOMJS);
}

@Override @Override
protected String getBaseURL() { public void setup() throws Exception {
super.setup();

testBench().resizeViewPortTo(SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT);

openTestURL();
}

private void openTestURL() {
String url = getDeploymentURL() + getContextPath() + getTestPath() + "?"
+ getParameters().collect(Collectors.joining("&"));
driver.get(url);

if (!isElementPresent(UIElement.class)) {
waitUntil(e -> isElementPresent(UIElement.class), 10);
}
}

protected Stream<String> getParameters() {
return Stream.of("restartApplication");
}

/**
* Returns a path where the test UI is found.
*
* @return path for test
*/
protected abstract String getTestPath();

private String getDeploymentURL() {
String deploymentUrl = System.getProperty("deployment.url"); String deploymentUrl = System.getProperty("deployment.url");
if (deploymentUrl == null || deploymentUrl.equals("")) { if (deploymentUrl == null || deploymentUrl.equals("")) {
throw new RuntimeException( throw new RuntimeException(
Expand All @@ -40,17 +94,48 @@ protected String getBaseURL() {
return deploymentUrl; return deploymentUrl;
} }


@Override protected void compareScreen(String identifier) throws IOException {
protected void openTestURL() { String refFileName = identifier + "-"
super.openTestURL(); + getDesiredCapabilities().getBrowserName().toLowerCase()

+ ".png";
waitForApplication(); String errorFileName = identifier + "-"
+ getDesiredCapabilities().getBrowserName().toLowerCase() + "-"
+ System.getProperty("server-name") + ".png";
File referenceFile = ImageFileUtil
.getReferenceScreenshotFile(refFileName);
try {
BufferedImage reference = ImageIO.read(referenceFile);
if (testBench().compareScreen(reference, errorFileName)) {
return;
}
} catch (IOException e) {
Logger.getLogger(getClass().getName()).warning(
"Missing screenshot reference: " + referenceFile.getPath());
}
screenshotErrors = true;
} }


protected void waitForApplication() { @After
if (!isElementPresent(UIElement.class)) { public void teardown() {
// Wait for UI element. if (screenshotErrors) {
waitForElementPresent(By.vaadin("//com.vaadin.ui.UI")); throw new RuntimeException("Screenshots failed.");
} }
} }

/**
* Waits the given number of seconds for the given condition to become true.
* Use e.g. as
* {@link #waitUntil(ExpectedConditions.textToBePresentInElement(by, text))}
*
* @param condition
* the condition to wait for to become true
*/
protected <T> void waitUntil(ExpectedCondition<T> condition,
long timeoutInSeconds) {
new WebDriverWait(driver, timeoutInSeconds).until(condition);
}

protected String getContextPath() {
return "/demo";
}
} }
@@ -1,81 +1,21 @@
/*
* Copyright 2000-2016 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.integration; package com.vaadin.tests.integration;


import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;


import com.vaadin.testbench.elements.TableElement; import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.ParameterizedTB3Runner;


/**
* Base class for servlet integration tests. Automatically prepends "/demo" to
* the deployment path
*
* @author Vaadin Ltd
*/
@RunWith(ParameterizedTB3Runner.class)
public abstract class AbstractServletIntegrationTest public abstract class AbstractServletIntegrationTest
extends AbstractIntegrationTest { extends AbstractIntegrationTest {


private String contextPath = "/demo";

@Test @Test
public void runTest() throws IOException, AssertionError { public void runTest() throws Exception {
openTestURL();
// make sure no fading progress indicator from table update is lingering // make sure no fading progress indicator from table update is lingering
sleep(2000); Thread.sleep(2000);
compareScreen("initial"); compareScreen("initial");
$(TableElement.class).first().getCell(0, 1).click(); $(TableElement.class).first().getCell(0, 1).click();
// without this, table fetch might have a fading progress indicator // without this, table fetch might have a fading progress indicator
sleep(2000); Thread.sleep(2000);
compareScreen("finland"); compareScreen("finland");
} }


@Override
protected String getDeploymentPath(Class<?> uiClass) {
return contextPath + super.getDeploymentPath(uiClass);
}

public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}

@Parameters
public static Collection<String> getContextPaths() {
if (getServerName().equals("wildfly9-nginx")) {
ArrayList<String> paths = new ArrayList<>();
paths.add("/buffering/demo");
paths.add("/nonbuffering/demo");
paths.add("/buffering-timeout/demo");
paths.add("/nonbuffering-timeout/demo");
return paths;
} else {
return Collections.emptyList();
}
}

protected static String getServerName() {
return System.getProperty("server-name");
}

} }
@@ -0,0 +1,21 @@
package com.vaadin.tests.integration;

import org.openqa.selenium.remote.DesiredCapabilities;

import com.vaadin.testbench.parallel.Browser;
import com.vaadin.testbench.parallel.BrowserUtil;
import com.vaadin.testbench.parallel.DefaultBrowserFactory;

public class CustomBrowserFactory extends DefaultBrowserFactory {

@Override
public DesiredCapabilities create(Browser browser) {
DesiredCapabilities capabilities = super.create(browser);
if (BrowserUtil.isPhantomJS(capabilities)) {
capabilities.setVersion("2");
capabilities.setCapability("phantomjs.binary.path",
"/usr/bin/phantomjs2");
}
return capabilities;
}
}
Expand Up @@ -15,7 +15,12 @@
*/ */
package com.vaadin.tests.integration; package com.vaadin.tests.integration;


public class ServletIntegrationWebsocketUITest public class ServletIntegrationDefaultPushIT
extends AbstractServletIntegrationTest { extends AbstractServletIntegrationTest {
// Uses the test method declared in the super class // Uses the test method declared in the super class

@Override
protected String getTestPath() {
return "/run/ServletIntegrationDefaultPushUI";
}
} }
Expand Up @@ -15,6 +15,11 @@
*/ */
package com.vaadin.tests.integration; package com.vaadin.tests.integration;


public class ServletIntegrationUITest extends AbstractServletIntegrationTest { public class ServletIntegrationIT extends AbstractServletIntegrationTest {
// Uses the test method declared in the super class // Uses the test method declared in the super class

@Override
protected String getTestPath() {
return "/run/ServletIntegrationUI";
}
} }

0 comments on commit a2d3155

Please sign in to comment.