Search in sources :

Example 26 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project demo-project by vasyafomiuk.

the class Driver method getDriver.

public static WebDriver getDriver() {
    if (driver == null) {
        if (System.getProperty("BROWSER") == null) {
            browser = ConfigurationReader.getProperty("browser");
        } else {
            browser = System.getProperty("BROWSER");
        }
        System.out.println("Browser: " + browser);
        switch(browser) {
            case "remote-chrome":
                try {
                    // assign your grid server address
                    String gridAddress = "54.235.53.73";
                    URL url = new URL("http://" + gridAddress + ":4444/wd/hub");
                    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
                    desiredCapabilities.setBrowserName("chrome");
                    driver = new RemoteWebDriver(url, desiredCapabilities);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case "chrome":
                WebDriverManager.chromedriver().setup();
                driver = new ChromeDriver();
                break;
            case "chrome-headless":
                WebDriverManager.chromedriver().setup();
                driver = new ChromeDriver(new ChromeOptions().setHeadless(true));
                break;
            case "firefox":
                WebDriverManager.firefoxdriver().setup();
                driver = new FirefoxDriver();
                break;
            case "firefox-headless":
                WebDriverManager.firefoxdriver().setup();
                driver = new FirefoxDriver(new FirefoxOptions().setHeadless(true));
                break;
            case "ie":
                if (System.getProperty("os.name").toLowerCase().contains("mac")) {
                    throw new WebDriverException("Your operating system does not support the requested browser");
                }
                WebDriverManager.iedriver().setup();
                driver = new InternetExplorerDriver();
                break;
            case "edge":
                if (System.getProperty("os.name").toLowerCase().contains("mac")) {
                    throw new WebDriverException("Your operating system does not support the requested browser");
                }
                WebDriverManager.edgedriver().setup();
                driver = new EdgeDriver();
                break;
            case "safari":
                if (System.getProperty("os.name").toLowerCase().contains("windows")) {
                    throw new WebDriverException("Your operating system does not support the requested browser");
                }
                WebDriverManager.getInstance(SafariDriver.class).setup();
                driver = new SafariDriver();
                break;
        }
    }
    return driver;
}
Also used : InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) WebDriverException(org.openqa.selenium.WebDriverException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) WebDriverException(org.openqa.selenium.WebDriverException)

Example 27 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project vol-active-support by dvsa.

the class SafariSetUp method driver.

