Search in sources :

Example 11 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project page-factory-2 by sbtqa.

the class TagWebDriver method createDriver.

private static void createDriver() throws UnsupportedBrowserException, MalformedURLException {
    DesiredCapabilities capabilities = new WebDriverCapabilitiesParser().parse();
    if (!PROPERTIES.getProxy().isEmpty()) {
        Proxy seleniumProxy = ProxyConfigurator.configureProxy();
        capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    }
    String browserName = getBrowserName();
    capabilities.setBrowserName(browserName);
    String webDriverUrl = PROPERTIES.getWebDriverUrl();
    if (!webDriverUrl.isEmpty()) {
        setWebDriver(createRemoteWebDriver(webDriverUrl, capabilities));
    } else {
        if (browserName.equalsIgnoreCase(FIREFOX)) {
            setWebDriver(new FirefoxDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(SAFARI)) {
            setWebDriver(new SafariDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(CHROME)) {
            WebDriverManagerConfigurator.configureDriver(ChromeDriverManager.getInstance(), CHROME);
            setWebDriver(new ChromeDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(IE)) {
            WebDriverManagerConfigurator.configureDriver(InternetExplorerDriverManager.getInstance(), IE);
            setWebDriver(new InternetExplorerDriver(capabilities));
        } else {
            throw new UnsupportedBrowserException("'" + browserName + "' is not supported yet");
        }
    }
    webDriver.manage().timeouts().pageLoadTimeout(PageFactory.getTimeOutInSeconds(), TimeUnit.SECONDS);
    setBrowserSize();
    webDriver.get(PROPERTIES.getStartingUrl());
}
Also used : UnsupportedBrowserException(ru.sbtqa.tag.pagefactory.exceptions.UnsupportedBrowserException) Proxy(org.openqa.selenium.Proxy) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverCapabilitiesParser(ru.sbtqa.tag.pagefactory.support.capabilities.WebDriverCapabilitiesParser) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 12 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project divolte-collector by divolte.

the class SeleniumTestBase method doSetUp.

private void doSetUp(final Optional<String> configFileName) throws Exception {
    final String driverName = System.getenv().getOrDefault(DRIVER_ENV_VAR, PHANTOMJS_DRIVER);
    switch(driverName) {
        case CHROME_DRIVER:
            setupLocalChrome();
            break;
        case SAFARI_DRIVER:
            driver = new SafariDriver();
            break;
        case SAUCE_DRIVER:
            setupSauceLabs();
            break;
        case BS_DRIVER:
            setupBrowserStack();
            break;
        case PHANTOMJS_DRIVER:
        default:
            driver = new PhantomJSDriver();
            break;
    }
    final WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(WINDOW_AVAILABLE);
    server = configFileName.map(TestServer::new).orElseGet(TestServer::new);
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) SafariDriver(org.openqa.selenium.safari.SafariDriver) TestServer(io.divolte.server.ServerTestUtils.TestServer)

Example 13 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project archiva by apache.

the class WebdriverUtility method newWebDriver.

public static WebDriver newWebDriver(String seleniumBrowser, String seleniumHost, int seleniumPort, boolean seleniumRemote) {
    log.info("WebDriver {}, {}, {}, {}", seleniumBrowser, seleniumHost, seleniumPort, seleniumRemote);
    if (seleniumRemote && StringUtils.isEmpty(seleniumHost)) {
        throw new IllegalArgumentException("seleniumHost must be set, when seleniumRemote=true");
    }
    try {
        if (StringUtils.contains(seleniumBrowser, "chrome")) {
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            if (seleniumRemote) {
                DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities);
            } else {
                return new ChromeDriver(options);
            }
        }
        if (StringUtils.contains(seleniumBrowser, "safari")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.safari());
            } else {
                return new SafariDriver();
            }
        }
        if (StringUtils.contains(seleniumBrowser, "iexplore")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.internetExplorer());
            } else {
                new InternetExplorerDriver();
            }
        }
        if (StringUtils.contains(seleniumBrowser, "firefox")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.firefox());
            } else {
                return new FirefoxDriver();
            }
        }
        DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
        capabilities.setJavascriptEnabled(true);
        capabilities.setVersion("firefox-52");
        WebDriver driver;
        if (seleniumRemote) {
            driver = new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities);
        } else {
            driver = new HtmlUnitDriver(capabilities) {

                @Override
                protected WebClient modifyWebClient(WebClient client) {
                    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
                    client.getOptions().setThrowExceptionOnScriptError(false);
                    client.getOptions().setCssEnabled(true);
                    return client;
                }
            };
        }
        return driver;
    } catch (MalformedURLException e) {
        throw new RuntimeException("Initializion of remote driver failed");
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) MalformedURLException(java.net.MalformedURLException) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 14 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

