Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add proxy url to the RemoteWebDriver if the proxy url is not blank #31

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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