Search in sources :

Example 1 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project jlineup by otto-de.

the class BrowserUtils method getWebDriverByConfig.

synchronized WebDriver getWebDriverByConfig(Config config, int width) {
    WebDriver driver;
    switch(config.browser) {
        case FIREFOX:
            FirefoxDriverManager.getInstance().setup();
            FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setProfile(getFirefoxProfileWithDisabledAnimatedGifs());
            driver = new FirefoxDriver(firefoxOptions);
            break;
        case FIREFOX_HEADLESS:
            FirefoxDriverManager.getInstance().setup();
            FirefoxOptions firefoxOptionsForHeadless = new FirefoxOptions();
            // Headless parameter is supported with Firefox >= 55
            firefoxOptionsForHeadless.addArguments("--headless");
            firefoxOptionsForHeadless.addArguments("-width", width + "", "-height", config.windowHeight + "");
            firefoxOptionsForHeadless.setProfile(getFirefoxProfileWithDisabledAnimatedGifs());
            driver = new FirefoxDriver(firefoxOptionsForHeadless);
            break;
        case CHROME:
            ChromeDriverManager.getInstance().setup();
            ChromeOptions options = new ChromeOptions();
            // To work in a headless env, this is needed
            options.addArguments("--no-sandbox");
            driver = new ChromeDriver(options);
            break;
        case CHROME_HEADLESS:
            ChromeDriverManager.getInstance().setup();
            ChromeOptions options_headless = new ChromeOptions();
            // To work in a headless env, this is needed
            options_headless.addArguments("--no-sandbox", "--headless", "--disable-gpu");
            options_headless.addArguments("--window-size=" + width + "," + config.windowHeight);
            driver = new ChromeDriver(options_headless);
            break;
        case PHANTOMJS:
        default:
            PhantomJsDriverManager.getInstance().setup();
            driver = new PhantomJSDriver();
            break;
    }
    driver.manage().timeouts().pageLoadTimeout(config.pageLoadTimeout, TimeUnit.SECONDS);
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 2 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project openmeetings by apache.

the class AbstractTestDefaults method setUp.

@Before
public void setUp() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("intl.accept_languages", getLocale());
    driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) Before(org.junit.Before)

Example 3 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project blueocean-plugin by jenkinsci.

the class AthModule method configure.

@Override
protected void configure() {
    Config cfg = new Config();
    File userConfig = new File(new File(System.getProperty("user.home")), ".blueocean-ath-config");
    if (userConfig.canRead()) {
        cfg.loadProps(userConfig);
    }
    bind(Config.class).toInstance(cfg);
    String webDriverType = cfg.getString("webDriverType");
    MutableCapabilities capability;
    if ("firefox".equals(webDriverType)) {
        capability = new FirefoxOptions();
    } else {
        capability = new ChromeOptions();
    }
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capability.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    String webDriverUrl = cfg.getString("webDriverUrl", "http://localhost:4444/wd/hub");
    String webDriverBrowserSize = cfg.getString("webDriverBrowserSize");
    try {
        String launchUrl = cfg.getString("jenkinsUrl");
        if (launchUrl == null) {
            launchUrl = new String(Files.readAllBytes(Paths.get("runner/.blueocean-ath-jenkins-url")));
        }
        capability.setCapability("extendedDebugging", "true");
        capability.setCapability("initialBrowserUrl", launchUrl);
        if (!StringUtils.isBlank(cfg.getString("TUNNEL_IDENTIFIER"))) {
            capability.setCapability("tunnelIdentifier", cfg.getString("TUNNEL_IDENTIFIER"));
        }
        WebDriver driver = new RemoteWebDriver(new URL(webDriverUrl), capability);
        LocalDriver.setCurrent(driver);
        driver = new Augmenter().augment(driver);
        if (webDriverBrowserSize == null) {
            driver.manage().window().maximize();
        } else {
            String[] widthXHeight = webDriverBrowserSize.split("x");
            driver.manage().window().setSize(new Dimension(Integer.parseInt(widthXHeight[0]), Integer.parseInt(widthXHeight[1])));
        }
        driver.manage().deleteAllCookies();
        bind(WebDriver.class).toInstance(driver);
        bindConstant().annotatedWith(BaseUrl.class).to(launchUrl);
        LocalDriver.setUrlBase(launchUrl);
        JenkinsUser admin = new JenkinsUser(cfg.getString("adminUsername", "alice"), cfg.getString("adminPassword", "alice"));
        bind(JenkinsUser.class).toInstance(admin);
        CustomJenkinsServer server = new CustomJenkinsServer(new URI(launchUrl), admin);
        bind(JenkinsServer.class).toInstance(server);
        bind(CustomJenkinsServer.class).toInstance(server);
        if (server.getComputerSet().getTotalExecutors() < 10) {
            server.runScript("jenkins.model.Jenkins.get().setNumExecutors(10);\n" + "jenkins.model.Jenkins.get().save();\n", true);
        }
        Properties properties = new Properties();
        File liveProperties = new File("live.properties");
        if (liveProperties.canRead()) {
            properties.load(new FileInputStream(liveProperties));
        }
        bind(Properties.class).annotatedWith(Names.named("live")).toInstance(properties);
    } catch (Exception e) {
        LocalDriver.destroy();
        throw new RuntimeException(e);
    }
    install(new FactoryModuleBuilder().implement(ActivityPage.class, ActivityPage.class).build(ActivityPageFactory.class));
    install(new FactoryModuleBuilder().implement(MultiBranchPipeline.class, MultiBranchPipeline.class).build(MultiBranchPipelineFactory.class));
    install(new FactoryModuleBuilder().implement(FreestyleJob.class, FreestyleJob.class).build(FreestyleJobFactory.class));
    install(new FactoryModuleBuilder().implement(ClassicPipeline.class, ClassicPipeline.class).build(ClassicPipelineFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsPipelinePage.class, RunDetailsPipelinePage.class).build(RunDetailsPipelinePageFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsArtifactsPage.class, RunDetailsArtifactsPage.class).build(RunDetailsArtifactsPageFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsTestsPage.class, RunDetailsTestsPage.class).build(RunDetailsTestsPageFactory.class));
    install(new FactoryModuleBuilder().implement(BranchPage.class, BranchPage.class).build(BranchPageFactory.class));
    install(new FactoryModuleBuilder().implement(PullRequestsPage.class, PullRequestsPage.class).build(PullRequestsPageFactory.class));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) RunDetailsArtifactsPageFactory(io.blueocean.ath.factory.RunDetailsArtifactsPageFactory) Properties(java.util.Properties) BranchPageFactory(io.blueocean.ath.factory.BranchPageFactory) URI(java.net.URI) URL(java.net.URL) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) PullRequestsPageFactory(io.blueocean.ath.factory.PullRequestsPageFactory) FreestyleJobFactory(io.blueocean.ath.factory.FreestyleJobFactory) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ClassicPipelineFactory(io.blueocean.ath.factory.ClassicPipelineFactory) RunDetailsPipelinePageFactory(io.blueocean.ath.factory.RunDetailsPipelinePageFactory) MultiBranchPipelineFactory(io.blueocean.ath.factory.MultiBranchPipelineFactory) RunDetailsTestsPageFactory(io.blueocean.ath.factory.RunDetailsTestsPageFactory) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) JenkinsServer(com.offbytwo.jenkins.JenkinsServer) Dimension(org.openqa.selenium.Dimension) FileInputStream(java.io.FileInputStream) Augmenter(org.openqa.selenium.remote.Augmenter) ActivityPageFactory(io.blueocean.ath.factory.ActivityPageFactory) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) File(java.io.File)

Example 4 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project ats-framework by Axway.

the class AbstractRealBrowserDriver method start.

@Override
@PublicAtsApi
public void start() {
    try {
        log.info("Starting selenium browser with " + this.getClass().getSimpleName());
        if (browserType == BrowserType.FireFox) {
            com.axway.ats.uiengine.FirefoxDriver firefoxDriver = new com.axway.ats.uiengine.FirefoxDriver(url, browserPath, remoteSeleniumURL);
            FirefoxProfile profile = null;
            if (firefoxDriver.getProfileName() != null) {
                profile = new ProfilesIni().getProfile(firefoxDriver.getProfileName());
                if (profile == null) {
                    throw new SeleniumOperationException("Firefox profile '" + firefoxDriver.getProfileName() + "' doesn't exist");
                }
            } else if (firefoxDriver.getProfileDirectory() != null) {
                File profileDirectory = new File(firefoxDriver.getProfileDirectory());
                profile = new FirefoxProfile(profileDirectory);
            } else {
                profile = new FirefoxProfile();
                String downloadDir = UiEngineConfigurator.getInstance().getBrowserDownloadDir();
                // for default browser. Now will FIX this behavior
                if (downloadDir.endsWith("/") || downloadDir.endsWith("\\")) {
                    downloadDir = downloadDir.substring(0, downloadDir.length() - 1);
                }
                // Following options are described in http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
                profile.setPreference("browser.download.dir", downloadDir);
                profile.setPreference("browser.download.folderList", 2);
                profile.setPreference("browser.helperApps.neverAsk.saveToDisk", UiEngineConfigurator.getInstance().getBrowserDownloadMimeTypes());
                // set to  "Always Activate"
                profile.setPreference("plugin.state.java", 2);
                // set to  "Always Activate"
                profile.setPreference("plugin.state.flash", 2);
                profile.setAcceptUntrustedCertificates(true);
            }
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            setFirefoxProxyIfAvailable(capabilities);
            if (this.browserPath != null) {
                capabilities.setCapability(FirefoxDriver.BINARY, this.browserPath);
            }
            FirefoxOptions options = UiEngineConfigurator.getInstance().getFirefoxDriverOptions();
            if (options == null) {
                options = new FirefoxOptions();
            }
            capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new FirefoxDriver(capabilities);
            }
        } else if (browserType == BrowserType.InternetExplorer) {
            InternetExplorerOptions options = UiEngineConfigurator.getInstance().getInternetExplorerDriverOptions();
            if (options == null) {
                options = new InternetExplorerOptions(DesiredCapabilities.internetExplorer());
            }
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), options);
            } else {
                webDriver = new org.openqa.selenium.ie.InternetExplorerDriver(options);
            }
        } else if (browserType == BrowserType.Edge) {
            EdgeOptions options = UiEngineConfigurator.getInstance().getEdgeDriverOptions();
            if (options == null) {
                options = new EdgeOptions().merge(DesiredCapabilities.edge());
            }
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), options);
            } else {
                webDriver = new org.openqa.selenium.edge.EdgeDriver(options);
            }
        } else if (browserType == BrowserType.Chrome) {
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            // apply Chrome options
            ChromeOptions options = UiEngineConfigurator.getInstance().getChromeDriverOptions();
            if (options == null) {
                options = new ChromeOptions();
            }
            /* set browser download dir for Chrome Browser */
            String downloadDir = UiEngineConfigurator.getInstance().getBrowserDownloadDir();
            HashMap<String, Object> prefs = new HashMap<String, Object>();
            prefs.put("profile.default_content_settings.popups", 0);
            prefs.put("download.default_directory", downloadDir);
            options.setExperimentalOption("prefs", prefs);
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new org.openqa.selenium.chrome.ChromeDriver(capabilities);
            }
        } else if (browserType == BrowserType.Safari) {
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), DesiredCapabilities.safari());
            } else {
                webDriver = new org.openqa.selenium.safari.SafariDriver();
            }
        } else if (browserType == BrowserType.PhantomJS) {
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setJavascriptEnabled(true);
            capabilities.setCapability("acceptSslCerts", true);
            capabilities.setCapability("browserConnectionEnabled", true);
            capabilities.setCapability("takesScreenshot", true);
            // See: https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#settings-object
            if (System.getProperty(PhantomJsDriver.SETTINGS_PROPERTY) != null) {
                Map<String, String> settings = extractPhantomJSCapabilityValues(System.getProperty(PhantomJsDriver.SETTINGS_PROPERTY));
                for (Entry<String, String> capability : settings.entrySet()) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + capability.getKey(), capability.getValue());
                }
            }
            // See:  https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-customHeaders
            if (System.getProperty(PhantomJsDriver.CUSTOM_HEADERS_PROPERTY) != null) {
                Map<String, String> customHeaders = extractPhantomJSCapabilityValues(System.getProperty(PhantomJsDriver.CUSTOM_HEADERS_PROPERTY));
                for (Entry<String, String> header : customHeaders.entrySet()) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + header.getKey(), header.getValue());
                }
            }
            if (this.browserPath != null) {
                capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, this.browserPath);
                System.setProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, // required from the create screenshot method
                this.browserPath);
            }
            // See:  https://github.com/ariya/phantomjs/wiki/API-Reference#command-line-options
            List<String> cliArgsCapabilities = new ArrayList<String>();
            cliArgsCapabilities.add("--web-security=false");
            cliArgsCapabilities.add("--ignore-ssl-errors=true");
            if (System.getProperty(PhantomJsDriver.SSL_PROTOCOL_PROPERTY) != null) {
                cliArgsCapabilities.add("--ssl-protocol=" + System.getProperty(PhantomJsDriver.SSL_PROTOCOL_PROPERTY));
            } else {
                cliArgsCapabilities.add("--ssl-protocol=any");
            }
            if (System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY) != null) {
                cliArgsCapabilities.add("--cookies-file=" + PhantomJsDriver.cookiesFile);
            }
            // cliArgsCapabilities.add( "--local-to-remote-url-access=true" );
            setPhantomJSProxyIfAvailable(cliArgsCapabilities);
            capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCapabilities);
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new org.openqa.selenium.phantomjs.PhantomJSDriver(capabilities);
            }
        }
        log.info("Opening URL: " + url);
        webDriver.get(url);
        if (this instanceof com.axway.ats.uiengine.PhantomJsDriver) {
            webDriver.manage().window().setSize(new Dimension(1280, 1024));
        } else if (!(this instanceof com.axway.ats.uiengine.EdgeDriver)) {
            webDriver.manage().window().maximize();
        }
        int browserActionTimeout = UiEngineConfigurator.getInstance().getBrowserActionTimeout();
        if (browserActionTimeout > 0) {
            webDriver.manage().timeouts().setScriptTimeout(browserActionTimeout, TimeUnit.SECONDS);
        }
        if (!(this instanceof com.axway.ats.uiengine.EdgeDriver)) {
            webDriver.manage().timeouts().pageLoadTimeout(browserActionTimeout, TimeUnit.SECONDS);
        }
        // waiting for the "body" element to be loaded
        waitForPageLoaded(webDriver, UiEngineConfigurator.getInstance().getWaitPageToLoadTimeout());
    } catch (Exception e) {
        throw new SeleniumOperationException("Error starting Selenium", e);
    }
}
Also used : HashMap(java.util.HashMap) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) URL(java.net.URL) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) Entry(java.util.Map.Entry) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Dimension(org.openqa.selenium.Dimension) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) EdgeOptions(org.openqa.selenium.edge.EdgeOptions) ProfilesIni(org.openqa.selenium.firefox.ProfilesIni) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project syndesis-qe by syndesisio.

