From 9d6131f48ef123b6c3f4e95ba3c76912367fc916 Mon Sep 17 00:00:00 2001 From: bhecquet Date: Fri, 12 Jul 2024 12:07:11 +0200 Subject: [PATCH] Remove 'browserName' capability from stereotype when using RelaySession (#14247) * Remove 'browserName' capability from stereotype. We expect it to be present is SessionRequest * Only remove 'browserName' when 'appium:app' is present * Formatting file --------- Co-authored-by: Diego Molina Co-authored-by: Diego Molina --- .../grid/node/relay/RelaySessionFactory.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java b/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java index 889afb5bb958a..86860ab0919e1 100644 --- a/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java +++ b/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java @@ -40,6 +40,7 @@ import java.util.logging.Logger; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ImmutableCapabilities; +import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.SessionNotCreatedException; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.grid.data.CreateSessionRequest; @@ -49,6 +50,7 @@ import org.openqa.selenium.internal.Debug; import org.openqa.selenium.internal.Either; import org.openqa.selenium.internal.Require; +import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.Command; import org.openqa.selenium.remote.Dialect; import org.openqa.selenium.remote.DriverCommand; @@ -146,7 +148,16 @@ public Either apply(CreateSessionRequest sess new SessionNotCreatedException( "New session request capabilities do not " + "match the stereotype.")); } - capabilities = capabilities.merge(stereotype); + + // remove browserName capability if 'appium:app' is present as it breaks appium tests when app + // is provided + // they are mutually exclusive + MutableCapabilities filteredStereotype = new MutableCapabilities(stereotype); + if (capabilities.getCapability("appium:app") != null) { + filteredStereotype.setCapability(CapabilityType.BROWSER_NAME, (String) null); + } + + capabilities = capabilities.merge(filteredStereotype); LOG.info("Starting session for " + capabilities); try (Span span = tracer.getCurrentContext().createSpan("relay_session_factory.apply")) {