package com.wiley.driver.factory;

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

import java.net.MalformedURLException;
import java.net.URL;

public class TeasyDriver {

    public TeasyDriver() {
    }

    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.merge(extraCaps), isHeadless, gridUrl);
        } else {
            driverFactory = new StandaloneDriverFactory(Configuration.browser, Configuration.platform, Configuration.customCaps.merge(extraCaps), isHeadless, gridUrl);
        }

        return driverFactory.get();
    }

    private URL getGridHubUrl() {
        URL url;
        try {
            url = new URL(Configuration.gridHubUrl);
        } catch (MalformedURLException e) {
            throw new RuntimeException("Error during gridhuburl creation. For url " + Configuration.gridHubUrl);
        }
        return url;
    }
}

@@ -604,32 +604,48 @@
 ation.platform, 
+extraCaps.merge(
 Configuration.cu
@@ -652,32 +652,16 @@
 stomCaps
-.merge(extraCaps
 ), isHea
@@ -797,16 +797,32 @@
 atform, 
+extraCaps.merge(
 Configur
@@ -841,24 +841,8 @@
 Caps
-.merge(extraCaps
 ), i

fix - customCaps from Configuration should not be changed