Selective Decoding and the Source Code

This is follow up post on Selective Decoding, my master thesis project. You can get the main idea of selective decoding at previous post. This post simply provides some resources related to the project.

I’ve upload two videos to YouTube demonstrating how selective decoding works.

Selective Decoding without Zoom
Selective Decoding with Zoom

The source code for the Android player is available at github. You can find it at https://github.com/roman10/AndZop. Note that there are multiple branches, with the master branch containing the stable code and other branches having various experiments I did.

There is a research paper about selective decoding, available at http://www.comp.nus.edu.sg/~ooiwt/papers/pcm12-zoomable.pdf. If you want more detailed info, you can refer to my master thesis at http://www.roman10.net/src/thesis.pdf.

This project is part of the jiku project. There’re lots of other interesting stuff going on under the jiku project. We can refer to http://liubei.ddns.comp.nus.edu.sg/jiku/ for more information. 

Selenium: Reuse the HTTP Session in Firefox Browser

Selenium is a browser automation framework, which can be used for automating web application testing, crawling web pages etc. For a quick start guide, one can refer to http://code.google.com/p/selenium/wiki/GettingStarted.

This post gives an example of reusing an existing HTTP session in firefox browser with Selenium. The example is based on Selenium version 2.26.0.

The basic idea is to check if there’s an existing Firefox browser started by Selenium, if so, we simply connect to it and reuse the browser session.

Below is an example of using the same Firefox browser session for requesting 10 pages from Google Play. Note that the code does not work for existing Firefox browser window not started by Selenium.

import java.io.IOException;

import java.net.InetSocketAddress;

import java.net.Socket;

import java.net.URL;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

 

public class FirefoxDriverReuseExample {

    private static String ROOT_URL = "https://play.google.com/store/apps/details?id=";

    private static String[] appIds = new String[]{

        "roman10.media.converter",

        "Apna.LiveIndianTV",

        "app.fastfacebook.com",

        "app.FinalFutureSMS",

        "app.freepumpkintoss",

        "app.indianfinancemarketnews",

        "app.onetouchdrawLite",

        "app.visualjapan.pachisegu",

        "appinapp.mgong.proj.mannerlock",

        "appinventor.ai_giovannigemma2.origilale"

    };

    

    private static void retrieveAllUrls() {

        WebDriver driver = null;

        int cnt = 0;

        boolean isRunning = false;

        for (int i = 0; i < appIds.length; ++i) {

            String url = ROOT_URL + appIds[i];

            try {

                //see if the web driver is running

                final Socket s = new Socket();

                s.connect(new InetSocketAddress("localhost", 7055)); 

                s.close(); 

                isRunning = true; 

            } catch (IOException io) {

                isRunning = false;

            }

            if (!isRunning) {

                //start a new session

                driver = new FirefoxDriver();

                driver.get(url);

                String pageSource = driver.getPageSource();

                System.out.println(pageSource);

                cnt++;

            } else {

                //reuse the existing session

                try {

                    if (null == driver) {

                        //if not initialized yet, connect

                        driver = new RemoteWebDriver(new URL("http://localhost:7055/hub"), DesiredCapabilities.firefox()); 

                    }

                    driver.get(url);

                    String pageSource = driver.getPageSource();

                    System.out.println(pageSource);

                    cnt++;

                } catch (Exception e) {

                    e.printStackTrace();

                }

            }

        }

        System.out.println("Total No. of requests and responses: " + cnt);

    }

    

    public static void main(String[] args) {

        retrieveAllUrls();

    }

}

Note that I used the selenium-server-standalone-2.26.0.jar as referenced library for the code. It can be found at http://code.google.com/p/selenium/downloads/list.

References:

Selenium project page: http://code.google.com/p/selenium/