Skip to content

Commit

Permalink
feature: configuration key to keep the browser open at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
giulong committed Dec 25, 2024
1 parent 3aa928f commit 6a935bd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ public static class Extent {
@Generated
public static class Drivers {

@JsonPropertyDescription("Whether to keep the driver open after the execution")
private boolean keepOpen;

@JsonPropertyDescription("Driver's fluent waits")
private Waits waits;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public void accept(final Event event) {

final Configuration.Runtime runtime = configuration.getRuntime();

runtime.getDriver().shutdown();
if (!configuration.getDrivers().isKeepOpen()) {
runtime.getDriver().shutdown();
}

runtime.getEnvironment().shutdown();
}
}
2 changes: 2 additions & 0 deletions spectrum/src/main/resources/yaml/configuration.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ environments:

# Drivers configuration
drivers:
keepOpen: false # Whether to keep the driver open after the execution

waits:
implicit: 0 # Seconds Selenium waits before throwing a NoSuchElementException when an element isn't found
pageLoadTimeout: 10 # Seconds that Selenium waits before throwing an exception because the page wasn't fully loaded yet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class DriverConsumerTest {
@Mock
private Configuration.Runtime runtime;

@Mock
private Configuration.Drivers drivers;

@Mock
private Event event;

Expand Down Expand Up @@ -52,10 +55,12 @@ void acceptSkipped() {
}

@Test
@DisplayName("accept should shutdown the driver")
@DisplayName("accept should shutdown the driver and the environment")
void accept() {
when(event.getResult()).thenReturn(SUCCESSFUL);
when(configuration.getRuntime()).thenReturn(runtime);
when(configuration.getDrivers()).thenReturn(drivers);
when(drivers.isKeepOpen()).thenReturn(false);
doReturn(driver).when(runtime).getDriver();
doReturn(environment).when(runtime).getEnvironment();

Expand All @@ -64,4 +69,19 @@ void accept() {
verify(driver).shutdown();
verify(environment).shutdown();
}

@Test
@DisplayName("accept should not shutdown the driver if drivers.keepOpen is true")
void acceptKeepOpen() {
when(event.getResult()).thenReturn(SUCCESSFUL);
when(configuration.getRuntime()).thenReturn(runtime);
when(configuration.getDrivers()).thenReturn(drivers);
when(drivers.isKeepOpen()).thenReturn(true);
doReturn(environment).when(runtime).getEnvironment();

driverConsumer.accept(event);

verify(driver, never()).shutdown();
verify(environment).shutdown();
}
}

0 comments on commit 6a935bd

Please sign in to comment.