Skip to content

Commit e5352e8

Browse files
authored
test: bootstrapped integration e2e tests (#117)
1 parent d9b6bb8 commit e5352e8

File tree

5 files changed

+233
-0
lines changed

5 files changed

+233
-0
lines changed

pom.xml

+28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<version.jkube>1.16.2</version.jkube>
1515
<version.assertj>3.26.0</version.assertj>
1616
<version.exec-maven-plugin>3.2.0</version.exec-maven-plugin>
17+
<version.failsafe-maven-plugin>3.3.0</version.failsafe-maven-plugin>
18+
<version.selenium>4.22.0</version.selenium>
1719
<version.surefire-maven-plugin>3.3.0</version.surefire-maven-plugin>
1820
<container.image.tag>0.0.0-SNAPSHOT</container.image.tag>
1921
<jkube.enricher.jkube-service.type>NodePort</jkube.enricher.jkube-service.type>
@@ -98,6 +100,12 @@
98100
<version>${version.assertj}</version>
99101
<scope>test</scope>
100102
</dependency>
103+
<dependency>
104+
<groupId>org.seleniumhq.selenium</groupId>
105+
<artifactId>selenium-java</artifactId>
106+
<version>${version.selenium}</version>
107+
<scope>test</scope>
108+
</dependency>
101109
</dependencies>
102110
<build>
103111
<resources>
@@ -120,6 +128,15 @@
120128
</systemPropertyVariables>
121129
</configuration>
122130
</plugin>
131+
<plugin>
132+
<artifactId>maven-failsafe-plugin</artifactId>
133+
<version>${version.failsafe-maven-plugin}</version>
134+
<configuration>
135+
<systemPropertyVariables>
136+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
137+
</systemPropertyVariables>
138+
</configuration>
139+
</plugin>
123140
</plugins>
124141
</pluginManagement>
125142
<plugins>
@@ -135,6 +152,17 @@
135152
</execution>
136153
</executions>
137154
</plugin>
155+
<plugin>
156+
<artifactId>maven-failsafe-plugin</artifactId>
157+
<executions>
158+
<execution>
159+
<goals>
160+
<goal>integration-test</goal>
161+
<goal>verify</goal>
162+
</goals>
163+
</execution>
164+
</executions>
165+
</plugin>
138166
</plugins>
139167
</build>
140168
<profiles>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2024 Marc Nuri
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Created on 2024-06-26, 17:20
17+
*/
18+
package com.marcnuri.yakd.selenium;
19+
20+
import io.quarkus.test.common.http.TestHTTPResource;
21+
import io.quarkus.test.junit.QuarkusTest;
22+
import io.quarkus.test.junit.TestProfile;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
import org.openqa.selenium.By;
26+
import org.openqa.selenium.WebDriver;
27+
import org.openqa.selenium.support.ui.Wait;
28+
import org.openqa.selenium.support.ui.WebDriverWait;
29+
30+
import java.net.URL;
31+
import java.time.Duration;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
35+
@QuarkusTest
36+
@TestProfile(IntegrationTestProfile.class)
37+
public class HomeIT {
38+
39+
@TestHTTPResource
40+
URL url;
41+
WebDriver driver;
42+
43+
@BeforeEach
44+
void loadHomePage() {
45+
driver.get(url.toString());
46+
final Wait<WebDriver> wait = new WebDriverWait(driver, Duration.ofSeconds(1));
47+
wait.until(d -> d.findElement(By.cssSelector(".dashboard-page")).isDisplayed());
48+
}
49+
50+
@Test
51+
void hasDocumentTitle() {
52+
assertThat(driver.getTitle())
53+
.isEqualTo("YAKD - Kubernetes Dashboard");
54+
}
55+
56+
@Test
57+
void hasFooter() {
58+
assertThat(driver.findElement(By.cssSelector(".dashboard-page footer")).getText())
59+
.matches("Copyright © \\d{4} - Marc Nuri - Licensed under the Apache License 2.0");
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2024 Marc Nuri
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Created on 2024-06-26, 17:30
17+
*/
18+
package com.marcnuri.yakd.selenium;
19+
20+
import io.quarkus.test.junit.QuarkusTestProfile;
21+
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
22+
23+
import java.util.Map;
24+
25+
@WithSelenium
26+
@WithKubernetesTestServer
27+
public class IntegrationTestProfile implements QuarkusTestProfile {
28+
29+
@Override
30+
public Map<String, String> getConfigOverrides() {
31+
return Map.of(
32+
"yakd.frontend.root", "/frontend",
33+
"quarkus.kubernetes-client.devservices.enabled", "false"
34+
);
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2024 Marc Nuri
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Created on 2024-06-26, 17:30
17+
*/
18+
package com.marcnuri.yakd.selenium;
19+
20+
import io.quarkus.test.common.QuarkusTestResourceConfigurableLifecycleManager;
21+
import org.openqa.selenium.WebDriver;
22+
import org.openqa.selenium.chrome.ChromeDriver;
23+
import org.openqa.selenium.chrome.ChromeDriverService;
24+
import org.openqa.selenium.chrome.ChromeOptions;
25+
26+
import java.io.IOException;
27+
import java.util.Collections;
28+
import java.util.Map;
29+
30+
public class SeleniumTestResource implements QuarkusTestResourceConfigurableLifecycleManager<WithSelenium> {
31+
32+
private boolean headless;
33+
private ChromeDriverService chromeDriverService;
34+
private ChromeDriver chromeDriver;
35+
36+
@Override
37+
public void init(WithSelenium annotation) {
38+
headless = annotation.headless();
39+
}
40+
41+
@Override
42+
public Map<String, String> start() {
43+
chromeDriverService = new ChromeDriverService.Builder()
44+
.usingAnyFreePort()
45+
.build();
46+
try {
47+
chromeDriverService.start();
48+
} catch (IOException exception) {
49+
throw new IllegalStateException("Unable to start ChromeDriverService", exception);
50+
}
51+
final ChromeOptions chromeOptions = new ChromeOptions();
52+
if (headless) {
53+
chromeOptions.addArguments("--headless=new");
54+
}
55+
chromeDriver = new ChromeDriver(chromeDriverService, chromeOptions);
56+
return Collections.emptyMap();
57+
}
58+
59+
@Override
60+
public void stop() {
61+
if (chromeDriver != null) {
62+
chromeDriver.close();
63+
}
64+
if (chromeDriverService != null) {
65+
chromeDriverService.stop();
66+
}
67+
}
68+
69+
@Override
70+
public void inject(TestInjector testInjector) {
71+
testInjector.injectIntoFields(chromeDriver, new TestInjector.MatchesType(WebDriver.class));
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2024 Marc Nuri
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Created on 2024-06-26, 17:30
17+
*/
18+
package com.marcnuri.yakd.selenium;
19+
20+
import io.quarkus.test.common.QuarkusTestResource;
21+
22+
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Retention;
24+
import java.lang.annotation.RetentionPolicy;
25+
import java.lang.annotation.Target;
26+
27+
@QuarkusTestResource(SeleniumTestResource.class)
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@Target(ElementType.TYPE)
30+
public @interface WithSelenium {
31+
32+
boolean headless() default true;
33+
34+
}

0 commit comments

Comments
 (0)