Skip to content

Commit

Permalink
test: bootstrapped integration e2e tests (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa authored Jun 26, 2024
1 parent d9b6bb8 commit e5352e8
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<version.jkube>1.16.2</version.jkube>
<version.assertj>3.26.0</version.assertj>
<version.exec-maven-plugin>3.2.0</version.exec-maven-plugin>
<version.failsafe-maven-plugin>3.3.0</version.failsafe-maven-plugin>
<version.selenium>4.22.0</version.selenium>
<version.surefire-maven-plugin>3.3.0</version.surefire-maven-plugin>
<container.image.tag>0.0.0-SNAPSHOT</container.image.tag>
<jkube.enricher.jkube-service.type>NodePort</jkube.enricher.jkube-service.type>
Expand Down Expand Up @@ -98,6 +100,12 @@
<version>${version.assertj}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${version.selenium}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
Expand All @@ -120,6 +128,15 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.failsafe-maven-plugin}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand All @@ -135,6 +152,17 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
61 changes: 61 additions & 0 deletions src/test/java/com/marcnuri/yakd/selenium/HomeIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2024 Marc Nuri
*
* 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.
*
* Created on 2024-06-26, 17:20
*/
package com.marcnuri.yakd.selenium;

import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.net.URL;
import java.time.Duration;

import static org.assertj.core.api.Assertions.assertThat;

@QuarkusTest
@TestProfile(IntegrationTestProfile.class)
public class HomeIT {

@TestHTTPResource
URL url;
WebDriver driver;

@BeforeEach
void loadHomePage() {
driver.get(url.toString());
final Wait<WebDriver> wait = new WebDriverWait(driver, Duration.ofSeconds(1));
wait.until(d -> d.findElement(By.cssSelector(".dashboard-page")).isDisplayed());
}

@Test
void hasDocumentTitle() {
assertThat(driver.getTitle())
.isEqualTo("YAKD - Kubernetes Dashboard");
}

@Test
void hasFooter() {
assertThat(driver.findElement(By.cssSelector(".dashboard-page footer")).getText())
.matches("Copyright © \\d{4} - Marc Nuri - Licensed under the Apache License 2.0");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2024 Marc Nuri
*
* 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.
*
* Created on 2024-06-26, 17:30
*/
package com.marcnuri.yakd.selenium;

import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;

import java.util.Map;

@WithSelenium
@WithKubernetesTestServer
public class IntegrationTestProfile implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"yakd.frontend.root", "/frontend",
"quarkus.kubernetes-client.devservices.enabled", "false"
);
}

}
73 changes: 73 additions & 0 deletions src/test/java/com/marcnuri/yakd/selenium/SeleniumTestResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2024 Marc Nuri
*
* 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.
*
* Created on 2024-06-26, 17:30
*/
package com.marcnuri.yakd.selenium;

import io.quarkus.test.common.QuarkusTestResourceConfigurableLifecycleManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

public class SeleniumTestResource implements QuarkusTestResourceConfigurableLifecycleManager<WithSelenium> {

private boolean headless;
private ChromeDriverService chromeDriverService;
private ChromeDriver chromeDriver;

@Override
public void init(WithSelenium annotation) {
headless = annotation.headless();
}

@Override
public Map<String, String> start() {
chromeDriverService = new ChromeDriverService.Builder()
.usingAnyFreePort()
.build();
try {
chromeDriverService.start();
} catch (IOException exception) {
throw new IllegalStateException("Unable to start ChromeDriverService", exception);
}
final ChromeOptions chromeOptions = new ChromeOptions();
if (headless) {
chromeOptions.addArguments("--headless=new");
}
chromeDriver = new ChromeDriver(chromeDriverService, chromeOptions);
return Collections.emptyMap();
}

@Override
public void stop() {
if (chromeDriver != null) {
chromeDriver.close();
}
if (chromeDriverService != null) {
chromeDriverService.stop();
}
}

@Override
public void inject(TestInjector testInjector) {
testInjector.injectIntoFields(chromeDriver, new TestInjector.MatchesType(WebDriver.class));
}
}
34 changes: 34 additions & 0 deletions src/test/java/com/marcnuri/yakd/selenium/WithSelenium.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024 Marc Nuri
*
* 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.
*
* Created on 2024-06-26, 17:30
*/
package com.marcnuri.yakd.selenium;

import io.quarkus.test.common.QuarkusTestResource;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@QuarkusTestResource(SeleniumTestResource.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface WithSelenium {

boolean headless() default true;

}

0 comments on commit e5352e8

Please sign in to comment.