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

io.tromba.testdriver.core.WebDriverFactory Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package io.tromba.testdriver.core;

import io.tromba.testdriver.utils.TestdriverConfig;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Factory for WebDrivers.
 */
public class WebDriverFactory {

    private static final TestdriverConfig config = TestdriverConfig.getInstance();
    private static final String URL = config.getGrid();
    private static final String browser = config.getBrowser();

    /**
     * Create a new WebDriver by connecting to the Selenium Grid.
     * @return the newly-created driver.
     */
    public static WebDriver createInstance() {
        Capabilities capabilities = null;
        if (browser.equals("phantomjs")) {
            capabilities = DesiredCapabilities.phantomjs();
        } else if (browser.equals("chrome")) {
            capabilities = DesiredCapabilities.chrome();
        } else if (browser.equals("ie")) {
            capabilities = DesiredCapabilities.internetExplorer();
        } else {
            capabilities = DesiredCapabilities.firefox();
        }

        try {
            return new RemoteWebDriver(new URL(URL), capabilities);
        } catch (MalformedURLException ex) {
            throw new RuntimeException("Malformed Remote WebDriver URL: " + URL + "\n" + ex.getMessage());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy