-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#198] implement passing driver arguments for safari
- Loading branch information
1 parent
2403bf5
commit 7ccb1dd
Showing
2 changed files
with
40 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 28 additions & 39 deletions
67
src/main/java/com/xceptance/neodymium/common/browser/wrappers/SafariBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |