Thursday, December 16, 2010

A Simple Test using SWTBOT !!

SWTBOT was introduced to us in 2008 during a DemoCamp in Bangalore. Thanks to Ketan, the mastermind behind it. Ever since that i have always been wanting to use it. Finally i did get the chance.

I installed SWTBOT Plugins on my Helios Version of Eclipse and ran the example explained in Screencast A 5 minute quick quick tutorial on how to get started with swtbot. In this example they close the Welcome Window, open the Console from ShowView Shortcut Menu and then Close Console.

When i ran this test, it failed as i was in Resource Perspective and Console is not available on the ShowView Shortcut Menu in Resource Perspective. This is when i got curious on further evaluation and open the Console from inside the Show View > Others Menu.
After a few mistakes i got the code working ...


SWTBotMenu windowMenu = bot.menu("Window");
windowMenu.click();
SWTBotMenu showViewMenu = windowMenu.menu("ShowView");
showViewMenu.click();
SWTBotMenu otherMenu = showViewMenu.menu("Other...");
otherMenu.click();
SWTBotTree tree = bot.tree(0);
SWTBotTreeItem tItem = tree.getTreeItem("General").expand();
tItem.getNode("Console").doubleClick();

I just love the API flow. Its so much self explanatory. The API is very similar to documenting the steps of testing a UI. I would love if there is a document also generated when we ran the test case as a Test Description :) It could save a lot of time for a Tester to create a Functional TestCase Document.

0 comments: