@Override
    public DesiredCapabilities createCapabilities(Map<String, String> options) throws Exception {

        ClientProperties properties = new ClientProperties(options);

        final String browser = properties.getBrowser();

        if (properties.isUseGrid()) {
            DesiredCapabilities capabilities = null;

            if (properties.getGridUrl().length() == 0) {
                throw new Exception(
                        "You must provide 'grid.url' to use Selenium Grid in client property file");
            }
            if (browser.length() == 0) {
                throw new Exception(
                        "You must provide 'browser' to use Selenium Grid  in client property file");
            }
            if (properties.getGridPlatform().length() == 0) {
                throw new Exception(
                        "You must provide 'grid.platform' to use Selenium Grid in client property file");
            }

            if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore")
                    || browser.equalsIgnoreCase("*iexplore")
            		|| browser.equalsIgnoreCase("internet explorer")) {
                capabilities = DesiredCapabilities.internetExplorer();
            } else if ((browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("*firefox"))) {
                capabilities = DesiredCapabilities.firefox();
            } else if (browser.equalsIgnoreCase("chrome")) {
                capabilities = DesiredCapabilities.chrome();
            } else if (browser.equalsIgnoreCase("safari")) {
                capabilities = DesiredCapabilities.safari();
            } else if (browser.equalsIgnoreCase("opera")) {
                capabilities = DesiredCapabilities.opera();
            } else if (browser.equalsIgnoreCase("android")) {
                capabilities = DesiredCapabilities.android();
            } else if (browser.equalsIgnoreCase("ipad")) {
                capabilities = DesiredCapabilities.ipad();
            } else if (browser.equalsIgnoreCase("iphone")) {
                capabilities = DesiredCapabilities.iphone();
            } else if (browser.equalsIgnoreCase("MS Edge") || browser.equalsIgnoreCase("MicrosoftEdge")) {
            	capabilities = DesiredCapabilities.edge();
			} else {
                throw new Exception("Unsupported browser: " + browser
                        + " Please refer to documentation for supported browsers.");
            }

            capabilities.setVersion(properties.getBrowserVersion());

            String platform = properties.getGridPlatform();
            if (platform != null && platform.length() > 0) {
                capabilities.setCapability("platform", platform);
            } else {
                // Default to Windows 7
                capabilities.setCapability("platform", "Windows 7");
            }

            String sauceFile = properties.getGridSaucefile() ;
            if (sauceFile != null && sauceFile.length() > 0) {
                Map<String,String> sOptions = new HashMap<String,String>();
                sOptions.put("executable", "sauce-storage:" + sauceFile );
                sOptions.put("args", "[ '--silent', '-a', '-q' ]");
                sOptions.put("background", "true");
                 
                capabilities.setCapability("prerun",sOptions);
            	
            }
            
            String tunnelIdentifier = properties.getTunnelIdentifier();
            if(!Strings.isNullOrEmpty(tunnelIdentifier)) {
                capabilities.setCapability("tunnel-identifier", tunnelIdentifier);
            }
            
            // Set Proxy
            String proxyStr = properties.getProxy();
            String proxyHttps = properties.getProxyHttps();
            Proxy proxy = null;
            if (proxyStr != null && !proxyStr.equals("")) {
                proxy = new Proxy();
                proxy.setHttpProxy(proxyStr);

            }
            if (proxyHttps != null && !proxyHttps.equals("")) {
                if (proxy == null) {
                    proxy = new Proxy();
                }
                proxy.setSslProxy(proxyHttps);
            }

            if (proxy != null) {
                capabilities.setCapability(CapabilityType.PROXY, proxy);
            }

            // preparing data for session name
            String computerName = null;
            try {
                computerName = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException e) {
            }

            capabilities.setCapability("name", "JTAF EWD client=" + properties.getClient()
                    + "; started from " + computerName);

            String gridProperties = properties.getGridProperties();
            if (gridProperties != null && gridProperties.length() > 0) {
                String[] gridPropertiesSlpitted = gridProperties.split(" ");
                for (String gridPropertiesSlpittedCurrent : gridPropertiesSlpitted) {
                    if (gridPropertiesSlpittedCurrent != null
                            && gridPropertiesSlpittedCurrent.length() > 0) {
                        String[] propertyNameAndValue = gridPropertiesSlpittedCurrent.split("=");
                        if (propertyNameAndValue.length == 2) {
                            capabilities.setCapability(propertyNameAndValue[0],
                                    propertyNameAndValue[1]);
                        }
                    }
                }
            }

            return capabilities;
        } else {
            log.debug("browser [" + browser + "]");

            // Turning off all console logs using java.util.logging
            Handler[] h = java.util.logging.LogManager.getLogManager().getLogger("").getHandlers();
            for (int i = 0; i < h.length; i++) {
                if (h[i] instanceof ConsoleHandler) {
                    h[i].setLevel(Level.OFF);
                }
            }

            String proxyProperty = properties.getProxy();
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            if (proxyProperty != null) {
                Proxy proxy = new Proxy();
                proxy.setHttpProxy(proxyProperty).setFtpProxy(proxyProperty).setSslProxy(
                        proxyProperty);
                desiredCapabilities = new DesiredCapabilities();
                if (browser != null && browser.equalsIgnoreCase("chrome")) {
                    // chrome way of proxy initialization
                    desiredCapabilities.setCapability("chrome.switches", Arrays
                            .asList("--proxy-server=http://" + proxy));
                } else {
                    // ff and ie way of proxy initialization
                    desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
                }
            }

            if (properties.getDownloadFolder() != null
                    && properties.getDownloadFolder().length() > 0) {
                // '0' means to download to the desktop, '1' means to download
                // to the default "Downloads" directory, '2' means to use the
                // directory you specify in "browser.download.dir"
                desiredCapabilities.setCapability("browser.download.folderList", 2);
                desiredCapabilities.setCapability("browser.download.dir", System
                        .getProperty("user.dir")
                        + System.getProperty("file.separator") + properties.getDownloadFolder());
                desiredCapabilities
                        .setCapability(
                                "browser.helperApps.neverAsk.saveToDisk",
                                "text/csv, application/octet-stream, application/pdf, application/vnd.fdf, application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff");
                desiredCapabilities.setCapability("browser.helperApps.alwaysAsk.force", false);
                desiredCapabilities.setCapability("browser.download.manager.showWhenStarting",
                        false);
            }
            return desiredCapabilities;
        }
    }
