Search in sources :

Example 6 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project MedunnaHealthTeam75 by ElanurSelcuk.

the class Driver method getDriver.

// to initialize the driver we create a static method
public static WebDriver getDriver() {
    // create the driver if and only if it is null
    if (driver == null) {
        String browser = ConfigurationReader.getProperty("browser");
        if ("chrome".equals(browser)) {
            WebDriverManager.chromedriver().setup();
            driver = new ChromeDriver();
        } else if ("firefox".equals(browser)) {
            WebDriverManager.firefoxdriver().setup();
            driver = new FirefoxDriver();
        } else if ("ie".equals(browser)) {
            WebDriverManager.iedriver().setup();
            driver = new InternetExplorerDriver();
        } else if ("safari".equals(browser)) {
            WebDriverManager.getInstance(SafariDriver.class).setup();
            driver = new SafariDriver();
        } else if ("chrome-headless".equals(browser)) {
            WebDriverManager.chromedriver().setup();
            driver = new ChromeDriver(new ChromeOptions().setHeadless(true));
        }
    }
    // driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    driver.manage().window().maximize();
    return driver;
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 7 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project seleniumRobot by bhecquet.

the class CustomEventFiringWebDriver method scrollToElement.

/**
 * scroll to the given element
 * we scroll 200 px to the left of the element so that we see all of it
 * @param element
 */
public void scrollToElement(WebElement element, int yOffset) {
    if (isWebTest) {
        try {
            WebElement parentScrollableElement = (WebElement) ((JavascriptExecutor) driver).executeScript(JS_SCROLL_PARENT, element, (driver instanceof SafariDriver) ? SAFARI_BROWSER : OTHER_BROWSER);
            Long topHeaderSize = (Long) ((JavascriptExecutor) driver).executeScript(JS_GET_TOP_HEADER);
            // try a second method (the first one is quicker but does not work when element is inside a document fragment, slot or shadow DOM
            if ((parentScrollableElement == null || "html".equalsIgnoreCase(parentScrollableElement.getTagName())) && !(driver instanceof InternetExplorerDriver)) {
                parentScrollableElement = (WebElement) ((JavascriptExecutor) driver).executeScript(JS_SCROLL_PARENT2, element, (driver instanceof SafariDriver) ? SAFARI_BROWSER : OTHER_BROWSER);
            }
            if (parentScrollableElement != null) {
                String parentTagName = parentScrollableElement.getTagName();
                // When the scrollable element is the document itself (html or body), use the legacy behavior scrolling the window itself
                if ("html".equalsIgnoreCase(parentTagName) || "body".equalsIgnoreCase(parentTagName)) {
                    if (yOffset == Integer.MAX_VALUE) {
                        // equivalent to HtmlElement.OPTIMAL_SCROLLING but, for grid, we do not want dependency between the 2 classes
                        yOffset = (int) Math.min(-200, -topHeaderSize);
                    }
                    scrollWindowToElement(element, yOffset);
                // When scrollable element is a "div" or anything else, use scrollIntoView because it's the easiest way to make the element visible
                } else {
                    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
                    // check if scrollbar of parent is at bottom. In this case, going upside (yOffset < 0), could hide searched element.
                    // scrollIntoView is configured to position scrollbar to top position of the searched element.
                    // in case offset is > 0, this has no impact as scrollBottom will always be < 0
                    // wait a bit so that scrolling is complete
                    WaitHelper.waitForMilliSeconds(500);
                    // if top header is present, scroll up so that our element is not hidden behind it (scrollIntoView scrolls so that element is at the top of the view even if header masks it)
                    if (topHeaderSize > 0) {
                        // equivalent to HtmlElement.OPTIMAL_SCROLLING but, for grid, we do not want dependency between the 2 classes
                        Integer scrollOffset = (int) (yOffset == Integer.MAX_VALUE ? topHeaderSize : topHeaderSize - yOffset);
                        ((JavascriptExecutor) driver).executeScript("if((arguments[0].scrollHeight - arguments[0].scrollTop - arguments[0].clientHeight) > 0) {" + "   var rootElement = arguments[1] === \"safari\" ? document.body: document.documentElement;" + "   rootElement.scrollTop -= " + scrollOffset + ";" + "}", parentScrollableElement, (driver instanceof SafariDriver) ? SAFARI_BROWSER : OTHER_BROWSER);
                    }
                    // wait a bit so that scrolling is complete
                    WaitHelper.waitForMilliSeconds(500);
                }
            } else {
                // go to default behavior
                throw new JavascriptException("No parent found");
            }
        } catch (Exception e) {
            // fall back to legacy behavior
            if (yOffset == Integer.MAX_VALUE) {
                yOffset = -200;
            }
            try {
                scrollWindowToElement(element, yOffset);
            } catch (Exception e1) {
                logger.info(String.format("Cannot scroll to element %s: %s", element.toString(), e1.getMessage()));
            }
        }
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) JavascriptException(org.openqa.selenium.JavascriptException) WebElement(org.openqa.selenium.WebElement) HeadlessException(java.awt.HeadlessException) ScenarioException(com.seleniumtests.customexception.ScenarioException) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) AWTException(java.awt.AWTException) WebDriverException(org.openqa.selenium.WebDriverException) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) IOException(java.io.IOException) WebSessionEndedException(com.seleniumtests.customexception.WebSessionEndedException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 8 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project boyka-java by WasiqBhamla.

the class DriverManager method setupSafariDriver.

private WebDriver setupSafariDriver() {
    LOGGER.traceEntry();
    safaridriver().setup();
    return LOGGER.traceExit(new SafariDriver());
}
Also used : SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 9 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project okta-idx-java by okta.

the class DriverUtil method chooseDriver.

/**
 * By default to web driver will be firefox
 *
 * Override it by passing -Dbrowser=Chrome to the command line arguments
 * @return webdriver
 */
private static WebDriver chooseDriver() {
    String preferredDriver = System.getProperty("browser", "Chrome");
    boolean headless = System.getProperty("headless", "false").equals("true");
    switch(preferredDriver.toLowerCase()) {
        case "safari":
            try {
                driver = new SafariDriver();
            } catch (Exception e) {
                System.out.println(e.getMessage());
                System.exit(0);
            }
            return driver;
        case "edge":
            try {
                driver = new EdgeDriver();
            } catch (Exception e) {
                System.out.println(e.getMessage());
                System.exit(0);
            }
            return driver;
        case "firefox":
            FirefoxOptions options = new FirefoxOptions();
            if (headless) {
                options.addArguments("-headless", "-safe-mode");
            }
            try {
                driver = new FirefoxDriver(options);
            } catch (Exception e) {
                System.out.println(e.getMessage());
                System.exit(0);
            }
            return driver;
        default:
            final ChromeOptions chromeOptions = new ChromeOptions();
            if (headless) {
                chromeOptions.addArguments("--headless");
            }
            chromeOptions.addArguments("--disable-dev-shm-usage");
            if (System.getenv("TRAVIS") != null) {
                chromeOptions.addArguments("--headless", "--verbose");
            }
            try {
                driver = new ChromeDriver(chromeOptions);
                ErrorHandler handler = new ErrorHandler();
                handler.setIncludeServerErrors(false);
            // driver.setErrorHandler(handler);
            } catch (Exception e) {
                System.out.println(e.getMessage());
                System.exit(0);
            }
            return driver;
    }
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) ErrorHandler(org.openqa.selenium.remote.ErrorHandler) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) MalformedURLException(java.net.MalformedURLException) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 10 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project selenide by selenide.

