Skip to content

Commit cdeda0b

Browse files
henning-rooserik-edling
authored andcommitted
Create EI Frontend Test Framework (#36)
* Create EI Frontend Test Framework * Create EI Frontend Test Framework with Selenium test framework (using Firefox driver). * This test framework will be used for EI Frontend Functional Tests. * Support for Travis-CI * Sample test case
1 parent 08a718f commit cdeda0b

File tree

14 files changed

+547
-119
lines changed

14 files changed

+547
-119
lines changed

pom.xml

Lines changed: 158 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,165 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?><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">
2-
<modelVersion>4.0.0</modelVersion>
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
35

4-
<groupId>com.github.ericsson</groupId>
5-
<artifactId>eiffel-intelligence-frontend</artifactId>
6-
<version>0.0.8</version>
7-
<packaging>war</packaging>
6+
<groupId>com.github.ericsson</groupId>
7+
<artifactId>eiffel-intelligence-frontend</artifactId>
8+
<version>0.0.8</version>
9+
<packaging>war</packaging>
810

9-
<parent>
10-
<groupId>org.springframework.boot</groupId>
11-
<artifactId>spring-boot-starter-parent</artifactId>
12-
<version>2.0.1.RELEASE</version>
13-
<relativePath/> <!-- .. lookup parent from repository -->
14-
</parent>
1511

16-
<properties>
17-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
19-
<java.version>1.8</java.version>
20-
</properties>
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>2.0.1.RELEASE</version>
16+
<relativePath /> <!-- .. lookup parent from repository -->
17+
</parent>
2118

19+
<properties>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
22+
<java.version>1.8</java.version>
23+
<output-relative-path>src/main/java</output-relative-path>
24+
</properties>
2225

23-
<dependencies>
24-
<dependency>
25-
<groupId>org.springframework.boot</groupId>
26-
<artifactId>spring-boot-starter-actuator</artifactId>
27-
</dependency>
28-
<dependency>
29-
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-web</artifactId>
31-
<exclusions>
32-
<exclusion>
33-
<groupId>org.springframework.boot</groupId>
34-
<artifactId>spring-boot-starter-tomcat</artifactId>
35-
</exclusion>
36-
</exclusions>
37-
</dependency>
38-
<dependency>
39-
<groupId>org.springframework.boot</groupId>
40-
<artifactId>spring-boot-starter-thymeleaf</artifactId>
41-
</dependency>
42-
<dependency>
43-
<groupId>org.springframework.boot</groupId>
44-
<artifactId>spring-boot-devtools</artifactId>
45-
<optional>true</optional>
46-
</dependency>
47-
<dependency>
48-
<groupId>org.apache.httpcomponents</groupId>
49-
<artifactId>httpclient</artifactId>
50-
<version>4.5.3</version>
51-
</dependency>
52-
<dependency>
53-
<groupId>org.springframework.boot</groupId>
54-
<artifactId>spring-boot-starter-tomcat</artifactId>
55-
<scope>compile</scope>
56-
</dependency>
57-
<dependency>
58-
<groupId>org.springframework.boot</groupId>
59-
<artifactId>spring-boot-starter-test</artifactId>
60-
<scope>test</scope>
61-
</dependency>
62-
<dependency>
63-
<groupId>org.projectlombok</groupId>
64-
<artifactId>lombok</artifactId>
65-
<version>1.16.20</version>
66-
<scope>provided</scope>
67-
</dependency>
68-
<dependency>
69-
<groupId>com.google.code.gson</groupId>
70-
<artifactId>gson</artifactId>
71-
</dependency>
72-
<!-- https://mvnrepository.com/artifact/junit/junit -->
73-
<dependency>
74-
<groupId>junit</groupId>
75-
<artifactId>junit</artifactId>
76-
<version>4.12</version>
77-
</dependency>
78-
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
79-
<dependency>
80-
<groupId>org.mockito</groupId>
81-
<artifactId>mockito-all</artifactId>
82-
<version>1.10.19</version>
83-
</dependency>
84-
<!-- https://mvnrepository.com/artifact/org.mock-server/mockserver-netty -->
85-
<dependency>
86-
<groupId>org.mock-server</groupId>
87-
<artifactId>mockserver-netty</artifactId>
88-
<version>5.3.0</version>
89-
<scope>test</scope>
90-
</dependency>
91-
<!-- https://mvnrepository.com/artifact/org.mock-server/mockserver-client-java -->
92-
<dependency>
93-
<groupId>org.mock-server</groupId>
94-
<artifactId>mockserver-client-java</artifactId>
95-
<version>5.3.0</version>
96-
</dependency>
97-
</dependencies>
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-actuator</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-web</artifactId>
34+
<exclusions>
35+
<exclusion>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-tomcat</artifactId>
38+
</exclusion>
39+
</exclusions>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-devtools</artifactId>
48+
<optional>true</optional>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.apache.httpcomponents</groupId>
52+
<artifactId>httpclient</artifactId>
53+
<version>4.5.3</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-starter-tomcat</artifactId>
58+
<scope>compile</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-starter-test</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.projectlombok</groupId>
67+
<artifactId>lombok</artifactId>
68+
<version>1.16.20</version>
69+
<scope>provided</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.google.code.gson</groupId>
73+
<artifactId>gson</artifactId>
74+
<version>2.8.4</version>
75+
</dependency>
76+
<!-- https://mvnrepository.com/artifact/junit/junit -->
77+
<dependency>
78+
<groupId>junit</groupId>
79+
<artifactId>junit</artifactId>
80+
<version>4.12</version>
81+
</dependency>
82+
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
83+
<dependency>
84+
<groupId>org.mockito</groupId>
85+
<artifactId>mockito-all</artifactId>
86+
<version>1.10.19</version>
87+
</dependency>
88+
<!-- https://mvnrepository.com/artifact/org.mock-server/mockserver-client-java -->
89+
<dependency>
90+
<groupId>org.seleniumhq.selenium</groupId>
91+
<artifactId>selenium-firefox-driver</artifactId>
92+
<version>3.12.0</version>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.seleniumhq.selenium</groupId>
96+
<artifactId>selenium-server</artifactId>
97+
<version>3.12.0</version>
98+
</dependency>
99+
<!-- https://mvnrepository.com/artifact/org.mock-server/mockserver-client-java -->
100+
<dependency>
101+
<groupId>org.mock-server</groupId>
102+
<artifactId>mockserver-client-java</artifactId>
103+
<version>5.3.0</version>
104+
</dependency>
105+
<!-- https://mvnrepository.com/artifact/org.mock-server/mockserver-netty -->
106+
<dependency>
107+
<groupId>org.mock-server</groupId>
108+
<artifactId>mockserver-netty</artifactId>
109+
<version>5.3.0</version>
110+
<scope>test</scope>
111+
</dependency>
112+
</dependencies>
98113

99-
<build>
100-
<plugins>
101-
<plugin>
102-
<groupId>org.springframework.boot</groupId>
103-
<artifactId>spring-boot-maven-plugin</artifactId>
104-
</plugin>
105-
<plugin>
106-
<groupId>org.apache.maven.plugins</groupId>
107-
<artifactId>maven-war-plugin</artifactId>
108-
<configuration>
109-
<failOnMissingWebXml>false</failOnMissingWebXml>
110-
</configuration>
111-
</plugin>
112-
</plugins>
113-
</build>
114+
<build>
115+
<plugins>
116+
<plugin>
117+
<groupId>org.springframework.boot</groupId>
118+
<artifactId>spring-boot-maven-plugin</artifactId>
119+
</plugin>
120+
<plugin>
121+
<groupId>org.apache.maven.plugins</groupId>
122+
<artifactId>maven-war-plugin</artifactId>
123+
<configuration>
124+
<failOnMissingWebXml>false</failOnMissingWebXml>
125+
</configuration>
126+
</plugin>
127+
128+
<plugin>
129+
<groupId>org.codehaus.mojo</groupId>
130+
<artifactId>build-helper-maven-plugin</artifactId>
131+
<executions>
132+
<execution>
133+
<id>add-test-source</id>
134+
<phase>process-resources</phase>
135+
<goals>
136+
<goal>add-test-source</goal>
137+
</goals>
138+
<configuration>
139+
<sources>
140+
<source>src/functionaltest/java</source>
141+
<source>src/functionaltest/resources</source>
142+
</sources>
143+
</configuration>
144+
</execution>
145+
</executions>
146+
</plugin>
147+
148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-surefire-plugin</artifactId>
151+
<version>2.20</version>
152+
<configuration>
153+
<forkCount>2C</forkCount>
154+
<reuseForks>false</reuseForks>
155+
<excludes>
156+
<exclude>${someModule.test.excludes}</exclude>
157+
</excludes>
158+
<includes>
159+
<include>${someModule.test.includes}</include>
160+
</includes>
161+
</configuration>
162+
</plugin>
163+
</plugins>
164+
</build>
114165
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.ericsson.ei.config;
2+
3+
import com.ericsson.ei.frontend.exception.OSNotSupportedException;
4+
5+
import java.util.concurrent.TimeUnit;
6+
7+
import org.apache.commons.lang3.SystemUtils;
8+
import org.openqa.selenium.firefox.FirefoxDriver;
9+
import org.openqa.selenium.firefox.FirefoxOptions;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
13+
public class SeleniumConfig {
14+
15+
private static final Logger log = LoggerFactory.getLogger(SeleniumConfig.class);
16+
17+
public static FirefoxDriver getFirefoxDriver() throws OSNotSupportedException {
18+
FirefoxDriver driver;
19+
if (SystemUtils.IS_OS_LINUX) {
20+
System.setProperty("webdriver.gecko.driver", "src/functionaltest/resources/geckodriver");
21+
} else if (SystemUtils.IS_OS_WINDOWS) {
22+
System.setProperty("webdriver.gecko.driver", "src/functionaltest/resources/geckodriver.exe");
23+
} else {
24+
log.error("OS currently not supported.");
25+
throw new OSNotSupportedException();
26+
}
27+
FirefoxOptions firefoxOptions = new FirefoxOptions().setHeadless(true);
28+
29+
driver = new FirefoxDriver(firefoxOptions);
30+
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
31+
return driver;
32+
}
33+
34+
public static String getBaseUrl(int randomServerPort) {
35+
String baseUrl = "http://localhost:" + randomServerPort;
36+
return baseUrl;
37+
}
38+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.ericsson.ei.frontend;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import java.io.IOException;
6+
import java.nio.charset.StandardCharsets;
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
9+
10+
import com.ericsson.ei.config.SeleniumConfig;
11+
12+
import org.apache.http.impl.client.CloseableHttpClient;
13+
import org.junit.After;
14+
import org.junit.Before;
15+
import org.junit.Ignore;
16+
import org.junit.runner.RunWith;
17+
import org.mockito.InjectMocks;
18+
import org.mockito.MockitoAnnotations;
19+
import org.openqa.selenium.WebDriver;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.boot.test.context.SpringBootTest;
22+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
23+
import org.springframework.boot.test.mock.mockito.MockBean;
24+
import org.springframework.boot.web.server.LocalServerPort;
25+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
26+
@Ignore
27+
@RunWith(SpringJUnit4ClassRunner.class)
28+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
29+
public class SeleniumBaseClass {
30+
31+
@MockBean
32+
protected CloseableHttpClient mockedHttpClient;
33+
34+
@LocalServerPort
35+
private int randomServerPort;
36+
37+
@Autowired
38+
@InjectMocks
39+
EIRequestsController eIRequestsController;
40+
41+
@Autowired
42+
WebController webController;
43+
44+
protected WebDriver driver;
45+
protected String baseUrl;
46+
47+
private StringBuffer verificationErrors = new StringBuffer();
48+
49+
@Before
50+
public void setUp() throws Exception {
51+
MockitoAnnotations.initMocks(this);
52+
webController.setFrontendServicePort(randomServerPort);
53+
driver = SeleniumConfig.getFirefoxDriver();
54+
baseUrl = SeleniumConfig.getBaseUrl(randomServerPort);
55+
}
56+
57+
@After
58+
public void tearDown() throws Exception {
59+
driver.quit();
60+
String verificationErrorString = verificationErrors.toString();
61+
if (!verificationErrorString.equals("")) {
62+
fail(verificationErrorString);
63+
}
64+
}
65+
66+
protected String getResponseObjectFromFile(String filepath) throws IOException {
67+
return new String(Files.readAllBytes(Paths.get(filepath)), StandardCharsets.UTF_8);
68+
}
69+
}

0 commit comments

Comments
 (0)