Skip to content

Commit

Permalink
[#198] support driver args for edge
Browse files Browse the repository at this point in the history
  • Loading branch information
oomelianchuk committed Sep 11, 2024
1 parent 7ccb1dd commit 2853495
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public BrowserData()
private void populateBrowserDataWithGlobalInformation()
{
final String ieDriverPath = Neodymium.configuration().getIeDriverPath();
final String edgeDriverPath = Neodymium.configuration().getEdgeDriverPath();
final String chromeDriverPath = Neodymium.configuration().getChromeDriverPath();
final String geckoDriverPath = Neodymium.configuration().getFirefoxDriverPath();

Expand All @@ -131,6 +132,10 @@ private void populateBrowserDataWithGlobalInformation()
{
System.setProperty("webdriver.gecko.driver", geckoDriverPath);
}
if (!StringUtils.isEmpty(edgeDriverPath))
{
System.setProperty("webdriver.edge.driver", edgeDriverPath);
}

// TODO: do we need a possibility to define browser tags globaly via system var? Is this opportunity documented?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerDriverService;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.safari.SafariDriverService;
import org.openqa.selenium.safari.SafariOptions;
import org.openqa.selenium.support.events.EventFiringDecorator;

Expand All @@ -59,6 +59,7 @@
import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.common.browser.configuration.TestEnvironment;
import com.xceptance.neodymium.common.browser.wrappers.ChromeBuilder;
import com.xceptance.neodymium.common.browser.wrappers.EdgeBuilder;
import com.xceptance.neodymium.common.browser.wrappers.GeckoBuilder;
import com.xceptance.neodymium.common.browser.wrappers.IEBuilder;
import com.xceptance.neodymium.common.browser.wrappers.SafariBuilder;
Expand All @@ -84,6 +85,8 @@ public final class BrowserRunnerHelper

private static List<String> internetExplorerBrowsers = new LinkedList<String>();

private static List<String> edgeBrowsers = new LinkedList<String>();

private static List<String> safariBrowsers = new LinkedList<String>();

private final static Object mutex = new Object();
Expand All @@ -95,7 +98,7 @@ public final class BrowserRunnerHelper
firefoxBrowsers.add(FIREFOX.browserName());

internetExplorerBrowsers.add(IE.browserName());
internetExplorerBrowsers.add(EDGE.browserName());
edgeBrowsers.add(EDGE.browserName());

safariBrowsers.add(SAFARI.browserName());
}
Expand Down Expand Up @@ -320,32 +323,36 @@ else if (internetExplorerBrowsers.contains(browserName))
options.addCommandSwitches(argument);
}
}
InternetExplorerDriverService defaultServer = new IEBuilder().createDriverService(config.getDriverArguments());
if (defaultServer != null)
{
wDSC.setWebDriver(new InternetExplorerDriver(defaultServer, options));
}
else
wDSC.setWebDriver(new InternetExplorerDriver(new IEBuilder(config.getDriverArguments())
.build(), options));
}
else if (edgeBrowsers.contains(browserName))
{
final EdgeOptions options = new EdgeOptions().merge(capabilities);
if (config.getArguments() != null && config.getArguments().size() > 0)
{
wDSC.setWebDriver(new InternetExplorerDriver(options));
options.addArguments(config.getArguments());
}
wDSC.setWebDriver(new InternetExplorerDriver(options));
wDSC.setWebDriver(new EdgeDriver(options));
wDSC.setWebDriver(new EdgeDriver(new EdgeBuilder(config.getDriverArguments())
.build(), options));
}
else if (safariBrowsers.contains(browserName))
{
final SafariOptions options = (SafariOptions) capabilities;
// SafariDriverService defaultServer = new SafariBuilder().createDriverService(config.getDriverArguments());
//
// if (defaultServer != null)
// {
// wDSC.setWebDriver(new SafariDriver(defaultServer, options));
// }
// else
// {
// wDSC.setWebDriver(new SafariDriver(options));
// }
// SafariDriverService defaultServer = new
// SafariBuilder().createDriverService(config.getDriverArguments());
//
// if (defaultServer != null)
// {
// wDSC.setWebDriver(new SafariDriver(defaultServer, options));
// }
// else
// {
// wDSC.setWebDriver(new SafariDriver(options));
// }
wDSC.setWebDriver(new SafariDriver(new SafariBuilder(config.getDriverArguments())
.build(), options));
.build(), options));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.xceptance.neodymium.common.browser.wrappers;

import java.util.List;
import java.util.stream.Collectors;

import org.openqa.selenium.edge.EdgeDriverService.Builder;

import com.google.common.collect.ImmutableList;

public class EdgeBuilder extends Builder
{
private List<String> arguments;

public EdgeBuilder(List<String> args)
{
this.arguments = args;
if (this.arguments != null && !this.arguments.isEmpty())
{
List<String> portArgs = this.arguments.stream().filter(arg -> arg.contains("--port=")).collect(Collectors.toList());
if (!portArgs.isEmpty())
{
usingPort(Integer.parseInt(portArgs.get(portArgs.size() - 1).replace("--port=", "")));
arguments.removeAll(portArgs);
}
}
}

@Override
protected ImmutableList<String> createArgs()
{
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder();
argsBuilder.addAll(super.createArgs());
if (arguments != null)
{
argsBuilder.addAll(arguments);
}
return argsBuilder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class GeckoBuilder extends Builder
public GeckoBuilder(List<String> args)
{
this.arguments = args;
System.out.println(args);
if (this.arguments != null && !this.arguments.isEmpty())
{
List<String> logPaths = arguments.stream().filter(arg -> arg.contains("--log-path=")).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
package com.xceptance.neodymium.common.browser.wrappers;

import java.io.File;
import java.util.List;
import java.util.stream.Collectors;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.ie.InternetExplorerDriverService;
import org.openqa.selenium.ie.InternetExplorerDriverService.Builder;
import org.openqa.selenium.net.PortProber;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

public class IEBuilder extends Builder
{
private File ieBinary;

private int port;

private List<String> arguments;

public InternetExplorerDriverService createDriverService(List<String> arguments)
public IEBuilder(List<String> args)
{
// ieBinary = findDefaultExecutable();
port = PortProber.findFreePort();
this.arguments = arguments;
try
this.arguments = args;
if (this.arguments != null && !this.arguments.isEmpty())
{
return createDriverService(null, port, getDefaultTimeout(), createArgs(), ImmutableMap.copyOf(System.getenv()));
}
catch (WebDriverException e)
{
throw new RuntimeException("Could not create IE driver instance", e);
List<String> portArgs = this.arguments.stream().filter(arg -> arg.contains("--port=")).collect(Collectors.toList());
if (!portArgs.isEmpty())
{
usingPort(Integer.parseInt(portArgs.get(portArgs.size() - 1).replace("--port=", "")));
arguments.removeAll(portArgs);
}
}
}

Expand All @@ -39,12 +30,6 @@ protected ImmutableList<String> createArgs()
{
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder();
argsBuilder.addAll(super.createArgs());
argsBuilder.add(String.format("--port=%d", port));
if (ieBinary != null)
{
argsBuilder.add("-b");
argsBuilder.add(ieBinary.getPath());
} // else GeckoDriver will be responsible for finding Firefox on the PATH or via a capability.
if (arguments != null)
{
argsBuilder.addAll(arguments);
Expand Down

0 comments on commit 2853495

Please sign in to comment.