Skip to content

Commit

Permalink
Merge pull request #31 from ApplauseOSS/only-add-proxy-to-client-conf…
Browse files Browse the repository at this point in the history
…ig-if-not-blank

Only add proxy url to the RemoteWebDriver if the proxy url is not blank
  • Loading branch information
rconner46 authored Nov 26, 2024
2 parents 0f5ce61 + 3b7dc3f commit 088cfa0
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
import java.time.Duration;
import java.util.Locale;
import java.util.Optional;
import javax.annotation.Nullable;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.util.Strings;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.HttpCommandExecutor;
Expand All @@ -40,15 +42,28 @@
@Log4j2
public class RemoteDriverManager extends AbstractDriverManager {
private final URL seleniumGridUrl;
private final String httpProxyUrl;

/**
* Constructs a new RemoteDriverManager pointed at the provided selenium grid
*
* @param seleniumGridUrl The URL of the selenium grid
*/
public RemoteDriverManager(final @NonNull URL seleniumGridUrl) {
public RemoteDriverManager(final URL seleniumGridUrl) {
this(seleniumGridUrl, EnvironmentConfigurationManager.INSTANCE.get().httpProxyUrl());
}

/**
* Constructs a new RemoteDriverManager pointed at the provided selenium grid
*
* @param seleniumGridUrl The URL of the selenium grid
* @param httpProxyUrl The URL of the http proxy
*/
public RemoteDriverManager(
final @NonNull URL seleniumGridUrl, final @Nullable String httpProxyUrl) {
super(EnvironmentConfigurationManager.INSTANCE.get().driverRetryCount());
this.seleniumGridUrl = seleniumGridUrl;
this.httpProxyUrl = httpProxyUrl;
}

@Override
Expand All @@ -59,15 +74,17 @@ protected WebDriver createDriver(final EnhancedCapabilities driverConfig) {
Optional.ofNullable(driverConfig.getApplauseOptions().getOsName())
.map(os -> os.toUpperCase(Locale.US))
.orElse("");
final var config =
var config =
ClientConfig.defaultConfig()
.readTimeout(
Duration.ofMinutes(
EnvironmentConfigurationManager.INSTANCE.get().seleniumReadTimeoutMinutes()))
.proxy(
ConfigUtils.getHttpProxy(
EnvironmentConfigurationManager.INSTANCE.get().httpProxyUrl()))
.baseUrl(seleniumGridUrl);

// If we have an http proxy, set it on the ClientConfig
if (Strings.isNotBlank(this.httpProxyUrl)) {
config = config.proxy(ConfigUtils.getHttpProxy(this.httpProxyUrl));
}
return switch (type) {
case "ANDROID" -> new AndroidDriver(AppiumClientConfig.fromClientConfig(config), caps);
case "IOS" -> new IOSDriver(AppiumClientConfig.fromClientConfig(config), caps);
Expand Down

0 comments on commit 088cfa0

Please sign in to comment.