Example usage for org.openqa.selenium.firefox FirefoxBinary FirefoxBinary

List of usage examples for org.openqa.selenium.firefox FirefoxBinary FirefoxBinary

Introduction

In this page you can find the example usage for org.openqa.selenium.firefox FirefoxBinary FirefoxBinary.

Prototype

public FirefoxBinary(File pathToFirefoxBinary) 

Source Link

Usage

From source file:ExperimentRunner.java

License:Apache License

private void setupFirefox() throws Exception {
    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    FirefoxBinary binary = new FirefoxBinary(new File(firefoxBinary));
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.cache.disk.enable", false);
    profile.setPreference("browser.cache.disk_cache_ssl", false);
    profile.setPreference("browser.cache.memory.enable", false);
    profile.setPreference("browser.cache.offline.capacity", 0);
    profile.setPreference("browser.cache.offline.enable", false);
    profile.setPreference("media.cache_size", 0);
    profile.setPreference("network.http.use-cache", false);
    //profile.setPreference("brwoser.dom.window.dump.enabled", true);
    driver = new FirefoxDriver(binary, profile, desiredCapabilities);
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
}

From source file:calc.CalculatorUIT.java

public void testCodesCrud(DesiredCapabilities browser) throws Exception {

    ExtentReports logger = new ExtentReports("target//advancedReport.html", false);
    ExtentTest test1 = logger.startTest("Verify Target String");
    ExtentTest test2 = logger.startTest("Verify Calculation Result");

    WebDriver driver = null;//ww  w . j ava 2 s  .c om
    System.out.println("Attempt connect to Selenium Node @ " + NodeURL);
    File pathToBinary = new File("/opt/firefox46/firefox/firefox-bin");
    FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    driver = new FirefoxDriver(ffBinary, firefoxProfile);
    try {
        System.out.println("attempt connect to target: " + TargetURL);
        driver.get(TargetURL);
        //input a addition 12+8 example in the calculator web-application;
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[2]")).click();
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[3]")).click();
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[12]")).click();
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[10]")).click();
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[15]")).click();

        //search target string value
        String targetStr = "Welcome to the Demo";

        //verify result
        boolean isFound = (driver.findElement(By.tagName("body")).getText()).contains(targetStr);
        boolean result = driver.findElement(By.name("display")).getAttribute("value").contains("84");

        //verify title  
        if (isFound == true) {
            test1.log(LogStatus.PASS, "Title has been verified");
        }
        if (isFound == false) {
            test1.log(LogStatus.FAIL, "Title has NOT been verified");
        }

        //verify result     
        if (result == true) {
            test2.log(LogStatus.PASS,
                    "The Calculation result was correct: [12 multiply by 7 gave output of 84]");
        } else {
            test2.log(LogStatus.FAIL,
                    "The Calculation result was not correct [the title is[Welcome to the Demo!]");

        }
        logger.endTest(test1);
        logger.endTest(test2);
        logger.flush();

        System.out.println("look for= [" + targetStr + "]");
        System.out.println("did we find it? [" + isFound + "]");

        System.out.println("calculate 12 multiply by 7");
        System.out.println("Was the result 84 ? [" + result + "]");

        Assert.assertTrue(isFound);
        Assert.assertTrue(result);
        //  Assert.assertEquals("hell",driver.getTitle());
        //doTest(driver); 
        // rest of test commands come here
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(e.getMessage(), false);
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:com.adasasistemas.pilot.webtest3.NewSeleneseIT.java

@Test
public void testSimple() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    FirefoxProfile fp = new FirefoxProfile();

    //   fp.setPreference("browser.startup.homepage", URL);
    // fp.setPreference("startup.homepage_welcome_url", URL);
    //fp.setPreference("startup.homepage_welcome_url.additional", URL);
    FirefoxBinary fb = new FirefoxBinary(new File(NAVIGATOR));
    WebDriver driver = new FirefoxDriver(fb, fp);

    // And now use this to visit NetBeans
    //  driver.get("http://www.netbeans.org");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.netbeans.org");
    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    driver.navigate().to("http://localhost:8085/webtest3");
    //* driver.navigate().refresh();
    //  driver.get("http://localhost:8085/webtest3");
    //    System.out.println(driver.getPageSource());

    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override/*from w w  w. j ava2s .  co  m*/
        public Boolean apply(WebDriver d) {
            System.out.println(d.getPageSource());
            return d.getPageSource().contains("Hello");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:com.axatrikx.webdriver.FirefoxLoader.java

License:Apache License

@Override
public WebDriver getDriver() {
    WebDriver driver;//from w ww.j  av  a 2s .  co  m
    FirefoxProfile profile;
    if (!firefoxProfile.isEmpty()) {
        ProfilesIni allProfiles = new ProfilesIni();
        try {
            profile = allProfiles.getProfile(firefoxProfile);
        } catch (Exception e) {
            profile = new FirefoxProfile();
        }
    } else {
        profile = new FirefoxProfile();
    }
    profile.setPreference("browser.download.dir", downloadDir);
    profile.setPreference("browser.download.folderList", 2);

    if (useProxy) {
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", proxyHost);
        profile.setPreference("network.proxy.http_port", proxyPort);
        profile.setPreference("network.proxy.ssl", proxyHost);
        profile.setPreference("network.proxy.ssl_port", proxyPort);
        profile.setPreference("network.proxy.ftp", proxyHost);
        profile.setPreference("network.proxy.ftp_port", proxyPort);
    } else {
        profile.setPreference("network.proxy.type", Proxy.ProxyType.AUTODETECT.ordinal());
    }

    if (!firefoxBinaryPath.isEmpty()) {
        // set custom firefox binary
        FirefoxBinary binary = new FirefoxBinary(new File(firefoxBinaryPath));
        driver = new FirefoxDriver(binary, profile);
    } else {
        driver = new FirefoxDriver(profile);
    }
    return driver;
}

From source file:com.bitbreeds.webrtc.signaling.BrowserTest.java

License:Open Source License

@Test
public void testFull() throws Exception {

    String firefoxPath = System.getProperty("firefox.path");
    //OS X * /Firefox.app/Contents/MacOS/firefox
    System.setProperty("com.bitbreeds.keystore", "./src/test/resources/ws2.jks");
    System.setProperty("com.bitbreeds.keystore.alias", "websocket");
    System.setProperty("com.bitbreeds.keystore.pass", "websocket");

    if (firefoxPath != null) {
        SimpleSignalingExample.main();/*from w  ww.ja  va2  s.c om*/

        File fl = new File(".././web/index.html");

        String url = "file://" + fl.getAbsolutePath();
        System.out.println(url);
        FirefoxBinary binary = new FirefoxBinary(new File(firefoxPath));
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        WebDriver driver = new FirefoxDriver(binary, firefoxProfile);
        driver.get(url);

        (new WebDriverWait(driver, 20)).until((ExpectedCondition<Boolean>) d -> {
            assert d != null;
            return d.findElement(By.id("status")).getText().equalsIgnoreCase("ONMESSAGE");
        });

        driver.quit();
    }

}

From source file:com.cognifide.aet.worker.drivers.FirefoxWebDriverFactory.java

License:Apache License

private AetFirefoxDriver getFirefoxDriver(FirefoxProfile fp, DesiredCapabilities capabilities)
        throws IOException {
    AetFirefoxDriver driver;/*w  w  w .j a v  a  2 s .  c  om*/
    if (StringUtils.isBlank(path)) {
        driver = new AetFirefoxDriver(capabilities);
    } else {
        FirefoxBinary binary = new FirefoxBinary(new File(path));
        driver = new AetFirefoxDriver(binary, fp, capabilities);
    }
    driver.manage().timeouts().pageLoadTimeout(5L, TimeUnit.MINUTES);
    return driver;
}

From source file:com.coinbot.core.Worker.java

License:Open Source License

@Override
public void run() {
    File pathToBinary = new File("/home/jian/Descargas/firefox46/bin/firefox");
    // Firefox 46 needed
    FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
    FirefoxProfile profile = new FirefoxProfile();
    FirefoxDriver driver = new FirefoxDriver(ffBinary, profile);
    CoinbotApplication.ui.workerQueue.addWorker(workerPanel);

    while (CoinbotApplication.bot.isRunning()) {
        // Sacamos un "claim" de la cola
        Claim claim = CoinbotApplication.bot.getClaimQueue().next();
        if (claim == null) {
            continue;
        }/*  w  ww. ja va  2s. co m*/

        claim.getPanel().reset();
        claim.getPanel().getProgressBar().setMaximum(10);
        workerPanel.addClaim(claim.getPanel());
        claim.getPanel().nextStep("Opening URL");

        try {
            driver.manage().timeouts().pageLoadTimeout(12, TimeUnit.SECONDS);
            driver.navigate().to(new URL(claim.getFaucet().getUrl()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
            continue;
        } catch (TimeoutException e) {
            // Busca un elemento, si no lo encuentra que vuelva a cargar
            e.printStackTrace();
        }

        // Detectando captcha
        claim.getPanel().nextStep("Detecting Captcha");
        CaptchaDetector captchaDetector = new CaptchaDetector();
        CaptchaService captcha = null;

        try {
            captcha = captchaDetector.find(driver, driver.findElement(By.tagName("body")));
        } catch (NoSuchElementException ex) {
            ex.printStackTrace();
            claim.getPanel().nextStep("Body not found!");
            continue;
        } catch (UnrecognizedCaptcha ex) {
            ex.printStackTrace();
            claim.getPanel().nextStep("Captcha not recognized.");
            continue;
        } catch (Exception ex) {
            continue;
        }

        claim.getPanel().nextStep("Trying auto resolving");
        // Intentamos buscar el hash en la DB 
        CaptchaHash ch = new CaptchaHash(captcha);
        String answer = CoinbotApplication.captchaDatabase.getAnswer(ch.getHash());

        // Si no enctramos la respuesta en la bd se la pedimos al usuario
        if (answer == null) {
            claim.getPanel().nextStep("Waiting for captcha answer ...");

            // Encolar captcha
            CoinbotApplication.bot.getCaptchaQueue().toQueue(captcha);

            // Esperar la resolucion del captcha
            CaptchaTimer timer = new CaptchaTimer(captcha, 35);
            timer.start();

            // Esperamos a la resolucion
            while (!timer.isExpired() && !captcha.resolved()) {
                CoinbotApplication.ui.captchaQueue.getCaptchaPanel(captcha).setTimer(timer.getSecondsLeft());
            }

            if (!captcha.resolved()) {
                CoinbotApplication.captchaDatabase.addCaptcha(ch);
                continue;
            }
        }

        // Guardamos el captcha en la DB
        CoinbotApplication.captchaDatabase.addCaptcha(new CaptchaHash(captcha));

        // Y la imagen en un archivo
        try {
            ImageIO.write(captcha.getImage(), "png", new File("coinbot/captchas/" + ch.getHash() + ".png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Envia la respuesta al input
        captcha.answerToInput(driver);

        // Desencolar captcha
        CoinbotApplication.bot.getCaptchaQueue().deQueue(captcha);

        // Escribir address
        claim.getPanel().nextStep("Detecting input address");
        InputAddressDetector iad = new InputAddressDetector(driver);
        iad.insertAddress(claim.getBtcAddress());

        //claim.getPanel().nextStep("Detecting Antibot");
        // Detectar antibot (puzzle no soportado)
        // Resolver antibot

        // submit
        claim.getPanel().nextStep("Submiting ...");
        WebElement submit = driver.findElement(By.id("address"));
        submit.submit();

        claim.getPanel().nextStep("Checking response");
        //claim.getPanel().nextStep("Successfull claim!");
        /*WebElement out = null;
                
        try {
           out = driver.findElement(By.className("alert-success"));
        } catch (NoSuchElementException e) {
                   
        }
                
        try {
           out = driver.findElement(By.className("alert-danger"));
        } catch (NoSuchElementException e) {
        }
        */
        //claim.getPanel().nextStep("Failed claim!");

        claim.getPanel().done();
        workerPanel.removeClaim(claim.getPanel());
        claim.getTimer().done(2000, 1);
        CoinbotApplication.bot.getClaimQueue().toQueue(claim);

        try {
            Thread.sleep(25000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        driver.close();
    } catch (Exception e) {

    }
    CoinbotApplication.ui.workerQueue.removeWorker(workerPanel);
    System.out.println("Worker " + workerId + " end work!");
}

From source file:com.expedia.lux.accountsettingstest.core.CreateWebDriverHelper.java

License:Open Source License

/**
 * Create webdriver entry/*from www .ja  va  2s  . co m*/
 * 
 * @param testName
 * @param browserType
 *            1 is chrome, 2 is firefox, 0 is internet explorer, 3 is safari
 * @param logging
 * @return
 */
public static WebDriver createWebDriver(String testName, String testBrowser) {
    WebDriver driver = null;
    String isCloud = String.valueOf(isRemoteTest);

    if (!isRemoteTest) {
        DesiredCapabilities capabillities = new DesiredCapabilities();
        capabillities.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, false);
        switch (testBrowser.toUpperCase()) {
        case "IE":
            // Need set iedriver.exe file path
            System.setProperty("webdriver.ie.driver", ieDriverPath);
            driver = new InternetExplorerDriver(capabillities);
            break;
        case "FF":
            // TODO: Not stable
            capabillities.setCapability(FirefoxDriver.BINARY, new FirefoxBinary(new File(firefoxPath)));
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAcceptUntrustedCertificates(true);
            capabillities.setCapability(FirefoxDriver.PROFILE, profile);
            driver = new FirefoxDriver(capabillities);
            break;
        case "SF":
            // TODO: No one's machine has safari installed in SZ
            driver = new SafariDriver(capabillities);
            break;
        default:
            // Need set the chromedriver.exe file path.
            System.setProperty("webdriver.chrome.driver", chromeDriverPath);
            driver = new ChromeDriver(capabillities);
            break;
        }
    } else {
        DesiredCapabilities capabillities;
        switch (testBrowser.toUpperCase()) {
        case "IE9":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability(CapabilityType.VERSION, "9");
            break;
        case "FF":
            capabillities = DesiredCapabilities.firefox();
            break;
        case "SF":
            capabillities = DesiredCapabilities.safari();
            capabillities.setCapability("platform", "OS X 10.6");
            capabillities.setCapability("version", "5");
            capabillities.setCapability("disable-popup-handler", true);
            break;
        case "IE7":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability(CapabilityType.VERSION, "7");
            break;
        case "IE8":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability(CapabilityType.VERSION, "8");
            break;
        case "IE10":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability(CapabilityType.VERSION, "10");
            break;
        case "IE11":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability("version", "11");
            break;
        case "OP":
            capabillities = DesiredCapabilities.opera();
            capabillities.setCapability("version", "12");
            break;
        //Note: may not support HTTPS via sauceConnect with mobile platform yet
        case "IOS":
            capabillities = DesiredCapabilities.iphone();
            capabillities.setCapability("version", "6.1");
            capabillities.setCapability("platform", "OS X 10.8");
            capabillities.setCapability("device-orientation", "portrait");
            capabillities.setCapability("disable-popup-handler", true);
            break;
        case "AND":
            capabillities = DesiredCapabilities.android();
            capabillities.setCapability("version", "4.0");
            capabillities.setCapability("platform", "Linux");
            capabillities.setCapability("device-type", "tablet");
            capabillities.setCapability("device-orientation", "portrait");
            break;
        case "SAUCE":
            return createWebDriverSaucelab(testName + " (SauceLabs)");
        default:
            capabillities = DesiredCapabilities.chrome();
            capabillities.setBrowserName("chrome");
            break;
        }

        try {
            driver = new RemoteWebDriver(new URL("http://10.208.52.16:5555/wd/hub"), capabillities);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    fillBrowserName(testBrowser, isCloud);
    return driver;
}

From source file:com.galois.fiveui.drivers.Drivers.java

License:Apache License

/**
 * Return a new Firefox webdriver./* w w  w  . j av a 2 s .  c  o m*/
 * @param ffProfile Directory path for the desired Firefox profile to use. If
 *                  null a temporary blank profile is used.
 * @return
 */
public static FirefoxDriver buildFFDriver(String ffProfile) {
    File profileDir;
    if (null == ffProfile) {
        profileDir = Files.createTempDir();
        profileDir.deleteOnExit();
    } else {
        profileDir = new File(ffProfile);
    }
    System.out.println("com.galois.fiveui.drivers: using directory for Firefox profile: " + profileDir);
    FirefoxProfile profile = new FirefoxProfile(profileDir);

    String ffBinaryPath = System.getProperty(FIREFOX_BIN_PATH);

    FirefoxDriver driver;
    if (null == ffBinaryPath) {
        System.err.println("WARNING: Running essentially random version of Firefox!");
        System.err.println("         set a path to firefox with -D" + FIREFOX_BIN_PATH + "=<path to firefox>");
        driver = new FirefoxDriver(profile);
    } else {
        FirefoxBinary binary = new FirefoxBinary(new File(ffBinaryPath));
        driver = new FirefoxDriver(binary, profile);
    }

    return driver;
}

From source file:com.github.mike10004.seleniumhelp.UnitTests.java

License:Apache License

public static Supplier<FirefoxBinary> createFirefoxBinarySupplier() {
    String executablePath = getFirefoxExecutablePath();
    if (Strings.isNullOrEmpty(executablePath)) {
        return FirefoxBinary::new;
    } else {// w  w  w .  j a v a  2s .c o m
        File executableFile = new File(executablePath);
        if (!executableFile.isFile()) {
            throw new RuntimeException("not found: " + executablePath);
        }
        if (!executableFile.canExecute()) {
            throw new RuntimeException("not executable: " + executableFile);
        }
        return () -> new FirefoxBinary(executableFile);
    }
}