From a0ec2c5c618da100356b104147131bf98166d970 Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Mon, 30 May 2022 14:01:32 +0200 Subject: [PATCH] [java] Removing deprecated caps from response and temporarily excluding some non W3C caps from checks since they are returned by browser drivers. Fixes #10711 --- .../selenium/AcceptedW3CCapabilityKeys.java | 9 +++ .../selenium/remote/RemoteWebDriver.java | 33 ++------- .../selenium/JavascriptEnabledDriverTest.java | 16 ++--- .../RemoteWebDriverInitializationTest.java | 68 +++++++++---------- .../support/ui/WebDriverWaitTest.java | 18 ++--- 5 files changed, 66 insertions(+), 78 deletions(-) diff --git a/java/src/org/openqa/selenium/AcceptedW3CCapabilityKeys.java b/java/src/org/openqa/selenium/AcceptedW3CCapabilityKeys.java index b8e2f14b2883a..3286e1538263e 100644 --- a/java/src/org/openqa/selenium/AcceptedW3CCapabilityKeys.java +++ b/java/src/org/openqa/selenium/AcceptedW3CCapabilityKeys.java @@ -33,6 +33,15 @@ public class AcceptedW3CCapabilityKeys implements Predicate { "^proxy$", "^setWindowRect$", "^strictFileInteractability$", + // TODO: Needs to be removed when ChromeDriver issue is resolved. Not a W3C capability + // https://bugs.chromium.org/p/chromedriver/issues/detail?id=4129 + "^networkConnectionEnabled$", + // TODO: Needs to be removed when ChromeDriver issue is resolved. Not a W3C capability + // https://bugs.chromium.org/p/chromedriver/issues/detail?id=4129 + "^chrome$", + // TODO: Needs to be removed when GeckoDriver issue is resolved. Not a W3C capability + // https://github.com/mozilla/geckodriver/issues/2023 + "^platformVersion$", "^timeouts$", "^unhandledPromptBehavior$", "^webSocketUrl$") // from webdriver-bidi diff --git a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java index 7a6c8b4de64d4..9cb370486effc 100644 --- a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java +++ b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java @@ -94,7 +94,6 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.logging.Level.SEVERE; import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS; -import static org.openqa.selenium.remote.CapabilityType.PLATFORM; import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_JAVASCRIPT; @@ -256,20 +255,18 @@ protected void startSession(Capabilities capabilities) { if (responseValue == null) { throw new SessionNotCreatedException( "The underlying command executor returned a response without payload: " + - response.toString()); + response); } if (!(responseValue instanceof Map)) { throw new SessionNotCreatedException( "The underlying command executor returned a response with a non well formed payload: " + - response.toString()); + response); } @SuppressWarnings("unchecked") Map rawCapabilities = (Map) responseValue; MutableCapabilities returnedCapabilities = new MutableCapabilities(rawCapabilities); - String platformString = (String) rawCapabilities.getOrDefault( - PLATFORM, - rawCapabilities.get(PLATFORM_NAME)); + String platformString = (String) rawCapabilities.get(PLATFORM_NAME); Platform platform; try { if (platformString == null || "".equals(platformString)) { @@ -282,20 +279,8 @@ protected void startSession(Capabilities capabilities) { // system property. Try to recover and parse this. platform = Platform.extractFromSysProperty(platformString); } - returnedCapabilities.setCapability(PLATFORM, platform); returnedCapabilities.setCapability(PLATFORM_NAME, platform); - if (rawCapabilities.containsKey(SUPPORTS_JAVASCRIPT)) { - Object raw = rawCapabilities.get(SUPPORTS_JAVASCRIPT); - if (raw instanceof String) { - returnedCapabilities.setCapability(SUPPORTS_JAVASCRIPT, Boolean.parseBoolean((String) raw)); - } else if (raw instanceof Boolean) { - returnedCapabilities.setCapability(SUPPORTS_JAVASCRIPT, ((Boolean) raw).booleanValue()); - } - } else { - returnedCapabilities.setCapability(SUPPORTS_JAVASCRIPT, true); - } - this.capabilities = returnedCapabilities; sessionId = new SessionId(response.getSessionId()); } @@ -734,20 +719,16 @@ public String toString() { return super.toString(); } - // w3c name first - Object platform = caps.getCapability(PLATFORM_NAME); - if (!(platform instanceof String)) { - platform = caps.getCapability(PLATFORM); - } - if (platform == null) { - platform = "unknown"; + Object platformName = caps.getCapability(PLATFORM_NAME); + if (platformName == null) { + platformName = "unknown"; } return String.format( "%s: %s on %s (%s)", getClass().getSimpleName(), caps.getBrowserName(), - platform, + platformName, getSessionId()); } diff --git a/java/test/org/openqa/selenium/JavascriptEnabledDriverTest.java b/java/test/org/openqa/selenium/JavascriptEnabledDriverTest.java index d096d44369201..0eb69dbac6d3d 100644 --- a/java/test/org/openqa/selenium/JavascriptEnabledDriverTest.java +++ b/java/test/org/openqa/selenium/JavascriptEnabledDriverTest.java @@ -17,22 +17,21 @@ package org.openqa.selenium; +import org.junit.Test; +import org.openqa.selenium.interactions.Locatable; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.testing.JUnit4TestBase; +import org.openqa.selenium.testing.NoDriverAfterTest; +import org.openqa.selenium.testing.NotYetImplemented; + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeTrue; import static org.openqa.selenium.WaitingConditions.elementTextToEqual; import static org.openqa.selenium.WaitingConditions.elementValueToEqual; import static org.openqa.selenium.WaitingConditions.windowToBeSwitchedToWithName; -import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_JAVASCRIPT; import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs; import static org.openqa.selenium.testing.drivers.Browser.SAFARI; -import org.junit.Test; -import org.openqa.selenium.interactions.Locatable; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.testing.JUnit4TestBase; -import org.openqa.selenium.testing.NoDriverAfterTest; -import org.openqa.selenium.testing.NotYetImplemented; - public class JavascriptEnabledDriverTest extends JUnit4TestBase { @Test @@ -189,7 +188,6 @@ public void testShouldBeAbleToClickIfEvenSomethingHorribleHappens() { @Test public void testShouldBeAbleToGetTheLocationOfAnElement() { assumeTrue(driver instanceof JavascriptExecutor); - assumeTrue(((HasCapabilities) driver).getCapabilities().is(SUPPORTS_JAVASCRIPT)); driver.get(pages.javascriptPage); diff --git a/java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java b/java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java index ead487d30ada8..76f3a1e072332 100644 --- a/java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java +++ b/java/test/org/openqa/selenium/remote/RemoteWebDriverInitializationTest.java @@ -17,22 +17,6 @@ package org.openqa.selenium.remote; -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonMap; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; -import static org.openqa.selenium.remote.WebDriverFixture.echoCapabilities; -import static org.openqa.selenium.remote.WebDriverFixture.exceptionResponder; -import static org.openqa.selenium.remote.WebDriverFixture.nullResponder; -import static org.openqa.selenium.remote.WebDriverFixture.nullValueResponder; -import static org.openqa.selenium.remote.WebDriverFixture.valueResponder; - import com.google.common.collect.ImmutableMap; import org.junit.Test; @@ -55,6 +39,22 @@ import java.time.Duration; import java.util.UUID; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; +import static org.openqa.selenium.remote.WebDriverFixture.echoCapabilities; +import static org.openqa.selenium.remote.WebDriverFixture.exceptionResponder; +import static org.openqa.selenium.remote.WebDriverFixture.nullResponder; +import static org.openqa.selenium.remote.WebDriverFixture.nullValueResponder; +import static org.openqa.selenium.remote.WebDriverFixture.valueResponder; + @Category(UnitTests.class) public class RemoteWebDriverInitializationTest { private boolean quitCalled = false; @@ -172,24 +172,7 @@ public void canHandleNonStandardCapabilitiesReturnedByRemoteEnd() throws IOExcep CommandExecutor executor = mock(CommandExecutor.class); when(executor.execute(any())).thenReturn(resp); RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities()); - assertThat(driver.getCapabilities().getCapability("platform")).isEqualTo(Platform.UNIX); - } - - private class BadStartSessionRemoteWebDriver extends RemoteWebDriver { - public BadStartSessionRemoteWebDriver(CommandExecutor executor, - Capabilities desiredCapabilities) { - super(executor, desiredCapabilities); - } - - @Override - protected void startSession(Capabilities desiredCapabilities) { - throw new RuntimeException("Stub session that should fail"); - } - - @Override - public void quit() { - quitCalled = true; - } + assertThat(driver.getCapabilities().getCapability("platformName")).isEqualTo(Platform.UNIX); } @Test @@ -225,4 +208,21 @@ public void verifyNoCommands(CommandExecutor executor) { } verifyNoMoreInteractions(executor); } + + private class BadStartSessionRemoteWebDriver extends RemoteWebDriver { + public BadStartSessionRemoteWebDriver(CommandExecutor executor, + Capabilities desiredCapabilities) { + super(executor, desiredCapabilities); + } + + @Override + protected void startSession(Capabilities desiredCapabilities) { + throw new RuntimeException("Stub session that should fail"); + } + + @Override + public void quit() { + quitCalled = true; + } + } } diff --git a/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java b/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java index c4e025b8de5b1..712c04ba5bd14 100644 --- a/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java +++ b/java/test/org/openqa/selenium/support/ui/WebDriverWaitTest.java @@ -17,13 +17,6 @@ package org.openqa.selenium.support.ui; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.withSettings; - import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -49,6 +42,13 @@ import java.io.IOException; import java.time.Duration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; + @Category(UnitTests.class) public class WebDriverWaitTest { @@ -77,8 +77,8 @@ public void shouldIncludeRemoteInfoForWrappedDriverTimeout() throws IOException new WebDriverWait(testDriver, Duration.ofSeconds(1), Duration.ofMillis(200), clock, clock); assertThatExceptionOfType(TimeoutException.class) - .isThrownBy(() -> wait.until(d -> false)) - .withMessageContaining("Capabilities {javascriptEnabled: true, platform: ANY, platformName: ANY}") + .isThrownBy(() -> wait.until(d -> false)) + .withMessageContaining("Capabilities {platformName: ANY}") .withMessageContaining("Session ID: foo"); }