package twzip.context;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.safari.SafariDriver;

/**
 *
 * @author Kent Yeh
 */
public class WebDriverFactory {

    public static enum Brwoser {

        FIREFOX,
        CHROME,
        SAFARI,
        IE,
        HTMLUNIT,
    }

    public static WebDriver getInstance() {
        return getInstance(Brwoser.HTMLUNIT);
    }

    public static WebDriver getInstance(Brwoser browser, long implicitlyWaitSecs) {
        WebDriver driver = getInstance(browser);
        driver.manage().timeouts().implicitlyWait(implicitlyWaitSecs, TimeUnit.SECONDS);
        return driver;
    }
    
    public static WebDriver getInstance(Brwoser browser) {
        switch (browser) {
            case FIREFOX:
                DesiredCapabilities fc = DesiredCapabilities.firefox();
                fc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                return new FirefoxDriver(fc);
            case CHROME:
                DesiredCapabilities cc = DesiredCapabilities.chrome();
                cc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                return new ChromeDriver(cc);
            case SAFARI:
                DesiredCapabilities cs = DesiredCapabilities.safari();
                cs.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                return new SafariDriver(cs);
            case IE:
                DesiredCapabilities ci = DesiredCapabilities.internetExplorer();
                ci.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                return new SafariDriver(ci);
            default:
                DesiredCapabilities ch = DesiredCapabilities.htmlUnit();
                ch.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                return new HtmlUnitDriver(ch);
        }
    }
}

@@ -172,29 +172,129 @@
 ium.
-firefox.FirefoxDriver
+chrome.ChromeOptions;%0Aimport org.openqa.selenium.firefox.FirefoxDriver;%0Aimport org.openqa.selenium.firefox.FirefoxOptions
 ;%0Aim
@@ -495,16 +495,205 @@
 iDriver;
+%0Aimport org.openqa.selenium.safari.SafariOptions;%0Aimport org.openqa.selenium.edge.EdgeDriver;%0Aimport org.openqa.selenium.edge.EdgeOptions;%0Aimport org.openqa.selenium.firefox.FirefoxProfile;
 %0A%0A/**%0A *
@@ -841,17 +841,19 @@
         
-I
+EDG
 E,%0A     
@@ -1220,20 +1220,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -1353,134 +1353,375 @@
     
-DesiredCapabilities fc = DesiredCapabilities.firefox();%0A                fc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true
+FirefoxProfile firefoxProfile = new FirefoxProfile();%0A                firefoxProfile.setPreference(%22media.navigator.streams.fake%22, true);%0A                FirefoxOptions ffOptions = new FirefoxOptions();%0A                ffOptions.setProfile(firefoxProfile);%0A                ffOptions.setAcceptInsecureCerts(true);%0A                ffOptions.setBinary(%22/usr/bin/firefox%22
 );%0A 
@@ -1761,17 +1761,24 @@
 Driver(f
-c
+fOptions
 );%0A     
@@ -1817,133 +1817,314 @@
     
-DesiredCapabilities cc = DesiredCapabilities.chrome();%0A                cc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true
+ChromeOptions cOptions = new ChromeOptions();%0A                cOptions.setAcceptInsecureCerts(true);%0A                cOptions.setBinary(%22/usr/bin/google-chrome%22);%0A                cOptions.addArguments(%22use-fake-ui-for-media-stream%22);%0A                cOptions.addArguments(%22use-fake-device-for-media-stream%22
 );%0A 
@@ -2163,17 +2163,23 @@
 Driver(c
-c
+Options
 );%0A     
@@ -2350,38 +2350,56 @@
                 
-return
+SafariOptions sOptions =
  new SafariDrive
@@ -2393,22 +2393,23 @@
 w Safari
-Driver
+Options
 (cs);%0A  
@@ -2422,94 +2422,297 @@
     
-case IE:%0A                DesiredCapabilities ci = DesiredCapabilities.internetExplorer
+    sOptions.setCapability(%22autoclose%22, true);%0A                sOptions.setCapability(%22headless%22, true);%0A                sOptions.setUseTechnologyPreview(true);%0A                return new SafariDriver(sOptions);%0A            case EDGE:%0A                EdgeOptions eOptions = new EdgeOptions
 ();%0A
@@ -2727,18 +2727,24 @@
         
-ci
+eOptions
 .setCapa
@@ -2782,32 +2782,209 @@
 L_CERTS, true);%0A
+                eOptions.setCapability(%22autoclose%22, true);%0A                eOptions.setCapability(%22headless%22, true);%0A                eOptions.setCapability(%22avoidProxy%22, true);%0A
                 
@@ -2998,23 +2998,27 @@
 new 
-Safari
+Edge
 Driver(
-ci
+eOptions
 );%0A 

修改deprecated webdriver