Example usage for org.openqa.selenium.remote HttpCommandExecutor HttpCommandExecutor

List of usage examples for org.openqa.selenium.remote HttpCommandExecutor HttpCommandExecutor

Introduction

In this page you can find the example usage for org.openqa.selenium.remote HttpCommandExecutor HttpCommandExecutor.

Prototype

public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addressOfRemoteServer,
            HttpClient.Factory httpClientFactory) 

Source Link

Usage

From source file:com.stratio.qa.specs.HookGSpec.java

License:Apache License

/**
 * Connect to selenium.//from   ww  w  .  j a  va2  s  . c om
 *
 * @throws MalformedURLException
 */
@Before(order = ORDER_10, value = { "@mobile,@web" })
public void seleniumSetup() throws MalformedURLException {
    String grid = System.getProperty("SELENIUM_GRID");
    if (grid == null) {
        fail("Selenium grid not available");
    }
    String b = ThreadProperty.get("browser");

    if ("".equals(b)) {
        fail("Non available browsers");
    }

    String browser = b.split("_")[0];
    String version = b.split("_")[1];
    commonspec.setBrowserName(browser);
    commonspec.getLogger().debug("Setting up selenium for {}", browser);

    DesiredCapabilities capabilities = null;

    switch (browser.toLowerCase()) {
    case "chrome":
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--ignore-certificate-errors");
        capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        break;
    case "firefox":
        capabilities = DesiredCapabilities.firefox();
        break;
    case "phantomjs":
        capabilities = DesiredCapabilities.phantomjs();
        break;
    case "iphone":
    case "safari":
        capabilities = DesiredCapabilities.iphone();
        capabilities.setCapability("platformName", "iOS");
        capabilities.setCapability("platformVersion", "8.1");
        capabilities.setCapability("deviceName", "iPhone Simulator");
        break;
    case "android":
        capabilities = DesiredCapabilities.android();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "6.0");
        capabilities.setCapability("deviceName", "Android Emulator");
        capabilities.setCapability("app", "Browser");
        break;
    default:
        commonspec.getLogger().error("Unknown browser: " + browser);
        throw new SeleniumException("Unknown browser: " + browser);
    }

    capabilities.setVersion(version);

    grid = "http://" + grid + "/wd/hub";
    HttpClient.Factory factory = new ApacheHttpClient.Factory(new HttpClientFactory(60000, 60000));
    HttpCommandExecutor executor = new HttpCommandExecutor(new HashMap<String, CommandInfo>(), new URL(grid),
            factory);
    commonspec.setDriver(new RemoteWebDriver(executor, capabilities));
    commonspec.getDriver().manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
    commonspec.getDriver().manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS);
    commonspec.getDriver().manage().timeouts().setScriptTimeout(SCRIPT_TIMEOUT, TimeUnit.SECONDS);

    commonspec.getDriver().manage().deleteAllCookies();
    if (capabilities.getCapability("deviceName") == null) {
        commonspec.getDriver().manage().window().setSize(new Dimension(1440, 900));
    }
    commonspec.getDriver().manage().window().maximize();

}