the class CustomWebDriverProvider method prepareFirefoxDriver.

/**
 * Method will prepare firefox driver with custom profile
 *
 * @return
 */
private FirefoxDriver prepareFirefoxDriver() {
    // so far we only use firefox and chrome so lets set up firefox here
    log.info("setting firefox profile");
    System.setProperty("webdriver.gecko.driver", findDriverPath());
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setCapability("marionette", true);
    firefoxOptions.addArguments("start-maximized");
    firefoxOptions.addPreference("browser.download.folderList", 2);
    firefoxOptions.addPreference("browser.download.manager.showWhenStarting", false);
    firefoxOptions.addPreference("browser.download.panel.shown", false);
    firefoxOptions.addPreference("browser.download.dir", DOWNLOAD_DIR);
    firefoxOptions.addPreference("browser.download.useDownloadDir", true);
    firefoxOptions.addPreference("browser.helperApps.neverAsk.saveToDisk", INTEGRATION_EXPORT_MIME_TYPE);
    firefoxOptions.addPreference("javascript.enabled", true);
    firefoxOptions.addPreference("app.update.enabled", false);
    firefoxOptions.addPreference("app.update.service.enabled", false);
    firefoxOptions.addPreference("app.update.auto", false);
    firefoxOptions.addPreference("app.update.staging.enabled", false);
    firefoxOptions.addPreference("app.update.silent", false);
    firefoxOptions.addPreference("media.gmp-provider.enabled", false);
    firefoxOptions.addPreference("extensions.update.autoUpdate", false);
    firefoxOptions.addPreference("extensions.update.autoUpdateEnabled", false);
    firefoxOptions.addPreference("extensions.update.enabled", false);
    firefoxOptions.addPreference("extensions.update.autoUpdateDefault", false);
    firefoxOptions.addPreference("extensions.logging.enabled", false);
    firefoxOptions.addPreference("lightweightThemes.update.enabled", false);
    return new FirefoxDriver(firefoxOptions);
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver)

Aggregations

FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)21 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)17 WebDriver (org.openqa.selenium.WebDriver)9 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)7 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)6 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)6 File (java.io.File)5 URL (java.net.URL)5 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)5 Before (org.junit.Before)4 Dimension (org.openqa.selenium.Dimension)3 FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)3 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)3 SafariDriver (org.openqa.selenium.safari.SafariDriver)3 IOException (java.io.IOException)2 TimeoutException (org.openqa.selenium.TimeoutException)2 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)2 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)2 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)2 OperaDriver (org.openqa.selenium.opera.OperaDriver)2