Search in sources :

Example 36 with FirefoxProfile

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

the class BaseTest method beforeClass.

@SuppressWarnings("deprecation")
@BeforeClass
public static void beforeClass() throws IOException {
    System.err.println("Launching " + browser);
    System.setProperty("webdriver.gecko.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/geckodriver.exe").getAbsolutePath() : "/tmp/geckodriver");
    System.setProperty("webdriver.firefox.bin", osName.toLowerCase().startsWith("windows") ? new File("c:/Program Files (x86)/Mozilla Firefox/firefox.exe").getAbsolutePath() : "/usr/bin/firefox");
    // https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    // use legacy FirefoxDriver
    capabilities.setCapability("marionette", false);
    // http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.firefox.FirefoxProfile
    capabilities.setCapability("locationContextEnabled", false);
    capabilities.setCapability("acceptSslCerts", true);
    capabilities.setCapability("elementScrollBehavior", 1);
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAcceptUntrustedCertificates(true);
    profile.setAssumeUntrustedCertificateIssuer(true);
    profile.setEnableNativeEvents(false);
    // optional
    /* 
		 profile.setPreference("general.useragent.override",
		 		"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20120101 Firefox/33.0");
		*/
    // System.out.println(System.getProperty("user.dir"));
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);
    try {
        driver = new FirefoxDriver(capabilities);
    } catch (WebDriverException e) {
        e.printStackTrace();
        throw new RuntimeException("Cannot initialize Firefox driver");
    }
    actions = new Actions(driver);
    driver.manage().window().setSize(new Dimension(width, height));
    driver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.SECONDS);
    // Declare a wait time
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    screenshot = ((TakesScreenshot) driver);
    js = ((JavascriptExecutor) driver);
    // driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(implicitWait, TimeUnit.SECONDS);
    // Go to URL
    driver.get(baseURL);
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) Actions(org.openqa.selenium.interactions.Actions) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Dimension(org.openqa.selenium.Dimension) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException) TakesScreenshot(org.openqa.selenium.TakesScreenshot) BeforeClass(org.junit.BeforeClass)

Example 37 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile 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 38 with FirefoxProfile

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

Example 39 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project iTest by e-government-ua.

the class SetupAndTeardown method createFirefoxProfileWithExtensions.

private FirefoxProfile createFirefoxProfileWithExtensions() {
    System.setProperty("webdriver.gecko.driver", "src\\test\\resources\\files\\geckodriver.exe");
    // System.setProperty("webdriver.firefox.marionette","src\\test\\resources\\files\\geckodriver.exe");
    /*хрень для deleteProcess чтоб чрез урл авторизироваться
        myProfile.setPreference("network.automatic-ntlm-auth.trusted-uris", "http://,https://");
        myProfile.setPreference("network.automatic-ntlm-auth.allow-non-fqdn", true);
        myProfile.setPreference("network.negotiate-auth.delegation-uris", "http://,https://");
        myProfile.setPreference("network.negotiate-auth.trusted-uris", "http://,https://");
        myProfile.setPreference("network.http.phishy-userpass-length", 255);
        myProfile.setPreference("security.csp.enable", false);
         */
    String path = "src/test/resources/files/cryptoplugin_ext_id@ff.xpi";
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAssumeUntrustedCertificateIssuer(false);
    profile.addExtension(new File(path));
    // profile.setPreference("plugin.state.npcryptoplugin", 2);
    profile.setPreference("xpinstall.signatures.required", false);
    DesiredCapabilities ff = DesiredCapabilities.firefox();
    ff.setAcceptInsecureCerts(true);
    ff.setCapability(FirefoxDriver.PROFILE, profile);
    ff.setCapability("marionette", true);
    return profile;
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) File(java.io.File)

Example 40 with FirefoxProfile

use of org.openqa.selenium.firefox.FirefoxProfile in project iTest by e-government-ua.

the class SetupAndTeardown method setDriver.

@Before
public void setDriver() {
    Configuration.startMaximized = true;
    // Configuration.browser = "chrome";
    Configuration.timeout = 10000;
    Configuration.collectionsTimeout = 10000;
    FirefoxProfile profile = createFirefoxProfileWithExtensions();
    WebDriver driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
    driver.manage().window().maximize();
    WebDriverRunner.setWebDriver(driver);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) Before(org.junit.Before)

Aggregations

FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)46 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)25 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)20 File (java.io.File)16 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)10 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)10 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)9 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)9 IOException (java.io.IOException)7 WebDriverException (org.openqa.selenium.WebDriverException)7 Actions (org.openqa.selenium.interactions.Actions)7 HashMap (java.util.HashMap)6 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)6 URL (java.net.URL)5 Dimension (org.openqa.selenium.Dimension)5 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)5 WebDriver (org.openqa.selenium.WebDriver)5 TakesScreenshot (org.openqa.selenium.TakesScreenshot)3 FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)3 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)3