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

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

Introduction

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

Prototype

private FirefoxDriver(FirefoxDriverCommandExecutor executor, FirefoxOptions options) 

Source Link

Usage

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;/*from www. j  a v a 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  ww .  ja  v a  2  s.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  w  w  . j a va2  s .  c  o  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();//  w ww  .j a v a2 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.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;
        }/*from w ww.  ja va 2  s.  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.example.calculator.CalculatorIntegrationTest.java

License:Apache License

@Before
public void openWebDriver() {
    testServerPort = System.getProperty("test.server.port", "8080");
    String display = System.getProperty("test.xvfb.display", null);
    FirefoxBinary firefox = new FirefoxBinary();
    if (display != null) {
        firefox.setEnvironmentProperty("DISPLAY", display);
    }//from   ww w . j ava 2 s .co  m
    webDriver = new FirefoxDriver(firefox, null);
}

From source file:com.googlesites.CaptchaTest.java

@Test(groups = "sikuli")
public void createSite() {

    FirefoxProfile profile = new FirefoxProfile();
    driver = new FirefoxDriver(new FirefoxBinary(new File(Config.getPropertyValue("firefoxLocation"))),
            profile);//from  w ww .j  a v a  2  s  . co  m
    WebDriverInstance wdi = new WebDriverInstance();
    wdi.setCurrentDriver(driver);
    driver.manage().window().maximize();
    sitesURLs.add("blanksitezzz");
    sitesURLs.add("intranetlintranetl111");
    sitesURLs.add("alf12opitds");
    sitesURLs.add("soccttttttttttttttttttttt");
    overview = new Overview(driver);
    overview.navigateToOverviewPage();
    loginPage = overview.navigateToLogin();
    sites = loginPage.logIn("johnjjones02@gmail.com", "MyPasswordIsC0@l");
    sites.verifyTheOnlySitesAre(sitesURLs);
    createSite = sites.clickOnCreateButton();
    createSite.createSite("Gollum1124", "siteyy1");
    driver.close();
}

From source file:com.googlesites.IntranetTests.java

@Test(groups = "sikuli", enabled = false)
public void intranetTest() {
    driver = new FirefoxDriver(new FirefoxBinary(new File(Config.getPropertyValue("firefoxLocation"))),
            profile);/*from  ww w.j  a v a  2 s.c  om*/
    driver.manage().window().maximize();
    WebDriverInstance wdi = new WebDriverInstance();
    wdi.setCurrentDriver(driver);
    overview = new Overview(driver);
    overview.navigateToOverviewPage();
    loginPage = overview.navigateToLogin();
    sites = loginPage.logIn("johnjjones02@gmail.com", "MyPasswordIsC0@l");
    site = sites.navigateToSite("intranetlintranetl111");
    intranet = new IntranetPage(driver);
    intranet.navigateTo("Documents");
    sikuli.find("Documents.png", "Documents page", 0.7);
    intranet.navigateTo("Directory");
    sikuli.find("Directory.png", "Directory page", 0.7);
    intranet.navigateTo("Discussion");
    sikuli.find("Discussion.png", "Discussion page", 0.7);
    intranet.navigateTo("Announcements");
    sikuli.find("Announcements.png", "Announcements page", 0.7);
    intranet.navigateTo("Sitemap");
    sikuli.find("Sitemap.png", "Sitemap page", 0.7);
    driver.close();
}

From source file:com.googlesites.IntranetTests.java

@Test(groups = "sikuli", priority = 1)
public void navigateToIntranet() {

    driver = new FirefoxDriver(new FirefoxBinary(new File(Config.getPropertyValue("firefoxLocation"))),
            profile);//from  w w  w  .  j  a  v a  2s  .  c o m
    driver.manage().window().maximize();
    WebDriverInstance wdi = new WebDriverInstance();
    wdi.setCurrentDriver(driver);
    overview = new Overview(driver);
    overview.navigateToOverviewPage();
    loginPage = overview.navigateToLogin();
    sites = loginPage.logIn("johnjjones02@gmail.com", "MyPasswordIsC0@l");
    site = sites.navigateToSite("intranetlintranetl111");
    intranet = new IntranetPage(driver);
}

From source file:com.googlesites.MapsTests.java

@Test(priority = 1, groups = "sikuli")
public void navigateToMaps() {
    driver = new FirefoxDriver(new FirefoxBinary(new File(Config.getPropertyValue("firefoxLocation"))),
            profile);/*from   ww w .j a va2 s .co m*/
    driver.manage().window().maximize();
    WebDriverInstance wdi = new WebDriverInstance();
    wdi.setCurrentDriver(driver);
    overview = new Overview(driver);
    overview.navigateToOverviewPage();
    loginPage = overview.navigateToLogin();
    sites = loginPage.logIn("johnjjones02@gmail.com", "MyPasswordIsC0@l");
    maps = sites.navigateToMaps();

}