From 704284cf4810cad26d956614922a7c46d86f99ef Mon Sep 17 00:00:00 2001
From: Vincent Massol <vincent@massol.net>
Date: Thu, 15 Dec 2022 12:18:21 +0100
Subject: [PATCH] [Misc] Upgrade to Selenium 4.7.2

---
 .../xwiki-platform-test/pom.xml               |  2 +-
 .../test/docker/junit5/browser/Browser.java   | 74 ++++++++++---------
 2 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/xwiki-platform-core/xwiki-platform-test/pom.xml b/xwiki-platform-core/xwiki-platform-test/pom.xml
index 447c754b973..0597909f30e 100644
--- a/xwiki-platform-core/xwiki-platform-test/pom.xml
+++ b/xwiki-platform-core/xwiki-platform-test/pom.xml
@@ -32,7 +32,7 @@
   <packaging>pom</packaging>
   <description>XWiki Platform - Test - Parent POM</description>
   <properties>
-    <selenium.version>4.7.1</selenium.version>
+    <selenium.version>4.7.2</selenium.version>
     <!-- Don't run backward-compatibility checks in test modules since we don't consider them as public APIs -->
     <xwiki.revapi.skip>true</xwiki.revapi.skip>
   </properties>
diff --git a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-docker/src/main/java/org/xwiki/test/docker/junit5/browser/Browser.java b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-docker/src/main/java/org/xwiki/test/docker/junit5/browser/Browser.java
index 23df21ffb6e..b9e8eaec2af 100644
--- a/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-docker/src/main/java/org/xwiki/test/docker/junit5/browser/Browser.java
+++ b/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-docker/src/main/java/org/xwiki/test/docker/junit5/browser/Browser.java
@@ -42,12 +42,12 @@ public enum Browser
     /**
      * The Firefox Browser.
      */
-    FIREFOX(new FirefoxOptions()),
+    FIREFOX(buildFirefoxOptions()),
 
     /**
      * The Chrome Browser.
      */
-    CHROME(new ChromeOptions());
+    CHROME(buildChromeOptions());
 
     /**
      * The path where to store the test-resources on the browser container.
@@ -64,40 +64,6 @@ public enum Browser
     Browser(Capabilities capabilities)
     {
         this.capabilities = capabilities;
-        this.forceDefaultCapabilities();
-    }
-
-    /**
-     * Ensure that some capabilities are set as expected for our tests.
-     */
-    private void forceDefaultCapabilities()
-    {
-        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
-        LoggingPreferences logPrefs = new LoggingPreferences();
-        logPrefs.enable(LogType.BROWSER, Level.ALL);
-        // By default we want to be able to handle alerts.
-        desiredCapabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
-        desiredCapabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
-        desiredCapabilities.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
-        desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
-        this.capabilities = this.capabilities.merge(desiredCapabilities);
-
-        if (this.capabilities instanceof FirefoxOptions) {
-            FirefoxOptions firefoxOptions = (FirefoxOptions) this.capabilities;
-            // Create the profile on the fly, mostly for test.
-            if (firefoxOptions.getProfile() == null) {
-                firefoxOptions.setProfile(new FirefoxProfile());
-            }
-            // We want to ensure that those events are taking into account.
-            firefoxOptions.addPreference("dom.disable_beforeunload", false);
-        } else if (this.capabilities instanceof ChromeOptions) {
-            ChromeOptions chromeOptions = (ChromeOptions) this.capabilities;
-            chromeOptions.addArguments(
-                "--whitelisted-ips",
-                "--no-sandbox",
-                "--disable-extensions"
-            );
-        }
     }
 
     /**
@@ -116,4 +82,40 @@ public String getTestResourcesPath()
     {
         return TEST_RESOURCES_PATH;
     }
+
+    private static Capabilities buildCommonCapabilities()
+    {
+        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
+        // By default, we want to be able to handle alerts.
+        desiredCapabilities.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
+        return desiredCapabilities;
+    }
+
+    private static FirefoxOptions buildFirefoxOptions()
+    {
+        FirefoxOptions options = new FirefoxOptions();
+        options.merge(buildCommonCapabilities());
+        // Create the profile on the fly, mostly for test.
+        if (options.getProfile() == null) {
+            options.setProfile(new FirefoxProfile());
+        }
+        // We want to ensure that those events are taking into account.
+        options.addPreference("dom.disable_beforeunload", false);
+        return options;
+    }
+
+    private static ChromeOptions buildChromeOptions()
+    {
+        ChromeOptions options = new ChromeOptions();
+        options.merge(buildCommonCapabilities());
+        LoggingPreferences logPrefs = new LoggingPreferences();
+        logPrefs.enable(LogType.BROWSER, Level.ALL);
+        options.setCapability(ChromeOptions.LOGGING_PREFS, logPrefs);
+        options.addArguments(
+            "--whitelisted-ips",
+            "--no-sandbox",
+            "--disable-extensions"
+        );
+        return options;
+    }
 }
-- 
GitLab