Skip to content

Commit

Permalink
#198 improve support of driver arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
oomelianchuk committed Sep 6, 2021
1 parent 3a0766f commit 83dd7cb
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 0 deletions.
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();
}
}
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();
}
}
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();
}
}
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();
}
}

0 comments on commit 83dd7cb

Please sign in to comment.