SHARE
TWEET

Untitled

a guest Jun 2nd, 2017 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void main(final String[] args) {
  2.     final EBrowser browser = EBrowser.FIREFOX;
  3.     final String pathToDriver = "/home/zabuza/Programme/driver/geckodriver";
  4.     final String pathToBinary = "/usr/lib/firefox-esr/firefox-bin";
  5.     final DesiredCapabilities capabilities = api.createCapabilities(browser, pathToDriver, pathToBinary, null);
  6.  
  7.     final WebDriver driver = new FirefoxDriver(capabilities);
  8.     // Do something with the driver
  9. }
  10.  
  11. public DesiredCapabilities createCapabilities(final EBrowser browser, final String driverPath,
  12.             final String binaryPath, final String userProfile) {
  13.         DesiredCapabilities capabilities = null;
  14.  
  15.         if (browser == EBrowser.FIREFOX) {
  16.             capabilities = DesiredCapabilities.firefox();
  17.             final FirefoxOptions options = new FirefoxOptions();
  18.  
  19.             // Set the driver
  20.             if (driverPath != null) {
  21.                 System.setProperty("webdriver.gecko.driver", driverPath);
  22.                 System.setProperty("webdriver.firefox.marionette", driverPath);
  23.                 capabilities.setCapability(FirefoxDriver.MARIONETTE, true);
  24.             }
  25.  
  26.             // Set the binary
  27.             if (binaryPath != null) {
  28.                 final File pathToBinary = new File(binaryPath);
  29.                 final FirefoxBinary binary = new FirefoxBinary(pathToBinary);
  30.                 options.setBinary(binary);
  31.             }
  32.  
  33.             // Set the user profile
  34.             if (userProfile != null) {
  35.                 final FirefoxProfile profile = new ProfilesIni().getProfile(userProfile);
  36.                 options.setProfile(profile);
  37.             }
  38.  
  39.             options.addTo(capabilities);
  40.         } else if (browser == EBrowser.CHROME) {
  41.             capabilities = DesiredCapabilities.chrome();
  42.             final ChromeOptions options = new ChromeOptions();
  43.  
  44.             // Set the driver
  45.             if (driverPath != null) {
  46.                 System.setProperty("webdriver.chrome.driver", driverPath);
  47.             }
  48.  
  49.             // Set the binary
  50.             if (binaryPath != null) {
  51.                 options.setBinary(binaryPath);
  52.             }
  53.  
  54.             // Set the user profile
  55.             if (userProfile != null) {
  56.                 options.addArguments("user-data-dir=" + userProfile);
  57.             }
  58.             options.addArguments("disable-infobars");
  59.  
  60.             capabilities.setCapability(ChromeOptions.CAPABILITY, options);
  61.         } else if (browser == EBrowser.SAFARI) {
  62.             capabilities = DesiredCapabilities.internetExplorer();
  63.  
  64.             // Set the driver
  65.             if (driverPath != null) {
  66.                 System.setProperty("webdriver.safari.driver", driverPath);
  67.             }
  68.  
  69.             // Set the binary
  70.             if (binaryPath != null) {
  71.                 capabilities.setCapability("safari.binary", binaryPath);
  72.             }
  73.         } else if (browser == EBrowser.INTERNET_EXPLORER) {
  74.             capabilities = DesiredCapabilities.internetExplorer();
  75.  
  76.             // Set the driver
  77.             if (driverPath != null) {
  78.                 System.setProperty("webdriver.ie.driver", driverPath);
  79.             }
  80.  
  81.             // Set the binary
  82.             if (binaryPath != null) {
  83.                 capabilities.setCapability("ie.binary", binaryPath);
  84.             }
  85.         } else if (browser == EBrowser.OPERA) {
  86.             capabilities = DesiredCapabilities.internetExplorer();
  87.  
  88.             // Set the driver
  89.             if (driverPath != null) {
  90.                 System.setProperty("webdriver.opera.driver", driverPath);
  91.             }
  92.  
  93.             // Set the binary
  94.             if (binaryPath != null) {
  95.                 capabilities.setCapability("opera.binary", binaryPath);
  96.             }
  97.  
  98.             // Set the user profile
  99.             if (userProfile != null) {
  100.                 capabilities.setCapability("opera.profile", userProfile);
  101.             }
  102.         } else if (browser == EBrowser.MS_EDGE) {
  103.             capabilities = DesiredCapabilities.internetExplorer();
  104.  
  105.             // Set the driver
  106.             if (driverPath != null) {
  107.                 System.setProperty("webdriver.edge.driver", driverPath);
  108.             }
  109.  
  110.             // Set the binary
  111.             if (binaryPath != null) {
  112.                 capabilities.setCapability("edge.binary", binaryPath);
  113.             }
  114.         } else {
  115.             throw new IllegalArgumentException("The given browser is not supported: " + browser);
  116.         }
  117.  
  118.         return capabilities;
  119.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top