-
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 improve support of driver arguments
- Loading branch information
1 parent
3a0766f
commit 83dd7cb
Showing
4 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...com/xceptance/neodymium/module/statement/browser/multibrowser/wrappers/ChromeBuilder.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.xceptance.neodymium.module.statement.browser.multibrowser.wrappers; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.openqa.selenium.chrome.ChromeDriverService; | ||
import org.openqa.selenium.chrome.ChromeDriverService.Builder; | ||
import org.openqa.selenium.net.PortProber; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
public class ChromeBuilder extends Builder | ||
{ | ||
private File firefoxBinary; | ||
|
||
private int port; | ||
|
||
private List<String> arguments; | ||
|
||
public ChromeDriverService createDriverService(List<String> arguments) | ||
{ | ||
firefoxBinary = findDefaultExecutable(); | ||
port = PortProber.findFreePort(); | ||
this.arguments = arguments; | ||
try | ||
{ | ||
return new ChromeDriverService(firefoxBinary, port, createArgs(), ImmutableMap.copyOf(System.getenv())); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
protected ImmutableList<String> createArgs() | ||
{ | ||
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder(); | ||
argsBuilder.addAll(super.createArgs()); | ||
argsBuilder.add(String.format("--port=%d", port)); | ||
if (firefoxBinary != null) | ||
{ | ||
argsBuilder.add("-b"); | ||
argsBuilder.add(firefoxBinary.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(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
.../com/xceptance/neodymium/module/statement/browser/multibrowser/wrappers/GeckoBuilder.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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.xceptance.neodymium.module.statement.browser.multibrowser.wrappers; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.openqa.selenium.firefox.GeckoDriverService; | ||
import org.openqa.selenium.firefox.GeckoDriverService.Builder; | ||
import org.openqa.selenium.net.PortProber; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.io.ByteStreams; | ||
|
||
public class GeckoBuilder extends Builder | ||
{ | ||
private File firefoxBinary; | ||
|
||
private int port; | ||
|
||
private List<String> arguments; | ||
|
||
public GeckoDriverService createDriverService(List<String> arguments) | ||
{ | ||
firefoxBinary = findDefaultExecutable(); | ||
port = PortProber.findFreePort(); | ||
this.arguments = arguments; | ||
var logPathArgs = arguments.stream().filter(arg -> arg.contains("--log-path")).collect(Collectors.toList()); | ||
this.arguments.removeAll(logPathArgs); | ||
var service = createDriverService(firefoxBinary, port, createArgs(), ImmutableMap.copyOf(System.getenv())); | ||
|
||
if (!logPathArgs.isEmpty()) | ||
{ | ||
String firefoxLogFile = logPathArgs.get(0).replaceAll("--log-path=", "").trim(); | ||
if (firefoxLogFile != null) | ||
{ | ||
if ("/dev/stdout".equals(firefoxLogFile)) | ||
{ | ||
service.sendOutputTo(System.out); | ||
} | ||
else if ("/dev/stderr".equals(firefoxLogFile)) | ||
{ | ||
service.sendOutputTo(System.err); | ||
} | ||
else if ("/dev/null".equals(firefoxLogFile)) | ||
{ | ||
service.sendOutputTo(ByteStreams.nullOutputStream()); | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
service.sendOutputTo(new FileOutputStream(firefoxLogFile)); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
return service; | ||
} | ||
|
||
@Override | ||
protected ImmutableList<String> createArgs() | ||
{ | ||
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder(); | ||
// argsBuilder.addAll(super.createArgs()); | ||
argsBuilder.add(String.format("--port=%d", port)); | ||
if (firefoxBinary != null) | ||
{ | ||
argsBuilder.add("-b"); | ||
argsBuilder.add(firefoxBinary.getPath()); | ||
} // else GeckoDriver will be responsible for finding Firefox on the PATH or via a capability. | ||
if (arguments != null && !arguments.isEmpty()) | ||
{ | ||
argsBuilder.addAll(arguments); | ||
} | ||
return argsBuilder.build(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...ava/com/xceptance/neodymium/module/statement/browser/multibrowser/wrappers/IEBuilder.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.xceptance.neodymium.module.statement.browser.multibrowser.wrappers; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
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 firefoxBinary; | ||
|
||
private int port; | ||
|
||
private List<String> arguments; | ||
|
||
public InternetExplorerDriverService createDriverService(List<String> arguments) | ||
{ | ||
firefoxBinary = findDefaultExecutable(); | ||
port = PortProber.findFreePort(); | ||
this.arguments = arguments; | ||
try | ||
{ | ||
return createDriverService(firefoxBinary, port, createArgs(), ImmutableMap.copyOf(System.getenv())); | ||
} | ||
catch (WebDriverException e) | ||
{ | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
protected ImmutableList<String> createArgs() | ||
{ | ||
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder(); | ||
argsBuilder.addAll(super.createArgs()); | ||
argsBuilder.add(String.format("--port=%d", port)); | ||
if (firefoxBinary != null) | ||
{ | ||
argsBuilder.add("-b"); | ||
argsBuilder.add(firefoxBinary.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(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...com/xceptance/neodymium/module/statement/browser/multibrowser/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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.xceptance.neodymium.module.statement.browser.multibrowser.wrappers; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
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 firefoxBinary; | ||
|
||
private int port; | ||
|
||
private List<String> arguments; | ||
|
||
public SafariDriverService createDriverService(List<String> arguments) | ||
{ | ||
firefoxBinary = findDefaultExecutable(); | ||
port = PortProber.findFreePort(); | ||
this.arguments = arguments; | ||
return createDriverService(firefoxBinary, port, 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 (firefoxBinary != null) | ||
{ | ||
argsBuilder.add("-b"); | ||
argsBuilder.add(firefoxBinary.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(); | ||
} | ||
} |