Skip to content

Commit

Permalink
Merge pull request #205 from Kgalkin/master
Browse files Browse the repository at this point in the history
add ability to config browser for every test
  • Loading branch information
vefimofff committed Sep 6, 2019
2 parents 2d4b3e8 + 3e182d0 commit 1bd1c92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/main/java/com/wiley/driver/WebDriverFactory.java
Expand Up @@ -12,11 +12,13 @@
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;

import java.net.InetAddress;
import java.net.URL;
import java.util.Collections;

import static com.wiley.holders.DriverHolder.getDriver;

Expand All @@ -31,14 +33,14 @@ public class WebDriverFactory {
private static final ThreadLocal<Integer> tryToCreateDriverCount = ThreadLocal.withInitial(() -> START_COUNT);
private static final ThreadLocal<Integer> restartDriverAfterNumberOfTests = ThreadLocal.withInitial(() -> START_COUNT);

public static void initDriver() {
public static void initDriver(DesiredCapabilities extraCaps) {
restartDriverAfterNumberOfTests.set(restartDriverAfterNumberOfTests.get() + 1);
if (getDriver() != null && (isBrowserDead() || isNeedToRestartDriver())) {
quitWebDriver();
}
if (getDriver() == null) {
try {
FramesTransparentWebDriver driver = createDriver();
FramesTransparentWebDriver driver = createDriver(extraCaps);

addShutdownHook(driver);

Expand All @@ -50,10 +52,13 @@ public static void initDriver() {
}
}
}
public static void initDriver(){
initDriver(new DesiredCapabilities());
}

private static FramesTransparentWebDriver createDriver() {
private static FramesTransparentWebDriver createDriver(DesiredCapabilities extraCaps) {
TeasyDriver teasyDriver = new TeasyDriver();
return new FramesTransparentWebDriver(teasyDriver.init());
return new FramesTransparentWebDriver(teasyDriver.init(extraCaps));
}

private static void lastTryToCreateDriver(Throwable t) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/wiley/driver/factory/TeasyDriver.java
Expand Up @@ -2,6 +2,7 @@

import com.wiley.config.Configuration;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -11,14 +12,14 @@ public class TeasyDriver {
public TeasyDriver() {
}

public WebDriver init() {
public WebDriver init(DesiredCapabilities extraCaps) {
DriverFactory driverFactory;
URL gridUrl = getGridHubUrl();
boolean isHeadless = Configuration.headless;
if (Configuration.runWithGrid) {
driverFactory = new RemoteDriverFactory(Configuration.browser, Configuration.platform, Configuration.customCaps, isHeadless, gridUrl);
driverFactory = new RemoteDriverFactory(Configuration.browser, Configuration.platform, Configuration.customCaps.merge(extraCaps), isHeadless, gridUrl);
} else {
driverFactory = new StandaloneDriverFactory(Configuration.browser, Configuration.platform, Configuration.customCaps, isHeadless, gridUrl);
driverFactory = new StandaloneDriverFactory(Configuration.browser, Configuration.platform, Configuration.customCaps.merge(extraCaps), isHeadless, gridUrl);
}

return driverFactory.get();
Expand Down

0 comments on commit 1bd1c92

Please sign in to comment.