Monday, December 13, 2010

Invention of most precise clocks and their precision

During my studies, I knew about Cesium Atomic clock which is used as World Standard to define duration of one second. Today I ready about some more clocks in the science magazine. Here is the summary. Hope this will be helpful to me in keeping my memories and may help others as well.

Cesium Clock: First suggested by Lord Kelvin in 1879.  The first atomic clock was built in 1949 at the U.S. National Bureau of Standards.
  • Principal: It uses photons oscillations(absorption and emission of energy by electrons)
  • Frequency: 9192631770 Hz
  • Accuracy: +/- 1 Second every 100 Million Yrs
  • Number of Atoms used: 10 Million
Strontium Clock: Developed in 2009 at Joint Institute for Laboratory Astrophysics (JILA).
  • Principal:It uses blue lasers to excite Strontium (neutral) atoms in a vacuum chamber.
  • Frequency: 45,000 times higher than Cesium Clock ( 450 Trillion Hz)
  • Accuracy: +/- 1 Second every 300 Million Yrs
  • Number of Atoms used: 2000

Mercury Logic Clock: Developed in 2009 at National Institute of Standards and Technology.
  • Principal: It uses lasers to excite mercury atom.
  • Frequency: 4,000 times higher the Cesium Clock (~ 40 Billion Hz)
  • Accuracy: +/- 1 Second every 1 Billion Yrs
  • Number of Atoms used: 1
Quantum Logic Clock: Developed in February 2010 at National Institute of Standards and Technology. Currently this is considered as the most precise clock in the world.
  • Principal: It uses lasers to excite Aluminium atom and Beryllium to report at absolute Zero temperature.
  • Frequency: 100,000 times higher the Cesium Clock (~ 1 Quadrillion Hz)
  • Accuracy: +/- 1 Second every 4 Billion Yrs
  • Number of Atoms used: 2
Scientists are continuously working on to redefine the precision of the measurable time. The results are not only fascinating but helpful too. They help in many great ways in learning Cosmology and understanding the Physics even better than before.

Sunday, December 5, 2010

UI Test automation using Watij, Webspec : Handling ModalDialogs

Since long I have been trying a complete & cheap (free) tool to automate the UI based testing. Since when I learnt about automated testing , I knew about screen recording based test technologies such as Winrunner & HP QuickTest Professionalwhich also supports scripting using a proprietary Test Script Language(TST). Though QuickTest Professional serves most of the purpose I was looking for, but I didn't like it because of two primary reasons. First being its high license cost and second its proprietary software which needs to be installed on developer's/tester's PC.

I kept searching for better solutions as per my needs (free/cheap solution) and got a lot of hope when I first learnt about recording based UI testing supported by Selenium, I was very excited. Later Selenium started supporting script based test scenario creation which was a big aid to create the automated test cases. Later I learnt about about Java based test tool Watij. This was a big improvement in the world of UI based automation testing.

Creating test cases in Watij or Selenium is very easy. If you have clear understanding of DOM, it becomes much more simpler. Here are some examples of sample test script statements.

IE ie = new IE();
ie.start("http://yogendrakrsingh.blogspot.com/");
assertTrue(ie.containsText("/MY LEARNINGS/"));

To set some text field value, you can simply write as ie.textField(id,"myTextId").set("My Value");
To click some button, you can simply write as ie.button(value,"My Botton").click();

Similarly in Selenium a simple test script could be as following:

selenium.open("http://yogendrakrsingh.blogspot.com/");
selenium.waitForPageToLoad("1000");
verifyTrue(selenium.isTextPresent("MY LEARNINGS"));

To set some text field value, you can simply write as selenium.type("myTextId", "My Value");
To click some button, you can simply write as selenium.click("myButton");

Though both Selenium and Watij were very easy to use, both were having limitation in handling Modal dialogs. This limitation proved fatal and all my attempts to use either of them(Selenium/Watij) as automated UI test tools became unsuccessful. Some time back, I learnt the trick to handle ModalDialog using Watij vr. 3.2.1. To handle a Modal Dialog in Watij, created a method in watij.runtime.ie.IE java file as below:

    public ModalDialog modalDialogNested() throws Exception { 
      waitUntilReady();
      final OleMessageLoop modalDialogMessageLoop = new OleMessageLoop("modalDialogMessageLoop"); 
      final ModalDialogFinder modalDialogFinder = new ModalDialogFinder((int) hwnd, modalDialogMessageLoop); 
      modalDialogMessageLoop.doStart(); 
      modalDialogMessageLoop.doInvokeAndWait(modalDialogFinder); 
      return new IEModalDialog(modalDialogFinder.getHtmlDocument(), 
                                             modalDialogMessageLoop, modalDialogFinder.getIE()); 
    }

Then another trick is to open a modal dialog in a new Java Thread so that main thread is not in waiting state. This provides you the control to write and execute further UI test script in the modal dialog. Sample test script could be as below:

    ie.frame(id,"testFrame").textField(id, "inpField").set("Hello! Test very success");
        new Thread(new Runnable() {
            public void run() {
                try {
                    ie.button(id,"mybutton").click();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();


        ModalDialog modalDialog = ie.modalDialogNested();
        modalDialog.textField(id, "inpField").set("Hello! test success");
        final Button myButton =  modalDialog.button(id,"mybutton");
        new Thread(new Runnable() {
            public void run() {
                try {
                 myButton.click();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
   
        ModalDialog modalDialogChild = modalDialog.modalDialog();
        modalDialogChild.textField(id, "inpField").set("Hello! Test success ultimate");
        modalDialogChild.button(value, "Close").click();
        modalDialog.button(value, "Close").click();

Thus I was able to overcome the Modal Dialog limitation of Watij and all set to use Watij as complete UI automation test tool.

Webspec is newer version of Watij with more simpler and powerful syntax. This works on IE, Firefox and Safari with platform support of Windows, Linux and Mac. Along with its simpler command based statements, its also supports the power of JQuery.

To perform the above kind of tasks through WebSpec, we can write statements as below:

WebSpec spec = new WebSpec().ie();
spec.open("http://yogendrakrsingh.blogspot.com/");
spec.find("title").with("My Learnings").shouldExist();

To handle the modal dialog in Webspec, you need to implement html dialog listener by following steps below:

com.jniwrapper.win32.ie.Browser browser = spec.getBrowser().getPeer();
browser.setHtmlDialogListener(new MyHtmlDialogListener(){
        public void show(HtmlDialogEvent event){
             HTMLDialog myDialog = event.getDialog();
             HTMLDocument dialogDocument = myDialog.getDocument();
             //perform your steps in the modal dailog document here
        }
});


Webspec is currently in active development. We need to refer their latest release documents to get familiar with latest updates.