All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.testvagrant.optimus.core.web.ChromeDriverManager Maven / Gradle / Ivy

Go to download

Optimus Lite API to manage test devices and create appium driver based on platform

There is a newer version: 0.1.7-beta
Show newest version
package com.testvagrant.optimus.core.web;

import com.testvagrant.optimus.core.parser.WebTestFeedParser;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;
import java.util.List;
import java.util.Map;

class ChromeDriverManager {

  private final ChromeOptions chromeOptions;

  public ChromeDriverManager(WebTestFeedParser testFeedParser) {
    this.chromeOptions = buildChromeOptions(testFeedParser);
  }

  public WebDriver createDriver() {
    WebDriverManager.chromedriver().setup();
    return new ChromeDriver(chromeOptions);
  }

  private ChromeOptions buildChromeOptions(WebTestFeedParser testFeedParser) {
    List arguments = testFeedParser.getArguments();
    List extensions = testFeedParser.getExtensions();
    Map preferences = testFeedParser.getPreferences();
    Map experimentalOptions = testFeedParser.getExperimentalOptions();
    DesiredCapabilities desiredCapabilities = testFeedParser.getDesiredCapabilities();

    ChromeOptions options = new ChromeOptions();

    if (arguments.size() > 0) options.addArguments(arguments);

    if (extensions.size() > 0) {
      extensions.forEach(extensionPath -> options.addExtensions(new File(extensionPath)));
    }

    if (preferences.keySet().size() > 0) {
      options.setExperimentalOption("prefs", preferences);
    }

    if (experimentalOptions.keySet().size() > 0) {
      experimentalOptions.forEach(options::setExperimentalOption);
    }

    options.merge(desiredCapabilities);
    return options;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy