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

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

Introduction

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

Prototype

@Override
    public Options manage() 

Source Link

Usage

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  ww  w.ja  v  a 2s  . c o  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.vaadin.testbench.TestBenchDriverTest.java

@Test
public void testTestBenchDriverActsAsProxy() {
    FirefoxDriver mockDriver = createMock(FirefoxDriver.class);
    mockDriver.close();//from   w  w  w.  jav  a 2  s. c om
    expectLastCall().once();
    WebElement mockElement = createNiceMock(WebElement.class);
    expect(mockDriver.findElement(isA(By.class))).andReturn(mockElement);
    List<WebElement> elements = Arrays.asList(mockElement);
    expect(mockDriver.findElements(isA(By.class))).andReturn(elements);
    mockDriver.get("foo");
    expectLastCall().once();
    expect(mockDriver.getCurrentUrl()).andReturn("foo");
    expect(mockDriver.getPageSource()).andReturn("<html></html>");
    expect(mockDriver.getTitle()).andReturn("bar");
    expect(mockDriver.getWindowHandle()).andReturn("baz");
    Set<String> handles = new HashSet<String>();
    expect(mockDriver.getWindowHandles()).andReturn(handles);
    Options mockOptions = createNiceMock(Options.class);
    expect(mockDriver.manage()).andReturn(mockOptions);
    Navigation mockNavigation = createNiceMock(Navigation.class);
    expect(mockDriver.navigate()).andReturn(mockNavigation);
    mockDriver.quit();
    expectLastCall().once();
    expect(((JavascriptExecutor) mockDriver).executeScript(anyObject(String.class))).andStubReturn(true);
    TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class);
    expect(mockDriver.switchTo()).andReturn(mockTargetLocator);
    replay(mockDriver);

    // TestBenchDriverProxy driver = new TestBenchDriverProxy(mockDriver);
    WebDriver driver = TestBench.createDriver(mockDriver);
    driver.close();
    By mockBy = createNiceMock(By.class);
    assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands);
    assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands);
    driver.get("foo");
    assertEquals("foo", driver.getCurrentUrl());
    assertEquals("<html></html>", driver.getPageSource());
    assertEquals("bar", driver.getTitle());
    assertEquals("baz", driver.getWindowHandle());
    assertEquals(handles, driver.getWindowHandles());
    assertEquals(mockOptions, driver.manage());
    assertEquals(mockNavigation, driver.navigate());
    driver.quit();
    assertEquals(mockTargetLocator, driver.switchTo());

    verify(mockDriver);
}

From source file:com.zhao.crawler.util.CookieUtil.java

License:Open Source License

/**
 * csdn??cookies?/*from w  ww . j  a v a  2 s .  c  o m*/
 * 
 * @param username
 *            ??
 * @param password
 *            ?
 * @param geckodriverpath
 *            gecko?https://github.com/mozilla/geckodriver
 * @param savecookiepath
 *            cookies?
 * @throws Exception
 */
public static void firfoxDriverGetCookies(String username, String password, String geckodriverpath,
        String savecookiepath) throws Exception {
    // ???
    System.setProperty("webdriver.gecko.driver", geckodriverpath);
    FirefoxDriver driver = new FirefoxDriver();
    String baseUrl = "http://kaixin65.com/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login";
    // url
    driver.get(baseUrl);
    // ?
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    // ??
    WebElement elemUsername = driver.findElement(By.name("username"));
    WebElement elemPassword = driver.findElement(By.name("password"));
    WebElement btn = driver.findElement(By.className("logging"));
    WebElement rememberMe = driver.findElement(By.id("rememberMe"));
    // ??
    elemUsername.sendKeys(username);
    elemPassword.sendKeys(password);
    rememberMe.click();
    // ???
    btn.submit();
    Thread.sleep(5000);
    driver.get("http://msg.csdn.net/");
    Thread.sleep(5000);
    // ?cookies
    driver.manage().getCookies();
    Set<org.openqa.selenium.Cookie> cookies = driver.manage().getCookies();
    System.out.println("Size: " + cookies.size());
    Iterator<org.openqa.selenium.Cookie> itr = cookies.iterator();

    CookieStore cookieStore = new BasicCookieStore();

    while (itr.hasNext()) {
        Cookie cookie = itr.next();
        BasicClientCookie bcco = new BasicClientCookie(cookie.getName(), cookie.getValue());
        bcco.setDomain(cookie.getDomain());
        bcco.setPath(cookie.getPath());
        cookieStore.addCookie(bcco);
    }
    // ?
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(savecookiepath)));
    oos.writeObject(cookieStore);
    oos.close();

}

From source file:org.asqatasun.sebuilder.tools.FirefoxDriverPoolableObjectFactory.java

License:Open Source License

@Override
public FirefoxDriver makeObject() throws Exception {
    FirefoxBinary ffBinary = new FirefoxBinary();
    if (System.getProperty(DISPLAY_PROPERTY_KEY) != null) {
        Logger.getLogger(this.getClass())
                .info("Setting Xvfb display with value " + System.getProperty(DISPLAY_PROPERTY_KEY));
        ffBinary.setEnvironmentProperty("DISPLAY", System.getProperty(DISPLAY_PROPERTY_KEY));
    }/*from w w  w  .  j a  va 2  s . co m*/
    FirefoxDriver fd = new FirefoxDriver(ffBinary, ProfileFactory.getInstance().getScenarioProfile());
    if (this.implicitelyWaitDriverTimeout != null) {
        fd.manage().timeouts().implicitlyWait(this.implicitelyWaitDriverTimeout.longValue(), TimeUnit.SECONDS);
    }
    if (this.pageLoadDriverTimeout != null) {
        fd.manage().timeouts().pageLoadTimeout(this.pageLoadDriverTimeout.longValue(), TimeUnit.SECONDS);
    }
    return fd;
}

From source file:pawl.webdriver.LocalizedWebDriverProvider.java

License:Apache License

/**
 * Provide new Firefox driver with setup of user language.
 *
 * @return firefox driver//from  ww  w  . j ava2 s  .  c om
 */
protected FirefoxDriver createFirefoxDriver() {
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("intl.accept_languages", getSystemLanguage());
    FirefoxDriver firefoxDriver = new FirefoxDriver(firefoxProfile);
    firefoxDriver.manage().window().maximize();
    return firefoxDriver;
}

From source file:sLinkValidator.LinkValidator.java

License:Apache License