the class SafariDriverFactory method create.

@Nonnull
@CheckReturnValue
@Override
public WebDriver create(Config config, Browser browser, @Nullable Proxy proxy, @Nullable File browserDownloadsFolder) {
    SafariDriverService driverService = createDriverService(config);
    SafariOptions capabilities = createCapabilities(config, browser, proxy, browserDownloadsFolder);
    return new SafariDriver(driverService, capabilities);
}
Also used : SafariDriverService(org.openqa.selenium.safari.SafariDriverService) SafariOptions(org.openqa.selenium.safari.SafariOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver) CheckReturnValue(javax.annotation.CheckReturnValue) Nonnull(javax.annotation.Nonnull)

Aggregations

SafariDriver (org.openqa.selenium.safari.SafariDriver)27 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)16 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)15 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)12 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)11 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)8 SafariOptions (org.openqa.selenium.safari.SafariOptions)8 WebDriver (org.openqa.selenium.WebDriver)7 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)7 URL (java.net.URL)6 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)6 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)6 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)3 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)3 OperaDriver (org.openqa.selenium.opera.OperaDriver)3 SafariDriverService (org.openqa.selenium.safari.SafariDriverService)3 InvalidBrowserException (com.coveros.selenified.exceptions.InvalidBrowserException)2 IOException (java.io.IOException)2