Skip to content

Commit

Permalink
[#198] implement passing driver arguments for safari
Browse files Browse the repository at this point in the history
  • Loading branch information
oomelianchuk committed Sep 5, 2024
1 parent 2403bf5 commit 7ccb1dd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,18 @@ else if (internetExplorerBrowsers.contains(browserName))
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));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,35 @@
package com.xceptance.neodymium.common.browser.wrappers;

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

import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.safari.SafariDriverService;
import org.openqa.selenium.safari.SafariDriverService.Builder;

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

public class SafariBuilder extends Builder
{
private File safariBinary;

private int port;

private List<String> arguments;

public SafariDriverService createDriverService(List<String> arguments)
{
// safariBinary = findDefaultExecutable();
port = PortProber.findFreePort();
this.arguments = arguments;
return createDriverService(null, port, getDefaultTimeout(), createArgs(), ImmutableMap.copyOf(System.getenv()));
}

@Override
protected ImmutableList<String> createArgs()
{
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder();
argsBuilder.addAll(super.createArgs());
argsBuilder.add(String.format("--port=%d", port));
if (safariBinary != null)
{
argsBuilder.add("-b");
argsBuilder.add(safariBinary.getPath());
} // else GeckoDriver will be responsible for finding Firefox on the PATH or via a capability.
if (arguments != null)
{
argsBuilder.addAll(arguments);
}
return argsBuilder.build();
}
public class SafariBuilder extends Builder {
private List<String> arguments;

public SafariBuilder(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=", "")));
this.arguments.removeAll(portArgs);
}
List<String> diagnose = this.arguments.stream().filter(arg -> arg.contains("--diagnose"))
.collect(Collectors.toList());
if (!diagnose.isEmpty()) {
withLogging(true);
this.arguments.removeAll(diagnose);
}
}
}

@Override
protected List<String> createArgs() {
List<String> args = super.createArgs();
args.addAll(arguments);
return args;
}
}

0 comments on commit 7ccb1dd

Please sign in to comment.