Search in sources :

Example 16 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project selenium_java by sergueik.

the class WebRtcFirefoxTest method setupTest.

@Before
public void setupTest() {
    FirefoxOptions options = new FirefoxOptions();
    // This flag avoids granting the access to the camera
    options.addPreference("media.navigator.permission.disabled", true);
    // This flag force to use fake user media (synthetic video of multiple
    // color)
    options.addPreference("media.navigator.streams.fake", true);
    driver = new FirefoxDriver(options);
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) Before(org.junit.Before)

Example 17 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project selenium_java by sergueik.

the class HeadlessFirefoxSeleniumExample method main.

public static void main(String[] args) {
    FirefoxBinary firefoxBinary = new FirefoxBinary();
    firefoxBinary.addCommandLineOptions("--headless");
    System.setProperty("webdriver.gecko.driver", "/home/sergueik/Downloads/geckodriver");
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setBinary(firefoxBinary);
    FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
    try {
        driver.get("http://www.google.com");
        driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
        WebElement queryBox = driver.findElement(By.name("q"));
        queryBox.sendKeys("headless firefox");
        WebElement searchBtn = driver.findElement(By.name("btnK"));
        searchBtn.click();
        WebElement iresDiv = driver.findElement(By.id("ires"));
        iresDiv.findElements(By.tagName("a")).get(0).click();
        System.out.println(driver.getPageSource());
    } finally {
        driver.quit();
    }
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) WebElement(org.openqa.selenium.WebElement)

Example 18 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project sonar-scanner-jenkins by SonarSource.

the class JenkinsOrchestrator method start.

public void start() {
    if (started.getAndSet(true)) {
        throw new IllegalStateException("Jenkins is already started");
    }
    int port = config.getInt("jenkins.container.port", 0);
    if (port <= 0) {
        port = NetworkUtils.getNextAvailablePort(NetworkUtils.getLocalhost());
    }
    distribution.setPort(port);
    FileSystem fileSystem = config.fileSystem();
    ServerInstaller serverInstaller = new ServerInstaller(fileSystem);
    server = serverInstaller.install(distribution);
    server.setUrl(String.format("http://localhost:%d", port));
    jenkinsWrapper = new JenkinsWrapper(server, config, fileSystem.javaHome(), port);
    jenkinsWrapper.start();
    FirefoxProfile profile = new FirefoxProfile();
    // force language to be English
    profile.setPreference("intl.accept_languages", "en");
    FirefoxOptions options = new FirefoxOptions().setProfile(profile);
    driver = new FirefoxDriver(options);
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get(server.getUrl());
    // Fix window size for having reproducible test behavior
    driver.manage().window().setPosition(new Point(20, 20));
    driver.manage().window().setSize(new Dimension(1024, 768));
    try {
        cli = new CLI(new URL(server.getUrl()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // Force updatecenter initialization
    driver.get(server.getUrl() + "/pluginManager");
    findElement(By.linkText("Advanced")).click();
    findElement(buttonByText("Check now")).click();
}
Also used : CLI(hudson.cli.CLI) JenkinsWrapper(com.sonar.it.jenkins.orchestrator.container.JenkinsWrapper) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) Point(org.openqa.selenium.Point) URL(java.net.URL) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FileSystem(com.sonar.orchestrator.config.FileSystem) ServerInstaller(com.sonar.it.jenkins.orchestrator.container.ServerInstaller)

Example 19 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project structr by structr.

the class SeleniumTest method startDriver.

@Before
public void startDriver() {
    switch(activeBrowser) {
        case FIREFOX:
            System.setProperty("webdriver.gecko.driver", getBrowserDriverLocation(activeBrowser));
            final FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setHeadless(true);
            driver = new FirefoxDriver(firefoxOptions);
            break;
        case CHROME:
            System.setProperty("webdriver.chrome.driver", getBrowserDriverLocation(activeBrowser));
            System.setProperty("webdriver.chrome.logfile", "/tmp/chromedriver.log");
            System.setProperty("webdriver.chrome.verboseLogging", "true");
            final ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.setHeadless(true);
            driver = new ChromeDriver(chromeOptions);
            break;
        case NONE:
            // Don't create a driver in main thread, useful for parallel testing
            break;
    }
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Before(org.junit.Before)

Example 20 with FirefoxOptions

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

the class WebDriverManager method getWebDriver.

public static WebDriver getWebDriver() {
    WebDriver driver = null;
    try {
        int firefoxVersion = WebDriverManager.getFirefoxVersion();
        LOG.info("Firefox version " + firefoxVersion + " detected");
        downLoadsDir = FileUtils.getTempDirectory().toString();
        String tempPath = downLoadsDir + "/firefox/";
        downloadGeekoDriver(firefoxVersion, tempPath);
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.dir", downLoadsDir);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.download.manager.showAlertOnComplete", false);
        profile.setPreference("browser.download.manager.closeWhenDone", true);
        profile.setPreference("app.update.auto", false);
        profile.setPreference("app.update.enabled", false);
        profile.setPreference("dom.max_script_run_time", 0);
        profile.setPreference("dom.max_chrome_script_run_time", 0);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
        profile.setPreference("network.proxy.type", 0);
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);
        ImmutableMap<String, String> displayImmutable = ImmutableMap.<String, String>builder().build();
        if ("true".equals(System.getenv("TRAVIS"))) {
            // Run with DISPLAY 99 for TRAVIS or other build machine
            displayImmutable = ImmutableMap.of("DISPLAY", ":99");
        }
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
        System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
        driver = new FirefoxDriver(new GeckoDriverService.Builder().usingDriverExecutable(new File(tempPath + "geckodriver")).withEnvironment(displayImmutable).build(), firefoxOptions);
    } catch (Exception e) {
        LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
    }
    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
        }
    }
    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while SafariDriver ", e);
        }
    }
    String url;
    if (System.getenv("url") != null) {
        url = System.getenv("url");
    } else {
        url = "http://localhost:8080";
    }
    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.get(url);
    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {

                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
            driver.navigate().to(url);
        }
    }
    if (loaded == false) {
        fail();
    }
    driver.manage().window().maximize();
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) IOException(java.io.IOException) TimeoutException(org.openqa.selenium.TimeoutException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) GeckoDriverService(org.openqa.selenium.firefox.GeckoDriverService) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) TimeoutException(org.openqa.selenium.TimeoutException)

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