Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit b3b1534

Browse files
author
Axel Schüssler
committed
serve test pages via HTTP, not file system
Serve integration test pages via Jetty instead of reading them from the file system. The network abstraction makes the tests OS-independent and will allow us to run the tests against selenium docker containers instead of local browser installations.
1 parent b5bba5d commit b3b1534

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
<version.mockito>1.10.19</version.mockito>
6868
<version.checkstyle>6.9</version.checkstyle>
6969

70+
<version.jetty-server>9.4.0.M0</version.jetty-server>
71+
7072
<version.selenium>2.53.0</version.selenium>
7173

7274
<version.slf4j>1.7.12</version.slf4j>
@@ -238,6 +240,12 @@
238240
<version>${version.checkstyle}</version>
239241
</dependency>
240242

243+
<dependency>
244+
<groupId>org.eclipse.jetty</groupId>
245+
<artifactId>jetty-server</artifactId>
246+
<version>${version.jetty-server}</version>
247+
</dependency>
248+
241249
</dependencies>
242250
</dependencyManagement>
243251

webtester-core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
<artifactId>selenium-firefox-driver</artifactId>
6161
<scope>test</scope>
6262
</dependency>
63+
<dependency>
64+
<groupId>org.eclipse.jetty</groupId>
65+
<artifactId>jetty-server</artifactId>
66+
<scope>test</scope>
67+
</dependency>
6368

6469
</dependencies>
6570

webtester-core/src/test/java/integration/BaseIntegrationTest.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import java.io.File;
66

7+
import org.eclipse.jetty.server.Server;
8+
import org.eclipse.jetty.server.handler.ResourceHandler;
9+
import org.junit.AfterClass;
710
import org.junit.Before;
811
import org.junit.BeforeClass;
912

@@ -21,15 +24,37 @@
2124
@NoArgsConstructor(access = AccessLevel.PROTECTED)
2225
public class BaseIntegrationTest {
2326

27+
private static final String TEST_PAGE_SERVER_HOST = System.getProperty("testPageServerHost", "localhost");
28+
29+
private static final int TEST_PAGE_SERVER_PORT = Integer.parseInt(System.getProperty("testPageServerPort", "8080"));
30+
31+
private static final String TEST_PAGE_SERVER_BASE_ADDRESS = String.format("http://%s:%d/", TEST_PAGE_SERVER_HOST, TEST_PAGE_SERVER_PORT);
32+
33+
private static Server server;
34+
2435
private static Browser browser;
2536

2637
@BeforeClass
27-
public static void setUpBeforeClass() {
38+
public static void setupBrowser() {
2839
if (browser == null) {
2940
browser = new TestBrowserFactory().createBrowser();
3041
}
3142
}
3243

44+
@BeforeClass
45+
public static void startTestPageServer() throws Exception {
46+
server = new Server(TEST_PAGE_SERVER_PORT);
47+
ResourceHandler resourceHandler = new ResourceHandler();
48+
resourceHandler.setResourceBase(getTestResourceFolder().getCanonicalPath());
49+
server.setHandler(resourceHandler);
50+
server.start();
51+
}
52+
53+
@AfterClass
54+
public static void stopTestPageServer() throws Exception {
55+
server.stop();
56+
}
57+
3358
@Before
3459
public final void navigateToTestURL() {
3560
String htmlFilePath = getHTMLFilePath();
@@ -79,18 +104,13 @@ protected EventSystem eventSystem(){
79104
}
80105

81106
protected static String getUrlFor(String fileName) {
107+
assertThatFileResourceExists(fileName);
108+
return TEST_PAGE_SERVER_BASE_ADDRESS + fileName;
109+
}
82110

83-
File testResourceFolder = getTestResourceFolder();
84-
File testResourceFile = new File(testResourceFolder, fileName);
85-
111+
private static void assertThatFileResourceExists(String fileName) {
112+
File testResourceFile = new File(getTestResourceFolder(), fileName);
86113
assertThat(testResourceFile.isFile()).withFailMessage("file not found: " + testResourceFile).isTrue();
87-
88-
String systemDependentPath = testResourceFile.getAbsolutePath();
89-
String replacedBackslashes = systemDependentPath.replaceAll("\\\\", "/");
90-
String replacedWhitespaces = replacedBackslashes.replaceAll(" ", "%20");
91-
92-
return "file:///" + replacedWhitespaces;
93-
94114
}
95115

96116
private static File getTestResourceFolder() {

0 commit comments

Comments
 (0)