Skip to content

Commit 6d12835

Browse files
committed
Bump to WebDriverManager 6.1.0 and update BrowserWatcher features
1 parent 3b98163 commit 6d12835

File tree

8 files changed

+56
-73
lines changed

8 files changed

+56
-73
lines changed

pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<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">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
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">
24
<modelVersion>4.0.0</modelVersion>
35

46
<groupId>io.github.bonigarcia</groupId>
@@ -8,7 +10,7 @@
810
<properties>
911
<!-- Compile dependencies -->
1012
<slf4j.version>2.0.17</slf4j.version>
11-
<webdrivermanager.version>6.0.1</webdrivermanager.version>
13+
<webdrivermanager.version>6.1.0</webdrivermanager.version>
1214

1315
<!-- Provided dependencies -->
1416
<junit.jupiter.version>5.12.2</junit.jupiter.version>

src/doc/asciidoc/index.adoc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ TIP: Notice that the previous example also uses the attributes `lang` and `timez
161161
.Example of noVNC session using Chrome in Docker
162162
image::seljup-vnc.png[scaledwidth=100%]
163163

164-
==== Recordings
165-
The following related feature is the recording of the remote session of a dockerized browser. To enable it, we need to set to `true` the attribute `recording` of `@DockerBrowser`. Internally, Selenium-Jupiter starts another Docker container using https://ffmpeg.org/[FFmpeg] to record the browser session. At the end of the test, we can find the recording in MP4, by default, in the same folder of the project root. The following example shows a simple using this feature.
164+
==== Video Recording
165+
The following related feature is recording the desktop session of a dockerized browser. To enable it, we need to set to `true` the attribute `recording` of `@DockerBrowser`. Internally, Selenium-Jupiter starts another Docker container using https://ffmpeg.org/[FFmpeg] to record the browser session. At the end of the test, we can find the recording in MP4, by default, in the same folder of the project root. The following example shows a simple using this feature.
166166

167167
[source,java]
168168
----
@@ -210,8 +210,7 @@ TIP: You can use the capabilities annotations also for browsers in Docker (see h
210210
=== Template tests
211211
Selenium-Jupiter uses a standard feature of JUnit 5 called http://junit.org/junit5/docs/current/user-guide/#writing-tests-test-templates[test templates]. Test templates are a special kind of test in which the same test logic is executed several times according to some custom data. In Selenium-Jupiter, the data to feed a test template is known as _browser scenario_.
212212

213-
The following example shows a test using this feature.
214-
Notice that instead of declaring the method with the usual `@Test` annotation, we use the JUnit 5's `@TestTemplate`. Then, the parameter type of the test template method is `WebDriver`. This type is the generic interface of Selenium WebDriver, and the concise type (i.e. `ChromeDriver,` `FirefoxDriver,` etc.) is determined by Selenium-Jupiter in runtime. The `@BrowserScenarioTest` annotation can be used for more control over the test names generated by the template tests.
213+
The following example shows a test using this feature. Notice that instead of declaring the method with the usual `@Test` annotation, we use the JUnit 5's `@TestTemplate`. Then, the parameter type of the test template method is `WebDriver`. This type is the generic interface of Selenium WebDriver, and the concise type (i.e. `ChromeDriver,` `FirefoxDriver,` etc.) is determined by Selenium-Jupiter in runtime. Also, the `@BrowserScenarioTest` annotation can be used for more control over the test names generated by the template tests.
215214

216215
[source,java]
217216
----
@@ -260,7 +259,7 @@ In addition to log gathering, BrowserWatcher allows displaying the console logs
260259

261260
[source,java]
262261
----
263-
include::../../test/java/io/github/bonigarcia/seljup/test/watcher/DisplayLogsChromeTest.java[tags=snippet-in-doc,indent=0]
262+
include::../../test/java/io/github/bonigarcia/seljup/test/watcher/DisplayLogsFirefoxTest.java[tags=snippet-in-doc,indent=0]
264263
----
265264

266265
The following picture shows an example of these notifications:
@@ -270,15 +269,17 @@ The following picture shows an example of these notifications:
270269
.Display logs example
271270
image::display-console-logs-example-v3.png[scaledwidth=100%]
272271

273-
==== Tab Recording
274-
BrowserWatcher allows recording a browser tab. This feature requires a page loaded in the current tab (in other words, it cannot record empty or configuration pages). Then, the recording is started using the method `startRecording()` and stopped with `stopRecording()`, for instance, as follows:
272+
WARNING: This feature is not available for BrowserWatcher 2.x (i.e., based on manifest v3 -MV3-). Therefore, this feature is currently only available for Firefox.
273+
274+
==== Video Recording
275+
BrowserWatcher (MV3) allows recording the current browser tab (i.e., the browser viewport). This feature requires a page loaded in the current tab (in other words, it cannot record empty or configuration pages). Then, the recording is started using the method `startRecording()` and stopped with `stopRecording()`. After stopping, the video recording will be automatically downloaded by the browser, and the recording (a webm file) will be stored in the downloads folder. You can discover the path of this recording using the method `getRecordingPath()`. The following test illustrates this feature:
275276

276277
[source,java]
277278
----
278-
include::../../test/java/io/github/bonigarcia/seljup/test/watcher/RecordEdgeTest.java[tags=snippet-in-doc,indent=0]
279+
include::../../test/java/io/github/bonigarcia/seljup/test/watcher/RecordChromeTest.java[tags=snippet-in-doc,indent=0]
279280
----
280281

281-
WARNING: This feature is based on the API https://developer.chrome.com/docs/extensions/reference/tabCapture/[tabCapture]. Therefore, this feature is not available in Firefox since this API is not implemented by Firefox yet.
282+
WARNING: This feature is based on the https://developer.chrome.com/docs/extensions/reference/tabCapture/[tabCapture API]. Therefore, it is only available in Chromium-based browsers (e.g., Chrome and Edge).
282283

283284
==== Disabling CSP
284285
https://content-security-policy.com/[Content Security Policy (CSP)] is the name of an HTTP response header that browsers use to improve the security of web pages. CSP helps to protect from attacks such as cross-site scripting (XSS). Nevertheless, developers might want to disable the CSP headers received from the server for testing purposes. For this reason, BrowserWatcher allows bypassing these CSP headers. This feature (i.e., disabling CSP headers) can be enabled in WebDriverManager using the property `disableCsp`, as follows:

src/main/java/io/github/bonigarcia/seljup/SeleniumJupiter.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,13 +557,15 @@ public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContex
557557
if (!browserJsonContent.isEmpty()) {
558558
return new Gson()
559559
.fromJson(browserJsonContent, BrowsersTemplate.class)
560-
.getStream().map(b -> invocationContext(b, this, extensionContext));
560+
.getStream()
561+
.map(b -> invocationContext(b, this, extensionContext));
561562
}
562563

563564
if (browserListMap != null) {
564565
List<Browser> browsers = browserListMap.get(contextId);
565566
if (browsers != null) {
566-
return Stream.of(invocationContext(browsers, this, extensionContext));
567+
return Stream.of(invocationContext(browsers, this,
568+
extensionContext));
567569
} else {
568570
return Stream.empty();
569571
}
@@ -578,17 +580,20 @@ public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContex
578580
}
579581

580582
private synchronized TestTemplateInvocationContext invocationContext(
581-
List<Browser> template, SeleniumJupiter parent, ExtensionContext extensionContext) {
583+
List<Browser> template, SeleniumJupiter parent,
584+
ExtensionContext extensionContext) {
582585
return new TestTemplateInvocationContext() {
583586
@Override
584587
public String getDisplayName(int invocationIndex) {
585-
return AnnotationSupport.findAnnotation(
586-
extensionContext.getRequiredTestMethod(), BrowserScenarioTest.class)
587-
.map(annotation -> BrowserScenarioTest.NameFormatter.format(
588-
annotation.name(),
589-
extensionContext.getDisplayName(),
590-
template.get(0))
591-
).orElse(template.toString());
588+
return AnnotationSupport
589+
.findAnnotation(
590+
extensionContext.getRequiredTestMethod(),
591+
BrowserScenarioTest.class)
592+
.map(annotation -> BrowserScenarioTest.NameFormatter
593+
.format(annotation.name(),
594+
extensionContext.getDisplayName(),
595+
template.get(0)))
596+
.orElse(template.toString());
592597
}
593598

594599
@Override
@@ -659,7 +664,8 @@ public void putBrowserList(String key, List<Browser> browserList) {
659664
}
660665

661666
private boolean isTestTemplate(ExtensionContext extensionContext) {
662-
return AnnotationSupport.isAnnotated(extensionContext.getTestMethod(), TestTemplate.class);
667+
return AnnotationSupport.isAnnotated(extensionContext.getTestMethod(),
668+
TestTemplate.class);
663669
}
664670

665671
private boolean isGeneric(Class<?> type) {
@@ -824,6 +830,10 @@ public List<Map<String, Object>> getLogs(WebDriver driver) {
824830
return invokeWdm(driver, "getLogs");
825831
}
826832

833+
public void startRecording() {
834+
invokeWdm("startRecording");
835+
}
836+
827837
public void startRecording(String recFilename) {
828838
invokeWdm("startRecording", recFilename);
829839
}
@@ -840,6 +850,14 @@ public void stopRecording(WebDriver driver) {
840850
invokeWdm(driver, "stopRecording");
841851
}
842852

853+
public Path getRecordingPath() {
854+
return invokeWdm("getRecordingPath");
855+
}
856+
857+
public Path getRecordingPath(WebDriver driver) {
858+
return invokeWdm(driver, "getRecordingPath");
859+
}
860+
843861
@SuppressWarnings("unchecked")
844862
public <T> T invokeWdm(String method, Object... params) {
845863
T out = null;

src/test/java/io/github/bonigarcia/seljup/test/watcher/DisableCspFirefoxTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25-
import org.junit.jupiter.api.Disabled;
2625
import org.junit.jupiter.api.Test;
2726
import org.junit.jupiter.api.extension.RegisterExtension;
2827
import org.openqa.selenium.firefox.FirefoxDriver;
2928

3029
import io.github.bonigarcia.seljup.SeleniumJupiter;
3130
import io.github.bonigarcia.seljup.Watch;
3231

33-
@Disabled
3432
class DisableCspFirefoxTest {
3533

3634
@RegisterExtension

src/test/java/io/github/bonigarcia/seljup/test/watcher/DisplayLogsChromeTest.java renamed to src/test/java/io/github/bonigarcia/seljup/test/watcher/DisplayLogsFirefoxTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@
2626
import java.util.Map;
2727

2828
import org.junit.jupiter.api.AfterEach;
29-
import org.junit.jupiter.api.Disabled;
3029
import org.junit.jupiter.api.Test;
3130
import org.junit.jupiter.api.extension.RegisterExtension;
32-
import org.openqa.selenium.chrome.ChromeDriver;
31+
import org.openqa.selenium.firefox.FirefoxDriver;
3332
import org.slf4j.Logger;
3433

3534
import io.github.bonigarcia.seljup.SeleniumJupiter;
3635
import io.github.bonigarcia.seljup.Watch;
3736

38-
@Disabled
39-
class DisplayLogsChromeTest {
37+
class DisplayLogsFirefoxTest {
4038

4139
static final Logger log = getLogger(lookup().lookupClass());
4240

@@ -50,7 +48,7 @@ void teardown() throws InterruptedException {
5048
}
5149

5250
@Test
53-
void test(@Watch(display = true) ChromeDriver driver) {
51+
void test(@Watch(display = true) FirefoxDriver driver) {
5452
driver.get(
5553
"https://bonigarcia.dev/selenium-webdriver-java/console-logs.html");
5654

src/test/java/io/github/bonigarcia/seljup/test/watcher/GatherLogsFirefoxTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27-
import org.junit.jupiter.api.Disabled;
2827
import org.junit.jupiter.api.Test;
2928
import org.junit.jupiter.api.extension.RegisterExtension;
3029
import org.openqa.selenium.firefox.FirefoxDriver;
@@ -33,7 +32,6 @@
3332
import io.github.bonigarcia.seljup.SeleniumJupiter;
3433
import io.github.bonigarcia.seljup.Watch;
3534

36-
@Disabled
3735
class GatherLogsFirefoxTest {
3836

3937
static final Logger log = getLogger(lookup().lookupClass());

src/test/java/io/github/bonigarcia/seljup/test/watcher/RecordEdgeTest.java renamed to src/test/java/io/github/bonigarcia/seljup/test/watcher/RecordChromeTest.java

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,36 @@
1818

1919
//tag::snippet-in-doc[]
2020
import static java.lang.invoke.MethodHandles.lookup;
21-
import static org.assertj.core.api.Assertions.fail;
21+
import static org.assertj.core.api.Assertions.assertThat;
2222
import static org.slf4j.LoggerFactory.getLogger;
2323

24-
import java.io.File;
24+
import java.nio.file.Path;
2525
import java.time.Duration;
26-
import java.util.concurrent.TimeUnit;
2726

28-
import org.junit.jupiter.api.BeforeEach;
29-
import org.junit.jupiter.api.Disabled;
3027
import org.junit.jupiter.api.Test;
3128
import org.junit.jupiter.api.extension.RegisterExtension;
3229
import org.openqa.selenium.By;
33-
import org.openqa.selenium.edge.EdgeDriver;
30+
import org.openqa.selenium.chrome.ChromeDriver;
3431
import org.openqa.selenium.support.ui.ExpectedConditions;
3532
import org.openqa.selenium.support.ui.WebDriverWait;
3633
import org.slf4j.Logger;
3734

3835
import io.github.bonigarcia.seljup.SeleniumJupiter;
3936
import io.github.bonigarcia.seljup.Watch;
4037

41-
@Disabled
42-
class RecordEdgeTest {
38+
class RecordChromeTest {
4339

4440
static final Logger log = getLogger(lookup().lookupClass());
4541

46-
static final int REC_TIMEOUT_SEC = 10;
47-
static final int POLL_TIME_MSEC = 100;
48-
static final String REC_FILENAME = "myRecordingEdge";
49-
static final String REC_EXT = ".webm";
50-
5142
@RegisterExtension
5243
static SeleniumJupiter seleniumJupiter = new SeleniumJupiter();
5344

54-
File targetFolder;
55-
56-
@BeforeEach
57-
void setup() {
58-
targetFolder = new File(System.getProperty("user.home"), "Downloads");
59-
}
60-
6145
@Test
62-
void test(@Watch EdgeDriver driver) throws InterruptedException {
46+
void test(@Watch ChromeDriver driver) throws InterruptedException {
6347
driver.get(
6448
"https://bonigarcia.dev/selenium-webdriver-java/slow-calculator.html");
6549

66-
seleniumJupiter.startRecording(REC_FILENAME);
50+
seleniumJupiter.startRecording();
6751

6852
// 1 + 3
6953
driver.findElement(By.xpath("//span[text()='1']")).click();
@@ -77,22 +61,10 @@ void test(@Watch EdgeDriver driver) throws InterruptedException {
7761

7862
seleniumJupiter.stopRecording();
7963

80-
long timeoutMs = System.currentTimeMillis()
81-
+ TimeUnit.SECONDS.toMillis(REC_TIMEOUT_SEC);
82-
83-
File recFile;
84-
do {
85-
recFile = new File(targetFolder, REC_FILENAME + REC_EXT);
86-
if (System.currentTimeMillis() > timeoutMs) {
87-
fail("Timeout of " + REC_TIMEOUT_SEC
88-
+ " seconds waiting for recording " + recFile);
89-
break;
90-
}
91-
Thread.sleep(POLL_TIME_MSEC);
92-
93-
} while (!recFile.exists());
64+
Path recordingPath = seleniumJupiter.getRecordingPath();
65+
assertThat(recordingPath).exists();
9466

95-
log.debug("Recording available at {}", recFile);
67+
log.debug("Recording available at {}", recordingPath);
9668
}
9769

9870
}

src/test/resources/browsers.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
[
1616
{
1717
"type": "chrome-in-docker",
18-
"version": "beta",
19-
"arguments": [
20-
"--disable-gpu",
21-
"--no-sandbox"
22-
]
18+
"version": "beta"
2319
}
2420
],
2521
[

0 commit comments

Comments
 (0)