public static void main(String[] args) throws Exception {

    // create the command line parser
    CommandLineParser parser = new DefaultParser();

    // create the options object.
    Options options = new Options();

    Option optPathToGeckoDriver = Option.builder("gecko").longOpt("path-to-gecko")
            .desc("[Mandatory] full path to geckodriver.exe").required(true).hasArg().build();
    Option optAny = Option.builder("a").longOpt("all").desc("Also check \"link\" tag.").required(false).build();
    Option optListFile = Option.builder("f").longOpt("url-list")
            .desc("Specify a text file containing urls to be checked.").required(false).hasArg().argName("FILE")
            .build();/*from w w  w. j a va2 s .c om*/
    Option optHelp = Option.builder("h").longOpt("help").desc("print this help.").required(false).build();
    Option optUid = Option.builder("id").longOpt("user").desc("user id for the BASIC authentication.")
            .required(false).hasArg().argName("USERNAME").build();
    Option optCapture = Option.builder("capture").longOpt("screenshot").desc("take the page capture.")
            .required(false).build();
    Option optSkipElement = Option.builder("skipelement").longOpt("no-element-check")
            .desc("checks given url only, no element in the page is checked.").required(false).build();
    Option optTimeOut = Option.builder("o").longOpt("timeout").desc("timeout second.").required(false).hasArg()
            .argName("TIMEOUT").build();
    Option optPasswd = Option.builder("p").longOpt("password").desc("password for the BASIC authentication.")
            .required(false).hasArg().argName("PASSWORD").build();
    Option optNumThread = Option.builder("T").longOpt("thread")
            .desc("number of thread (must be an integer, less than " + numMaxThread
                    + "). 'AUTO' for available processer num. ")
            .required(false).hasArg().argName("NUM of Thread").build();
    Option optUrl = Option.builder("url").desc("Base URL to be checked.").required(false).hasArg()
            .argName("URL").build();
    Option optSitemapMode = Option.builder("s").longOpt("sitemap").desc("Sitemap mode. Follows only <a> tag.")
            .required(false).argName("SITEMAP").build();
    Option optVerbose = Option.builder("v").longOpt("verbose")
            .desc("verbose output mode. (outputs all result on colsole)").required(false).build();
    Option optVersionNum = Option.builder("V").longOpt("version").desc("print version number.").required(false)
            .build();

    options.addOption(optPathToGeckoDriver); // -gecko, --path-to-gecko
    options.addOption(optAny); // -a, -all
    options.addOption(optListFile); // -f, -url-list
    options.addOption(optHelp); // -h, -help
    options.addOption(optUid); // -id, -user
    options.addOption(optCapture); // -capture, -screenshot
    options.addOption(optSkipElement); // -skipelement, -no-element-check
    options.addOption(optPasswd); // -p, -password
    options.addOption(optNumThread); // -T, -thread
    options.addOption(optTimeOut); // -o, -timeout
    options.addOption(optUrl); // -url
    options.addOption(optSitemapMode); // -s, -sitemap
    options.addOption(optVerbose); // -v, -verbose
    options.addOption(optVersionNum); // -V, -version

    try {

        String strUid = "";
        String strPasswd = "";

        long startTime = System.currentTimeMillis();

        String timeStamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());

        // Parse the command line arguments.
        CommandLine cmdline = parser.parse(options, args);

        // -gecko (mandatory) : full path to the geckodriver binary file (e.g. [win] c:\path\to\geckodriver.exe, [mac] /path/to/geckodriver)
        if (cmdline.hasOption("gecko")) {
            strPathToGeckoDriver = cmdline.getOptionValue("gecko");
            if (strPathToGeckoDriver == null) {
                System.out.println("Specified path to geckodriver.exe was null. Please check again.");
                System.exit(0);
            }
        } else {
            System.out.println(
                    "You Must Specify full path to geckodriver.exe. e.g. '-gecko C:\\Program Files (x86)\\geckodriver\\geckodriver.exe'");
            System.exit(0);
        }

        // -a : any flag. (checks <link> tag's href)
        if (cmdline.hasOption("a")) {
            boolOptAny = true;
        }
        // -h : show help.  or no option specified
        if (cmdline.hasOption("h") || args.length == 0) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(strProgramName, options, true);
            System.exit(0);
        }
        // -id : User ID for BASIC auth.
        if (cmdline.hasOption("id")) {
            strUid = cmdline.getOptionValue("id");
        }
        // -capture : take capture.
        if (cmdline.hasOption("capture")) {
            boolOptScreencapture = true;
        }
        // -skipelement : no element link check within the page.
        if (cmdline.hasOption("skipelement")) {
            boolOptSkipElement = true;
        }
        // -p : password for BASIC auth.
        if (cmdline.hasOption("p")) {
            strPasswd = cmdline.getOptionValue("p");
        }
        // -o : timeout second.
        if (cmdline.hasOption("o")) {
            numTimeoutSec = Integer.parseInt(cmdline.getOptionValue("o")) / 2;
        }
        // -s : sitemap Mode (follows only <a> tag).
        if (cmdline.hasOption("s")) {
            boolOptSitemapMode = true;
        }
        // -T : num of thread.
        if (cmdline.hasOption("T")) {
            if (cmdline.getOptionValue("T").equalsIgnoreCase("auto")) {

                numThread = Runtime.getRuntime().availableProcessors();
                if (numThread > numMaxThread) {
                    numThread = numMaxThread;
                }

            } else {
                try {
                    numThread = Integer.parseInt(cmdline.getOptionValue("T"));
                    if (numThread > numMaxThread) {
                        System.err.println("Please specify the number less than " + numMaxThread + ".");
                        HelpFormatter formatter = new HelpFormatter();
                        formatter.printHelp(strProgramName, options, true);
                        System.exit(0);
                    }
                } catch (NumberFormatException e) {
                    System.err.println(e.getMessage());
                    System.err.println("Thread number must be an integer (less than " + numMaxThread + ").");
                    HelpFormatter formatter = new HelpFormatter();
                    formatter.printHelp(strProgramName, options, true);
                    System.exit(0);
                }
            }
        }
        // -V : show version
        if (cmdline.hasOption("V")) {
            System.out.println(strProgramName + " : Version " + strVersionNum + ".");
            System.exit(0);
        }
        // -v : verbose mode flag
        if (cmdline.hasOption("v")) {
            boolOptVerbose = true;
        }

        // illegal combination of options.
        if (cmdline.hasOption("f") && cmdline.hasOption("url")) {
            System.err.println("Cannot specify \"-url\" and \"-f\" option at the same time.");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(strProgramName, options, true);
            System.exit(0);
        }
        if (cmdline.hasOption("a") && cmdline.hasOption("skipelement")) {
            System.err.println("Cannot specify \"-a\" and \"-skipelement\" option at the same time.");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(strProgramName, options, true);
            System.exit(0);
        }
        if (cmdline.hasOption("a") && cmdline.hasOption("s")) {
            System.err.println("Cannot specify \"-a\" (any) and \"-s\" (sitemapmode) option at the same time.");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(strProgramName, options, true);
            System.exit(0);
        }
        if (cmdline.hasOption("skipelement") && cmdline.hasOption("s")) {
            System.err.println(
                    "Cannot specify \"-skipelement\" and \"-s\" (sitemapmode) option at the same time.");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(strProgramName, options, true);
            System.exit(0);
        }
        if (!cmdline.hasOption("f") && !cmdline.hasOption("url")) {
            System.err.println("Either \"-f\" or \"-url\" must be specified.");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(strProgramName, options, true);
            System.exit(0);
        }

        // in case given file of URL lists or given root url
        if (cmdline.hasOption("f") || cmdline.hasOption("url")) {

            // (attention)
            // This software does not support Chrome and InternetExplorer
            // since they cannot take full page screenshot.

            // Chrome
            //System.setProperty("webdriver.chrome.driver", "some/path/to/chromedriver");
            //WebDriver browserDriver = new ChromeDriver();

            // InternetExplorer
            //System.setProperty("webdriver.ie.driver", "some/path/to/IEDriverServer");
            //DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
            //ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
            //WebDriver browserDriver = new InternetExplorerDriver(ieCapabilities);
            //WebDriver browserDriver = new InternetExplorerDriver();

            // (note)
            // java.io.File doesn't represent an open file, it represents a path in the filesystem. 
            // Therefore having close method on it doesn't make sense.
            File f_ResultDir = new File("." + File.separator + "results");
            if (!f_ResultDir.exists()) {
                f_ResultDir.mkdir();
            }

            strFnameOk = "healthy_links-" + timeStamp + ".csv";
            strFnameError = "broken_links-" + timeStamp + ".csv";
            sttFNnameExternalLink = "external_links-" + timeStamp + ".csv";
            strFnameExceptions = "exceptions-" + timeStamp + ".txt";

            f_out_ok = new FileOutputStream("results" + File.separator + strFnameOk, true);
            f_out_error = new FileOutputStream("results" + File.separator + strFnameError, true);
            f_out_externalLinks = new FileOutputStream("results" + File.separator + sttFNnameExternalLink,
                    true);
            f_out_exceptions = new FileOutputStream("results" + File.separator + strFnameExceptions, true);

            String strCsvHeaders = "Source" + "," + "Type" + "," + "Destination" + "," + "Status" + ","
                    + "\"Status Code\"" + "," + "\"Alt text\"" + "," + "Anchor";

            new PrintStream(f_out_ok).println(strCsvHeaders);
            new PrintStream(f_out_error).println(strCsvHeaders);
            new PrintStream(f_out_externalLinks).println(strCsvHeaders);

            FileOutputStream f_out_dequecontents = null;
            ExecutorService executorService = Executors.newFixedThreadPool(numThread);

            String url = "";

            try {

                f_out_dequecontents = new FileOutputStream(
                        "results" + File.separator + "browsed_pages-" + timeStamp + ".csv", true);
                new PrintStream(f_out_dequecontents).println("URL,\"Response Code\", \"Response Message\"");

                if (cmdline.hasOption("f")) {
                    // given file of url lists

                    boolRunAsBFSSearch = false;

                    String urlListFile = cmdline.getOptionValue("f");

                    File f = new File(urlListFile);
                    if (!f.exists() || f.isDirectory()) {
                        System.err.println("The specified file \"" + urlListFile + "\" does not exist.");
                        System.exit(0);
                    }

                    BufferedReader f_in = new BufferedReader(new FileReader(urlListFile));

                    while ((url = f_in.readLine()) != null) {
                        deque.addLast(url);
                    }

                    f_in.close();

                } else if (cmdline.hasOption("url")) {
                    // root url was given

                    //BFS
                    boolRunAsBFSSearch = true;
                    strRootURL = cmdline.getOptionValue("url");

                    //stack.push(strRootURL);
                    deque.add(strRootURL);
                    new PrintStream(f_out_dequecontents).println("[Root URL] is : " + strRootURL + "\n");

                }

                int bdCnd = numThread;
                while (bdCnd > 0) {
                    System.setProperty("webdriver.gecko.driver", strPathToGeckoDriver); // for Selenium 3 and FF 50+
                    FirefoxDriver browserDriver_tmp = new FirefoxDriver();
                    browserDriver_tmp.manage().timeouts().pageLoadTimeout(numTimeoutSec, TimeUnit.SECONDS);
                    browserDriver_tmp.manage().timeouts().implicitlyWait(numTimeoutSec, TimeUnit.SECONDS); // (note) want to set to 120 second but somehow, it waits (second * 2) second. Bug?
                    browserDriver_tmp.manage().timeouts().setScriptTimeout(numTimeoutSec, TimeUnit.SECONDS);

                    dqBrowserDrivers.addLast(browserDriver_tmp);

                    bdCnd--;
                }

                // run thread(s).
                //while(!stack.isEmpty()) {
                while (!deque.isEmpty()) {

                    if (numThread == 1) {
                        // In case numThread is 1, perform the check by the safest way.

                        url = deque.pop();

                        //new PrintStream(f_out_dequecontents).println(url);

                        // obtain http response code
                        ResponseDataObj respData = RunnableLinkChecker.isLinkBroken(new URL(url), strUid,
                                strPasswd);
                        new PrintStream(f_out_dequecontents).println(
                                "\"" + url.replaceAll("\"", "\"\"") + "\"" + "," + respData.getRespCode() + ","
                                        + "\"" + respData.getRespMsg().replaceAll("\"", "\"\"") + "\"");

                        RunnableLinkChecker runnable = new RunnableLinkChecker(
                                Integer.toString(numBrowsedPages) + "_" + timeStamp, url, strUid, strPasswd,
                                boolRunAsBFSSearch);

                        Thread thread_1 = new Thread(runnable, Integer.toString(numBrowsedPages));
                        thread_1.start();
                        thread_1.join();

                        numBrowsedPages++;

                    } else {

                        int numThreadCnt = numThread;
                        int numArrSize = (numThread <= deque.size()) ? numThread : deque.size();
                        List<Callable<Object>> todo = new ArrayList<Callable<Object>>(numArrSize);

                        while (!deque.isEmpty() || (numThreadCnt > 0 && deque.size() >= numThreadCnt)) {

                            url = deque.pop();

                            // new PrintStream(f_out_dequecontents).println(url);

                            // obtain http response code
                            ResponseDataObj respData = RunnableLinkChecker.isLinkBroken(new URL(url), strUid,
                                    strPasswd);
                            new PrintStream(f_out_dequecontents).println("\"" + url.replaceAll("\"", "\"\"")
                                    + "\"" + "," + respData.getRespCode() + "," + "\""
                                    + respData.getRespMsg().replaceAll("\"", "\"\"") + "\"");

                            RunnableLinkChecker runnable = new RunnableLinkChecker(
                                    Integer.toString(numBrowsedPages) + "_" + timeStamp, url, strUid, strPasswd,
                                    boolRunAsBFSSearch);
                            //executorService.execute(runnable);
                            todo.add(Executors.callable(runnable));

                            numBrowsedPages++;
                            numThreadCnt--;
                        }

                        List<Future<Object>> futures = executorService.invokeAll(todo);
                        if (boolOptVerbose) {
                            for (Future<Object> future : futures) {
                                if (future.get() == null) {
                                    System.out.println("future.get() is null. The futre object is "
                                            + future.toString() + " .");
                                    new PrintStream(f_out_exceptions)
                                            .println("future.get() is null. The futre object is "
                                                    + future.toString() + " .");
                                } else {
                                    new PrintStream(f_out_ok)
                                            .println("future.get = " + future.get().toString());
                                }
                            }
                        }
                        numThreadCnt = numThread;

                    }

                }
                if (!executorService.isShutdown()) {
                    executorService.shutdown();
                    while (!executorService.awaitTermination(600, TimeUnit.SECONDS)) {
                        ;
                    }
                }

                //new PrintStream(f_out_dequecontents).println("Total Browsed Pages = " + numBrowsedPages);
                PrintStream printStream = new PrintStream(f_out_dequecontents);
                printStream.println("Total Browsed Pages = " + numBrowsedPages);
                printStream.close();

                new PrintStream(f_out_dequecontents).println(" ");

            } finally {
                try {
                    f_out_dequecontents.close();
                } catch (Exception e) {
                }
            }

            long endTime = System.currentTimeMillis();
            long differenceTime = endTime - startTime;

            System.out.println("It took " + TimeUnit.MILLISECONDS.toSeconds(differenceTime) + " seconds.");
            System.out.println("Total healthy Links = " + numHealthyLink);
            System.out.println("Total broken Links = " + numInvalidLink);
            System.out.println("Total Exceptions = " + numExceptions);
            System.out.println("Total External Links = " + numExternalLinks);
            System.out.println("Total Browsed Pages = " + numBrowsedPages);

            new PrintStream(f_out_error).println("Total broken Links = " + numInvalidLink);
            new PrintStream(f_out_error).println(" ");
            f_out_error.close();

            new PrintStream(f_out_ok)
                    .println("It took " + TimeUnit.MILLISECONDS.toSeconds(differenceTime) + " seconds.");
            new PrintStream(f_out_ok).println("Total healthy Links = " + numHealthyLink);
            new PrintStream(f_out_ok).println(" ");
            f_out_ok.close();

            new PrintStream(f_out_externalLinks).println("Total External Linkis = " + numExternalLinks);
            new PrintStream(f_out_externalLinks).println(" ");
            f_out_externalLinks.close();

            new PrintStream(f_out_exceptions).println("Total Exceptions = " + numExceptions);
            new PrintStream(f_out_exceptions).println(" ");
            f_out_exceptions.close();

        }

    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("BrokenLinkChecker", options);
        System.exit(0);
    } finally {

        while (!dqBrowserDrivers.isEmpty()) {
            FirefoxDriver browserDriver = dqBrowserDrivers.pop();
            browserDriver.close();
        }

        OS = System.getProperty("os.name");
        // cleanup the geckodriver in case Windows
        if (OS.startsWith("Windows")) {
            Runtime.getRuntime().exec("taskkill /F /IM geckodriver.exe /T");
        }

    }

}