private WebDriver createWebDriver(TestCleaner cleaner, TestName testName) throws IOException {
    String browser = getBrowser();
    String display = getBrowserDisplay();
    switch(browser) {
        case "firefox":
            setDriverPropertyIfMissing("geckodriver", GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY);
            GeckoDriverService.Builder builder = new GeckoDriverService.Builder();
            if (display != null) {
                builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
            }
            GeckoDriverService service = builder.build();
            return new FirefoxDriver(service, buildFirefoxOptions(testName));
        case "firefox-container":
            return createContainerWebDriver(cleaner, "selenium/standalone-firefox-debug:3.141.59", buildFirefoxOptions(testName));
        case "chrome-container":
            return createContainerWebDriver(cleaner, "selenium/standalone-chrome-debug:3.141.59", new ChromeOptions());
        case "ie":
        case "iexplore":
        case "iexplorer":
            return new InternetExplorerDriver();
        case "chrome":
            Map<String, String> prefs = new HashMap<String, String>();
            prefs.put(LANGUAGE_SELECTOR, "en");
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", prefs);
            if (isCaptureHarEnabled()) {
                options.setAcceptInsecureCerts(true);
                options.setProxy(createSeleniumProxy(testName.get()));
            }
            setDriverPropertyIfMissing("chromedriver", ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY);
            return new ChromeDriver(options);
        case "safari":
            return new SafariDriver();
        case "htmlunit":
            return new HtmlUnitDriver(true);
        case "saucelabs":
        case "saucelabs-firefox":
            DesiredCapabilities caps = DesiredCapabilities.firefox();
            caps.setCapability("version", "29");
            caps.setCapability("platform", "Windows 7");
            caps.setCapability("name", testName.get());
            if (isCaptureHarEnabled()) {
                caps.setCapability(CapabilityType.PROXY, createSeleniumProxy(testName.get()));
            }
            // if running inside Jenkins, expose build ID
            String tag = System.getenv("BUILD_TAG");
            if (tag != null)
                caps.setCapability("build", tag);
            return new SauceLabsConnection().createWebDriver(caps);
        case "phantomjs":
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setCapability(LANGUAGE_SELECTOR, "en");
            capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en");
            return new PhantomJSDriver(capabilities);
        case "remote-webdriver-firefox":
            String u = System.getenv("REMOTE_WEBDRIVER_URL");
            if (StringUtils.isBlank(u)) {
                throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set");
            }
            return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
            new URL(u), buildFirefoxOptions(testName));
        case "remote-webdriver-chrome":
            u = System.getenv("REMOTE_WEBDRIVER_URL");
            if (StringUtils.isBlank(u)) {
                throw new Error("remote-webdriver-chrome requires REMOTE_WEBDRIVER_URL to be set");
            }
            return new RemoteWebDriver(// http://192.168.99.100:4444/wd/hub
            new URL(u), DesiredCapabilities.chrome());
        default:
            throw new Error("Unrecognized browser type: " + browser);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) HashMap(java.util.HashMap) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) CommandBuilder(org.jenkinsci.utils.process.CommandBuilder) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) GeckoDriverService(org.openqa.selenium.firefox.GeckoDriverService) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SauceLabsConnection(org.jenkinsci.test.acceptance.utils.SauceLabsConnection)

Example 15 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)

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