Search in sources :

Example 6 with FirefoxBinary

use of org.openqa.selenium.firefox.FirefoxBinary in project wcomponents by BorderTech.

the class FirefoxWebDriverType method getDriverImplementation.

/**
 * {@inheritDoc}.
 */
@Override
public FirefoxDriver getDriverImplementation() {
    WebDriverManager.getInstance(DriverManagerType.FIREFOX).setup();
    FirefoxOptions options = new FirefoxOptions(getCapabilities());
    FirefoxBinary binary = getFirefoxBinary();
    FirefoxProfile profile = getFirefoxProfile();
    if (profile != null) {
        // it gets angry if you give it a null profile
        options.setProfile(profile);
    }
    // options.setHeadless(true);
    options.setBinary(binary);
    return new FirefoxDriver(options);
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 7 with FirefoxBinary

use of org.openqa.selenium.firefox.FirefoxBinary in project acceptance-test-harness by jenkinsci.

the class KerberosSsoTest method getNegotiatingFirefox.

private FirefoxDriver getNegotiatingFirefox(KerberosContainer kdc, String tokenCache) {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAlwaysLoadNoFocusLib(true);
    // Allow auth negotiation for jenkins under test
    String trustedUris = jenkins.url.toExternalForm();
    String jenkins_local_hostname = System.getenv("JENKINS_LOCAL_HOSTNAME");
    // if JENKINS_LOCAL_HOSTNAME is set, we add this to FF nego uris
    if (jenkins_local_hostname != null && !jenkins_local_hostname.isEmpty()) {
        try {
            // In the case where JENKINS_LOCAL_HOSTNAME is an IP,
            // we need to add its resolved hostname for auth negociation
            String hostName = InetAddress.getByName(jenkins_local_hostname).getCanonicalHostName();
            trustedUris = trustedUris + ", " + hostName;
        } catch (UnknownHostException e) {
            e.printStackTrace();
            throw new Error(e);
        }
    }
    profile.setPreference("network.negotiate-auth.trusted-uris", trustedUris);
    profile.setPreference("network.negotiate-auth.delegation-uris", trustedUris);
    FirefoxBinary binary = new FirefoxBinary();
    // Inject config and TGT
    binary.setEnvironmentProperty("KRB5CCNAME", tokenCache);
    binary.setEnvironmentProperty("KRB5_CONFIG", kdc.getKrb5ConfPath());
    // Turn debug on
    binary.setEnvironmentProperty("KRB5_TRACE", diag.touch("krb5_trace.log").getAbsolutePath());
    binary.setEnvironmentProperty("NSPR_LOG_MODULES", "negotiateauth:5");
    binary.setEnvironmentProperty("NSPR_LOG_FILE", diag.touch("firefox.nego.log").getAbsolutePath());
    String display = FallbackConfig.getBrowserDisplay();
    if (display != null) {
        binary.setEnvironmentProperty("DISPLAY", display);
    }
    final FirefoxDriver driver = new FirefoxDriver(binary, profile);
    cleaner.addTask(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                driver.quit();
            } catch (UnreachableBrowserException ex) {
                System.err.println("Browser died already");
                ex.printStackTrace();
            }
        }

        @Override
        public String toString() {
            return "Close Kerberos WebDriver after test";
        }
    });
    return driver;
}
Also used : UnknownHostException(java.net.UnknownHostException) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) Statement(org.junit.runners.model.Statement) Matchers.containsString(org.hamcrest.Matchers.containsString) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 8 with FirefoxBinary

use of org.openqa.selenium.firefox.FirefoxBinary in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

private WebDriver createWebDriver(TestName testName) throws IOException {
    String browser = System.getenv("BROWSER");
    if (browser == null)
        browser = "firefox";
    browser = browser.toLowerCase(Locale.ENGLISH);
    String display = getBrowserDisplay();
    switch(browser) {
        case "firefox":
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAlwaysLoadNoFocusLib(true);
            profile.setPreference(LANGUAGE_SELECTOR, "en");
            // Config screen with many plugins can cause FF to complain JS takes too long to complete - set longer timeout
            profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int) getElasticTime().seconds(600));
            FirefoxBinary binary = new FirefoxBinary();
            if (display != null) {
                binary.setEnvironmentProperty("DISPLAY", display);
            }
            return new FirefoxDriver(binary, profile);
        case "ie":
        case "iexplore":
        case "iexplorer":
            return new InternetExplorerDriver();
        case "chrome":
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", Collections.singletonMap(LANGUAGE_SELECTOR, "en"));
            ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
            if (display != null) {
                builder.withEnvironment(Collections.singletonMap("DISPLAY", display));
            }
            return new ChromeDriver(builder.build(), 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 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), DesiredCapabilities.firefox());
        default:
            throw new Error("Unrecognized browser type: " + browser);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SauceLabsConnection(org.jenkinsci.test.acceptance.utils.SauceLabsConnection)

Example 9 with FirefoxBinary

use of org.openqa.selenium.firefox.FirefoxBinary 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)

Aggregations

FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)9 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)9 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)4 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)3 File (java.io.File)2 Dimension (org.openqa.selenium.Dimension)2 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)2 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)2 TechnicalException (com.github.noraui.exception.TechnicalException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 ResourceBundle (java.util.ResourceBundle)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 SauceLabsConnection (org.jenkinsci.test.acceptance.utils.SauceLabsConnection)1 BeforeClass (org.junit.BeforeClass)1 Statement (org.junit.runners.model.Statement)1 WebElement (org.openqa.selenium.WebElement)1 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)1 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)1 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)1