@ Override public DesiredCapabilities createCapabilities ( Map < String , String > options ) throws Exception { ClientProperties properties = new ClientProperties ( options ) ; final String browser = properties . getBrowser ( ) ; if ( properties . isUseGrid ( ) ) { DesiredCapabilities capabilities = null ; if ( properties . getGridUrl ( ) . length ( ) == 0 ) { throw new Exception ( "You must provide 'grid.url' to use Selenium Grid in client property file" ) ; } if ( browser . length ( ) == 0 ) { throw new Exception ( "You must provide 'browser' to use Selenium Grid  in client property file" ) ; } if ( properties . getGridPlatform ( ) . length ( ) == 0 ) { throw new Exception ( "You must provide 'grid.platform' to use Selenium Grid in client property file" ) ; } if ( browser . equalsIgnoreCase ( "ie" ) || browser . equalsIgnoreCase ( "iexplore" ) || browser . equalsIgnoreCase ( "*iexplore" ) || browser . equalsIgnoreCase ( "internet explorer" ) ) { capabilities = DesiredCapabilities . internetExplorer ( ) ; } else if ( ( browser . equalsIgnoreCase ( "firefox" ) || browser . equalsIgnoreCase ( "*firefox" ) ) ) { capabilities = DesiredCapabilities . firefox ( ) ; } else if ( browser . equalsIgnoreCase ( "chrome" ) ) { capabilities = DesiredCapabilities . chrome ( ) ; } else if ( browser . equalsIgnoreCase ( "safari" ) ) { capabilities = DesiredCapabilities . safari ( ) ; } else if ( browser . equalsIgnoreCase ( "opera" ) ) { capabilities = DesiredCapabilities . opera ( ) ; } else if ( browser . equalsIgnoreCase ( "android" ) ) { capabilities = DesiredCapabilities . android ( ) ; } else if ( browser . equalsIgnoreCase ( "ipad" ) ) { capabilities = DesiredCapabilities . ipad ( ) ; } else if ( browser . equalsIgnoreCase ( "iphone" ) ) { capabilities = DesiredCapabilities . iphone ( ) ; } else if ( browser . equalsIgnoreCase ( "MS Edge" ) || browser . equalsIgnoreCase ( "MicrosoftEdge" ) ) { capabilities = DesiredCapabilities . edge ( ) ; } else { throw new Exception ( "Unsupported browser: " + browser + " Please refer to documentation for supported browsers." ) ; } capabilities . setVersion ( properties . getBrowserVersion ( ) ) ; String platform = properties . getGridPlatform ( ) ; if ( platform != null && platform . length ( ) > 0 ) { capabilities . setCapability ( "platform" , platform ) ; } else { capabilities . setCapability ( "platform" , "Windows 7" ) ; } String sauceFile = properties . getGridSaucefile ( ) ; if ( sauceFile != null && sauceFile . length ( ) > 0 ) { Map < String , String > sOptions = new HashMap < String , String > ( ) ; sOptions . put ( "executable" , "sauce-storage:" + sauceFile ) ; sOptions . put ( "args" , "[ '--silent', '-a', '-q' ]" ) ; sOptions . put ( "background" , "true" ) ; capabilities . setCapability ( "prerun" , sOptions ) ; } String tunnelIdentifier = properties . getTunnelIdentifier ( ) ; if ( ! Strings . isNullOrEmpty ( tunnelIdentifier ) ) { capabilities . setCapability ( "tunnel-identifier" , tunnelIdentifier ) ; } String proxyStr = properties . getProxy ( ) ; String proxyHttps = properties . getProxyHttps ( ) ; Proxy proxy = null ; if ( proxyStr != null && ! proxyStr . equals ( "" ) ) { proxy = new Proxy ( ) ; proxy . setHttpProxy ( proxyStr ) ; } if ( proxyHttps != null && ! proxyHttps . equals ( "" ) ) { if ( proxy == null ) { proxy = new Proxy ( ) ; } proxy . setSslProxy ( proxyHttps ) ; } if ( proxy != null ) { capabilities . setCapability ( CapabilityType . PROXY , proxy ) ; } String computerName = null ; try { computerName = InetAddress . getLocalHost ( ) . getHostName ( ) ; } catch ( UnknownHostException e ) { } capabilities . setCapability ( "name" , "JTAF EWD client=" + properties . getClient ( ) + "; started from " + computerName ) ; String gridProperties = properties . getGridProperties ( ) ; if ( gridProperties != null && gridProperties . length ( ) > 0 ) { String [ ] gridPropertiesSlpitted = gridProperties . split ( " " ) ; for ( String gridPropertiesSlpittedCurrent : gridPropertiesSlpitted ) { if ( gridPropertiesSlpittedCurrent != null && gridPropertiesSlpittedCurrent . length ( ) > 0 ) { String [ ] propertyNameAndValue = gridPropertiesSlpittedCurrent . split ( "=" ) ; if ( propertyNameAndValue . length == 2 ) { capabilities . setCapability ( propertyNameAndValue [ 0 ] , propertyNameAndValue [ 1 ] ) ; } } } } return capabilities ; } else { log . debug ( "browser [" + browser + "]" ) ; Handler [ ] h = java . util . logging . LogManager . getLogManager ( ) . getLogger ( "" ) . getHandlers ( ) ; for ( int i = 0 ; i < h . length ; i ++ ) { if ( h [ i ] instanceof ConsoleHandler ) { h [ i ] . setLevel ( Level . OFF ) ; } } String proxyProperty = properties . getProxy ( ) ; DesiredCapabilities desiredCapabilities = new DesiredCapabilities ( ) ; if ( proxyProperty != null ) { Proxy proxy = new Proxy ( ) ; proxy . setHttpProxy ( proxyProperty ) . setFtpProxy ( proxyProperty ) . setSslProxy ( proxyProperty ) ; desiredCapabilities = new DesiredCapabilities ( ) ; if ( browser != null && browser . equalsIgnoreCase ( "chrome" ) ) { desiredCapabilities . setCapability ( "chrome.switches" , Arrays . asList ( "--proxy-server=http://" + proxy ) ) ; } else { desiredCapabilities . setCapability ( CapabilityType . PROXY , proxy ) ; } } if ( properties . getDownloadFolder ( ) != null && properties . getDownloadFolder ( ) . length ( ) > 0 ) { desiredCapabilities . setCapability ( "browser.download.folderList" , 2 ) ; desiredCapabilities . setCapability ( "browser.download.dir" , System . getProperty ( "user.dir" ) + System . getProperty ( "file.separator" ) + properties . getDownloadFolder ( ) ) ; desiredCapabilities . setCapability ( "browser.helperApps.neverAsk.saveToDisk" , "text/csv, application/octet-stream, application/pdf, application/vnd.fdf, application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff" ) ; desiredCapabilities . setCapability ( "browser.helperApps.alwaysAsk.force" , false ) ; desiredCapabilities . setCapability ( "browser.download.manager.showWhenStarting" , false ) ; } return desiredCapabilities ; } }
/*
(non-Javadoc)

@see org.finra.jtaf.ewd.session.SessionFactory