Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ These modules' build will not fail anyway: they will be checked later on by the
# Entrypoint

Spectrum leverages [SpectrumSessionListener](spectrum/src/main/java/io/github/giulong/spectrum/SpectrumSessionListener.java) as its entrypoint,
which is a [LauncherSessionListener](https://junit.org/junit5/docs/current/user-guide/#launcher-api-launcher-session-listeners-custom)
which is a [LauncherSessionListener](https://docs.junit.org/current/user-guide/#launcher-api-launcher-session-listeners-custom)
registered via the Service Loader mechanism. This means we provide its fqdn in the
[org.junit.platform.launcher.LauncherSessionListener](spectrum/src/main/resources/org.junit.platform.launcher.LauncherSessionListener)
file, which is copied into the `META-INF/services` folder during the `prepare-package` phase.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# About

Spectrum is an **e2e test automation framework** that leverages **JUnit 5** and **Selenium 4** to provide these features automatically:
Spectrum is an **e2e test automation framework** that leverages **JUnit 6** and **Selenium 4** to provide these features automatically:

* **Driver** management
* **Auto-waiting** before interacting with elements, to **highly reduce flakiness**
Expand Down Expand Up @@ -124,7 +124,7 @@ and the [open issues](https://github.com/giulong/spectrum/issues).
<details>
<summary>Spectrum leverages these projects you should definitely check out!</summary>
<ul>
<li><a href="https://junit.org/junit5/docs/current/user-guide/">JUnit 5</a></li>
<li><a href="https://docs.junit.org/current/user-guide/">JUnit 6</a></li>
<li><a href="https://www.selenium.dev/">Selenium</a></li>
<li><a href="http://appium.io/docs/en/latest/">Appium</a></li>
<li><a href="https://projectlombok.org/">Lombok</a></li>
Expand Down
26 changes: 13 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

Spectrum is a [JUnit 5](https://junit.org/junit5/docs/current/user-guide/){:target="_blank"} and [Selenium 4](https://www.selenium.dev/){:target="_blank"} framework that aims to
Spectrum is a [JUnit 6](https://docs.junit.org/current/user-guide/){:target="_blank"} and [Selenium 4](https://www.selenium.dev/){:target="_blank"} framework that aims to
simplify the writing of e2e tests, providing these features:

* automatic [execution video](#automatic-execution-video-generation) generation
Expand Down Expand Up @@ -77,7 +77,7 @@ dependencies {

## Test creation

In general, all you need to do is create a **JUnit 5** test class extending the `SpectrumTest` class:
In general, all you need to do is create a **JUnit 6** test class extending the `SpectrumTest` class:

{% include copyCode.html %}

Expand Down Expand Up @@ -1745,7 +1745,7 @@ You can see an example report here:
> 💡 **Tip**<br/>
> You can provide your own *look and feel* by putting:
> * additional css rules in the `src/test/resources/css/report.css` file
> * additional css rules in the `src/test/resources/js/report.js` file
> * additional js functions in the `src/test/resources/js/report.js` file
>
> Spectrum will automatically load and apply them to the Extent Report. You can also customise the folder and name of the files above
> by changing the `extent.css` and `extent.js` keys in your `configuration*.yaml`. This is indeed the default in the internal
Expand Down Expand Up @@ -1789,7 +1789,7 @@ extent:
```

> ⚠️ **Dynamic Tests**<br/>
> [Dynamic Tests](https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests){:target="_blank"}
> [Dynamic Tests](https://docs.junit.org/current/user-guide/#writing-tests-dynamic-tests){:target="_blank"}
> are shown in the html report as a single one in the left column. In the test's details on the right,
> you'll see one collapsible nested block for each dynamic test. Additionally, if you enabled video generation,
> you'll find the full video attached on top of the right column, as well as the video related to the specific dynamic test
Expand Down Expand Up @@ -2409,14 +2409,14 @@ use to define the events they
want to be
notified about. Most of them can be used in consumers with the type of match specified below:

| Field Name | Type | Match |
|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|-------|
| [primaryId](#primaryid-and-secondaryid) | String | regex |
| [secondaryId](#primaryid-and-secondaryid) | String | regex |
| [tags](#tags) | Set\<String> | exact |
| [reason](#reason) | String | regex |
| [result](#result) | [Result]({{ site.repository_url }}/spectrum/src/main/java/io/github/giulong/spectrum/enums/Result.java){:target="_blank"} | exact |
| [context](#context) | [ExtensionContext](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExtensionContext.html){:target="_blank"} | - |
| Field Name | Type | Match |
|-------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|-------|
| [primaryId](#primaryid-and-secondaryid) | String | regex |
| [secondaryId](#primaryid-and-secondaryid) | String | regex |
| [tags](#tags) | Set\<String> | exact |
| [reason](#reason) | String | regex |
| [result](#result) | [Result]({{ site.repository_url }}/spectrum/src/main/java/io/github/giulong/spectrum/enums/Result.java){:target="_blank"} | exact |
| [context](#context) | [ExtensionContext](https://docs.junit.org/current/api/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExtensionContext.html){:target="_blank"} | - |

Let's see them in detail:

Expand Down Expand Up @@ -3644,7 +3644,7 @@ testBook:
# Parallel Execution

Spectrum tests can be run in parallel by leveraging
[JUnit Parallel Execution](https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-parallel-execution){:target="_blank"}
[JUnit Parallel Execution](https://docs.junit.org/snapshot/user-guide/#writing-tests-parallel-execution){:target="_blank"}

---

Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
<jar.skipIfEmpty>true</jar.skipIfEmpty>
<maven.install.skip>true</maven.install.skip>

<junit.version>5.13.4</junit.version>
<junit.version>6.0.0</junit.version>
<mockito.version>5.20.0</mockito.version>
<jackson.version>2.20.0</jackson.version>
<simplejavamail.version>8.12.6</simplejavamail.version>
<jsonschemagenerator.version>4.38.0</jsonschemagenerator.version>
<slf4j.version>2.0.17</slf4j.version>
<selenium.version>4.35.0</selenium.version>
<selenium.version>4.36.0</selenium.version>
</properties>

<profiles>
Expand Down Expand Up @@ -145,7 +145,7 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.13.4</version>
<version>${junit.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -195,7 +195,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.18</version>
<version>1.5.19</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
Expand Down Expand Up @@ -437,7 +437,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.6.1</version>
<version>3.6.2</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void addScreenshotToReport(final String msg, final Status status) {
final ExtensionContext context = testContext.get(EXTENSION_CONTEXT, ExtensionContext.class);
final byte[] screenshot = ((TakesScreenshot) context.getStore(GLOBAL).get(DRIVER, WebDriver.class)).getScreenshotAs(BYTES);

eventsDispatcher.fire(SCREENSHOT, SCREENSHOT, Map.of(EXTENSION_CONTEXT, context, SCREENSHOT, screenshot));
eventsDispatcher.fire(SCREENSHOT, SCREENSHOT, context, Map.of(SCREENSHOT, screenshot));

final Path path = fileUtils.writeTempFile("screenshot", ".png", screenshot);
final Media media = createScreenCaptureFromPath(path.toString()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void fire(final String reason, final Set<String> tags, final Result resul
fire(null, null, reason, result, tags, null);
}

public void fire(final String primaryId, final String reason, final Map<String, Object> payload) {
fire(primaryId, null, reason, null, null, null, payload);
public void fire(final String primaryId, final String reason, final ExtensionContext context, final Map<String, Object> payload) {
fire(primaryId, null, reason, null, null, context, payload);
}

public void fire(final String primaryId, final String reason) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
import java.nio.file.Path;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Map;

import static io.github.giulong.spectrum.SpectrumEntity.HASH_ALGORITHM;
import static io.github.giulong.spectrum.extensions.resolvers.DriverResolver.ORIGINAL_DRIVER;
import static io.github.giulong.spectrum.extensions.resolvers.TestContextResolver.EXTENSION_CONTEXT;
import static io.github.giulong.spectrum.extensions.resolvers.TestDataResolver.TEST_DATA;
import static io.github.giulong.spectrum.utils.web_driver_events.ScreenshotConsumer.SCREENSHOT;
import static java.awt.image.BufferedImage.TYPE_INT_RGB;
Expand All @@ -44,10 +42,9 @@ public VideoConsumer() {
@SneakyThrows
public void accept(final Event event) {
final Video video = configuration.getVideo();
final Map<String, Object> payload = event.getPayload();
final ExtensionContext.Store store = ((ExtensionContext) payload.get(EXTENSION_CONTEXT)).getStore(GLOBAL);
final ExtensionContext.Store store = event.getContext().getStore(GLOBAL);
final TestData testData = store.get(TEST_DATA, TestData.class);
final byte[] screenshot = (byte[]) payload.get(SCREENSHOT);
final byte[] screenshot = (byte[]) event.getPayload().get(SCREENSHOT);

if (video.isSkipDuplicateFrames() && !isNewFrame(screenshot, testData)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.nio.file.Path;

import static io.github.giulong.spectrum.extensions.resolvers.TestContextResolver.EXTENSION_CONTEXT;
import static io.github.giulong.spectrum.extensions.resolvers.TestDataResolver.TEST_DATA;
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;

Expand All @@ -22,7 +21,7 @@ protected boolean shouldAccept(final Event event) {
return false;
}

final ExtensionContext context = (ExtensionContext) event.getPayload().get(EXTENSION_CONTEXT);
final ExtensionContext context = event.getContext();
if (context == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Map;

import static io.github.giulong.spectrum.extensions.resolvers.DriverResolver.DRIVER;
import static io.github.giulong.spectrum.extensions.resolvers.TestContextResolver.EXTENSION_CONTEXT;
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;
import static org.openqa.selenium.OutputType.BYTES;

Expand All @@ -36,7 +35,7 @@ public void accept(final WebDriverEvent webDriverEvent) {
if (video.shouldRecord(frame)) {
final byte[] screenshot = ((TakesScreenshot) context.getStore(GLOBAL).get(DRIVER, WebDriver.class)).getScreenshotAs(BYTES);

eventsDispatcher.fire(SCREENSHOT, SCREENSHOT, Map.of(EXTENSION_CONTEXT, context, SCREENSHOT, screenshot));
eventsDispatcher.fire(SCREENSHOT, SCREENSHOT, context, Map.of(SCREENSHOT, screenshot));
log.trace("Recording frame {} for event '{}'", frame, webDriverEvent.getMessage());

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void addScreenshotToReport() {

assertArrayEquals(bytes, byteArrayArgumentCaptor.getValue());
verify(screenshots).put(path, bytes);
verify(eventsDispatcher).fire(SCREENSHOT, SCREENSHOT, Map.of(EXTENSION_CONTEXT, context, SCREENSHOT, bytes));
verify(eventsDispatcher).fire(SCREENSHOT, SCREENSHOT, context, Map.of(SCREENSHOT, bytes));
verify(extentTest).log(status, tag, media);
verifyNoMoreInteractions(eventsDispatcher);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ void firePrimaryIdReasonPayload() {
when(eventBuilder.reason(reason)).thenReturn(eventBuilder);
when(eventBuilder.result(null)).thenReturn(eventBuilder);
when(eventBuilder.tags(null)).thenReturn(eventBuilder);
when(eventBuilder.context(null)).thenReturn(eventBuilder);
when(eventBuilder.context(extensionContext)).thenReturn(eventBuilder);
when(eventBuilder.payload(payload)).thenReturn(eventBuilder);
when(eventBuilder.build()).thenReturn(event);

eventsDispatcher.fire(primaryId, reason, payload);
eventsDispatcher.fire(primaryId, reason, extensionContext, payload);

verify(consumer1).match(event);
verify(consumer2).match(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.stream.Stream;

import static io.github.giulong.spectrum.extensions.resolvers.DriverResolver.ORIGINAL_DRIVER;
import static io.github.giulong.spectrum.extensions.resolvers.TestContextResolver.EXTENSION_CONTEXT;
import static io.github.giulong.spectrum.extensions.resolvers.TestDataResolver.TEST_DATA;
import static io.github.giulong.spectrum.utils.web_driver_events.ScreenshotConsumer.SCREENSHOT;
import static java.awt.image.BufferedImage.TYPE_INT_RGB;
Expand Down Expand Up @@ -376,9 +375,8 @@ void resize() {
private void acceptStubs() {
when(configuration.getVideo()).thenReturn(video);
when(event.getPayload()).thenReturn(payload);
when(payload.get(EXTENSION_CONTEXT)).thenReturn(context);
when(event.getContext()).thenReturn(context);
when(context.getStore(GLOBAL)).thenReturn(store);
when(store.get(TEST_DATA, TestData.class)).thenReturn(testData);
//when(payload.get(SCREENSHOT)).thenReturn(screenshot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

import java.nio.file.Path;
import java.security.MessageDigest;
import java.util.Map;

import static io.github.giulong.spectrum.enums.Result.DISABLED;
import static io.github.giulong.spectrum.enums.Result.SUCCESSFUL;
import static io.github.giulong.spectrum.extensions.resolvers.TestContextResolver.EXTENSION_CONTEXT;
import static io.github.giulong.spectrum.extensions.resolvers.TestDataResolver.TEST_DATA;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;
Expand Down Expand Up @@ -53,9 +51,6 @@ class VideoDynamicConsumerTest {
@Mock
private Event event;

@Mock
private Map<String, Object> payload;

@Captor
private ArgumentCaptor<byte[]> byteArrayArgumentCaptor;

Expand All @@ -76,8 +71,7 @@ void shouldAccept() {
when(configuration.getVideo()).thenReturn(video);
when(video.isDisabled()).thenReturn(false);

when(event.getPayload()).thenReturn(payload);
when(payload.get(EXTENSION_CONTEXT)).thenReturn(context);
when(event.getContext()).thenReturn(context);
when(context.getStore(GLOBAL)).thenReturn(store);
when(store.get(TEST_DATA, TestData.class)).thenReturn(testData);

Expand All @@ -103,8 +97,7 @@ void shouldAcceptFalseContextNull() {
when(configuration.getVideo()).thenReturn(video);
when(video.isDisabled()).thenReturn(false);

when(event.getPayload()).thenReturn(payload);
when(payload.get(EXTENSION_CONTEXT)).thenReturn(null);
when(event.getContext()).thenReturn(null);

assertFalse(videoDynamicConsumer.shouldAccept(event));
}
Expand All @@ -117,8 +110,7 @@ void shouldAcceptFalseTestDataNull() {
when(configuration.getVideo()).thenReturn(video);
when(video.isDisabled()).thenReturn(false);

when(event.getPayload()).thenReturn(payload);
when(payload.get(EXTENSION_CONTEXT)).thenReturn(context);
when(event.getContext()).thenReturn(context);
when(context.getStore(GLOBAL)).thenReturn(store);
when(store.get(TEST_DATA, TestData.class)).thenReturn(null);

Expand All @@ -133,8 +125,7 @@ void shouldAcceptFalseTestDataNotDynamic() {
when(configuration.getVideo()).thenReturn(video);
when(video.isDisabled()).thenReturn(false);

when(event.getPayload()).thenReturn(payload);
when(payload.get(EXTENSION_CONTEXT)).thenReturn(context);
when(event.getContext()).thenReturn(context);
when(context.getStore(GLOBAL)).thenReturn(store);
when(store.get(TEST_DATA, TestData.class)).thenReturn(testData);
when(testData.isDynamic()).thenReturn(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.giulong.spectrum.utils.web_driver_events;

import io.github.giulong.spectrum.enums.Frame;
import io.github.giulong.spectrum.utils.ContextManager;
import io.github.giulong.spectrum.utils.HtmlUtils;
import io.github.giulong.spectrum.utils.Reflections;
import io.github.giulong.spectrum.utils.events.EventsDispatcher;
Expand All @@ -19,7 +18,6 @@

import static io.github.giulong.spectrum.enums.Frame.AUTO_AFTER;
import static io.github.giulong.spectrum.extensions.resolvers.DriverResolver.DRIVER;
import static io.github.giulong.spectrum.extensions.resolvers.TestContextResolver.EXTENSION_CONTEXT;
import static io.github.giulong.spectrum.utils.web_driver_events.ScreenshotConsumer.SCREENSHOT;
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -31,9 +29,6 @@ class ScreenshotConsumerTest {
@Mock
private HtmlUtils htmlUtils;

@Mock
private ContextManager contextManager;

@Mock
private ExtensionContext.Store store;

Expand Down Expand Up @@ -76,7 +71,7 @@ void accept() {

screenshotConsumer.accept(webDriverEvent);

verify(eventsDispatcher).fire(SCREENSHOT, SCREENSHOT, Map.of(EXTENSION_CONTEXT, context, SCREENSHOT, bytes));
verify(eventsDispatcher).fire(SCREENSHOT, SCREENSHOT, context, Map.of(SCREENSHOT, bytes));
verifyNoMoreInteractions(eventsDispatcher);
}

Expand Down
Loading