public WebDriver driver() throws MalformedURLException {
    safari.setCapability("idleTimeout", 5000);
    safari.setCapability("name", "VOL-Cross-Browser");
    if (getPlatform() == null) {
        driver = new SafariDriver(getSafari());
    } else {
        safari.setCapability("platform", getPlatform());
        safari.setCapability("browser_version", getBrowserVersion());
        safari.setCapability("browserstack.localIdentifier", "vol");
        safari.setCapability("browserstack.local", "true");
        driver = new RemoteWebDriver(new URL(hubURL()), getSafari());
    }
    return driver;
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 28 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project ca3sCore by kuehne-trustable-de.

the class LocomotiveBase method startWebDriver.

public void startWebDriver() {
    Capabilities capabilities;
    baseUrl = configuration.url();
    LOGGER.info(String.format("\n=== Configuration ===\n" + "\tURL:     %s\n" + "\tBrowser: %s\n" + "\tHub:     %s\n", configuration.url(), configuration.browser().name(), configuration.hub()));
    boolean isLocal = StringUtils.isEmpty(configuration.hub());
    switch(configuration.browser()) {
        case CHROME:
            capabilities = new ChromeOptions();
            String driverName = "chromedriver";
            if (SystemUtils.IS_OS_WINDOWS) {
                driverName = "chromedriver.exe";
            }
            try {
                URL resourceURL = ResourceUtils.getURL("classpath:drivers/" + driverName);
                File tmpFile = File.createTempFile("ca3sTest", driverName);
                Files.copy(resourceURL.openStream(), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                if (SystemUtils.IS_OS_LINUX) {
                    Set<PosixFilePermission> perms = new HashSet<>();
                    perms.add(PosixFilePermission.OWNER_READ);
                    perms.add(PosixFilePermission.OWNER_WRITE);
                    perms.add(PosixFilePermission.OWNER_EXECUTE);
                    Files.setPosixFilePermissions(tmpFile.toPath(), perms);
                }
                System.setProperty("webdriver.chrome.driver", tmpFile.getAbsolutePath());
                System.err.println("starting local Chrome using driver at : " + System.getProperty("webdriver.chrome.driver"));
                if (isLocal) {
                    try {
                        WebDriverManager.chromedriver().setup();
                        ChromeOptions options = new ChromeOptions();
                        options.addArguments("--no-sandbox");
                        options.addArguments("--disable-dev-shm-usage");
                        driver = new ChromeDriver(options);
                    } catch (Exception x) {
                        x.printStackTrace();
                        LOGGER.error("starting chrome driver, exiting ...", x);
                        logFatal("chromedriver not found. See https://github.com/ddavison/conductor/wiki/WebDriver-Executables for more information.");
                        System.exit(1);
                    }
                }
            } catch (IOException ioe) {
                ioe.printStackTrace();
                System.err.println("problem installing chrome driver, exiting ...");
                System.exit(1);
            }
            break;
        case FIREFOX:
            capabilities = DesiredCapabilities.firefox();
            if (isLocal)
                driver = new FirefoxDriver(capabilities);
            break;
        case INTERNET_EXPLORER:
            logFatal("iedriver not found. See https://github.com/ddavison/conductor/wiki/WebDriver-Executables for more information.");
            System.exit(1);
            capabilities = DesiredCapabilities.internetExplorer();
            if (isLocal)
                driver = new InternetExplorerDriver(capabilities);
            break;
        case SAFARI:
            logFatal("safaridriver not found. See https://github.com/ddavison/conductor/wiki/WebDriver-Executables for more information.");
            System.exit(1);
            capabilities = DesiredCapabilities.safari();
            if (isLocal)
                driver = new SafariDriver(capabilities);
            break;
        case PHANTOMJS:
            capabilities = DesiredCapabilities.phantomjs();
            if (isLocal)
                try {
                    driver = new PhantomJSDriver(capabilities);
                } catch (Exception x) {
                    logFatal("phantomjs not found. Download them from https://bitbucket.org/ariya/phantomjs/downloads/ and extract the binary as phantomjs.exe, phantomjs.linux, or phantomjs.mac at project root for Windows, Linux, or MacOS.");
                    System.exit(1);
                }
            break;
        default:
            System.err.println("Unknown browser: " + configuration.browser());
            return;
    }
    if (!isLocal)
        // they are using a hub.
        try {
            // just override the driver.
            driver = new RemoteWebDriver(new URL(configuration.hub()), capabilities);
        } catch (Exception x) {
            logFatal("Couldn't connect to hub: " + configuration.hub());
            x.printStackTrace();
            return;
        }
    actions = new Actions(driver);
    if (StringUtils.isNotEmpty(baseUrl))
        driver.navigate().to(baseUrl);
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) Actions(org.openqa.selenium.interactions.Actions) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) IOException(java.io.IOException) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) WebDriverException(org.openqa.selenium.WebDriverException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ElementNotInteractableException(org.openqa.selenium.ElementNotInteractableException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 29 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project selenese-runner-java by vmi.

the class SafariDriverFactory method newInstance.

@Override
public WebDriver newInstance(DriverOptions driverOptions) {
    if (!OS.isFamilyMac())
        throw new UnsupportedOperationException("Unsupported platform: " + Platform.getCurrent());
    SafariDriverService service = setupBuilder(new SafariDriverService.Builder(), driverOptions, null).build();
    SafariOptions options = newSafariOptions(driverOptions);
    options.merge(driverOptions.getCapabilities());
    SafariDriver driver = new SafariDriver(service, options);
    setInitialWindowSize(driver, driverOptions);
    return driver;
}
Also used : SafariDriverService(org.openqa.selenium.safari.SafariDriverService) SafariOptions(org.openqa.selenium.safari.SafariOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 30 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project test-automation-wrapper by gjorezaharchev.

the class Safari method browser.

public WebDriver browser() {
    System.setProperty("webdriver.safari.noinstall", "true");
    driver = new SafariDriver();
    return driver;
}
Also used : SafariDriver(org.openqa.selenium.safari.SafariDriver)

Aggregations

SafariDriver (org.openqa.selenium.safari.SafariDriver)34 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)20 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)20 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)17 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)15 WebDriver (org.openqa.selenium.WebDriver)10 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)10 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)9 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)9 SafariOptions (org.openqa.selenium.safari.SafariOptions)8 URL (java.net.URL)7 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)7 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)7 WebDriverException (org.openqa.selenium.WebDriverException)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 OperaDriver (org.openqa.selenium.opera.OperaDriver)5 WebElement (org.openqa.selenium.WebElement)4 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)4 File (java.io.File)3 IOException (java.io.IOException)3