Posted: December 15th, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled, Selenium | Tags: Java, Selenium | 4 Comments »
Lately I have been adding improvements to the framework that I have build using selenium rc, JUnit, Java, and Xpath. While adding more functions I wanted to add a method to handle ajax. The idea was to wait until all the ajax action complete in a page. Selenium api has a waitForCondition method. Method accept a script, and time out.
public void waitForCondition(java.lang.String script,
java.lang.String timeout)
Our application uses Prototype ajax library. so I used waitForCondition() from selenium api, and implement the following method.
public void waitForAjax() {
super.waitForCondition("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0;",
SeleniumDefaultProperties.getResourceAsStream("default.pageload.timeout"));
}
I have added
.properties file to handle all the server settings and timings related to our test automation framework. In above method timing is invoked from that properties file.
Posted: November 15th, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled | Tags: Java | No Comments »
I was just reading upcoming changes in Java 7, and I was very excited. One thing I found out that java.io.File getting a make over.
Here are the things that going to be added to the Java 7 release,
- FileRef – represents file object in system
- Path – extends FileRef, binds a file to a system-dependent location
- FileSystem – interface to file system FileStore – underlying storage system
I am planning to put a post once I find an example using the new api.
Posted: November 4th, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled, My MacBook Pro, Technology | Tags: Java, MacBook Pro | No Comments »
I was doing my regular daily doze of technical reading and stumble upon Jeff Bonwick’s blog. Sounds like deduplication is a great concept. I think this might be very helpful reducing the size of the repositories. But more than any thing I was thrilled about his previous post. ZFS is available on Snow Leopard. Wow!!!, as you may know from my previous posts, I switch to mac just about a month ago. And I must say somehow my mac book pro able fascinate me in daily basis. And this was another example.
Posted: August 12th, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled, Selenium | Tags: Java, Selenium | No Comments »
Dealing with threads in Java is not the easiest but I was in the process of implementing a custom Java Selenium Framework and I decided “Why not use the help of the ThreadLocal class to ease my pain”. So, this is my attempt to take stab at ThreadLocal class.
Why Did I need to use the ThreadLocal class?
In nutshell, The Selenium Framework I was building designed based upon pages of the web application. ex: Lets say we have login page and then once we login, use get navigated to about page. The framework I built have two separate Java classes to handle function in login page and about page. Since both these classes live from selenium session, I wanted to save the selenium session where each class can freely access the session without session getting passed around back and forth between those class.
Only thing you need to know about my implementation.
As I mentioned, I have created class that extends DefualtSelenium.java (lets call it OurDefaultSelenium.java, this class has method that start the selenium session)
So, just because I think I should use the ThreadLocal class does it mean is it the best mechanism to use..?
Most typical scenario of using ThreadLocal would be as an alternative to an object or resource pool, when we don’t mind creating one object per thread.
So When should I really use the Thread Local
The objects are non-trivial to construct;
An instance of the object is frequently needed by a given thread;
The application pools threads, such as in a typical server (if every time the thread-local is used it is from a new thread, then a new object will still be created on each call!);
Ok enough of lecturing, lets get to the bottom of it, shall we.
I am a big fan of Java generics so this example uses Java 5, Java generics.
Lets call our Class, SeleniumSession make sense right we are dealing with selenium session.
public class SeleniumSession {
private static final Logger log = Logger.getLogger(SeleniumSession.class.getName());
private static ThreadLocal<HashMap<String, OurDefaultSelenium>> session=
new ThreadLocal<HashMap<String, OurDefaultSelenium >>() {
protected synchronized HashMap<String, OurDefaultSelenium > initialvalue() {
return new HashMap<String, OurDefaultSelenium >();
}
};
private static ThreadLocal< OurDefaultSelenium > selenium = new ThreadLocal< OurDefaultSelenium>();
/**
* Get the current selenium session.
* @return
*/
public static OurDefaultSelenium get() {
return selenium.get();
}
Note that there is still a single, static instance of SeleniumSession shared by all threads. But that single instance uses the ThreadLocal variable session, which has a per-thread value. Inside get(), the call to selenium.get() will always operate on our thread-private “instance” of the variable, with synchronization.
Since we are using Java generics, subsequent get() method doesn’t need an explicit cast. (That is, the cast is inserted automatically by the compiler.)
But lets focus our eyes on to <strong>initialValue </strong>method. We actually subclass ThreadLocal and override initialValue() to provide an appropriate object each time a new one is required (i.e. when get() is called for the first time on a particular thread). I know what you thinking, You could add a logic to check the null inside the get() method. Like this,
OurDefaultSelenium ourSelenium = session.get();
if (ourSelenium == null) {
session.set(cal = new DefaultSelenium());
}
return ourSelenium;
But You don’t need to do this since we are overriding ThreadLocal.initialValue() automatically handles this logic and makes our code a bit neater– especially if we’re calling get() in multiple places.
In this implementation I also have methods to set the session and end the selenium session.
/**
* Set the current selenium session.
* @param classInstance
*/
public static void set(OurDefaultSelenium classInstance) {
selenium.set(classInstance);
}
/**
* Method to end the session, should use after the test.
*/
public static void endSession() {
selenium.get().stop();
}
Posted: July 2nd, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled, Selenium | Tags: Data Driven, Java, Selenium | 6 Comments »
Over the past year or two Selenium has taken over many developers hearts. Let me put it in this way, It won most of the Java developers hearts simply because if you are a java developer using Selenium now you can write a test without learning a new language nor using another stupid application developed by HP or any other 3rd party software company.
But some criticize saying that Selenium can not do Data Driven testing. I think its a bogus statement. Prior to this implementation I have used Selenium but I never had the oppertunitity to explore how I can used Dynamic data from csv file to execute in a selenium test.
In my development I decided to use csv file as the input but it doesn’t have to be csv file, I am more comfortable on dealing CSV Files with Java than any other file type so I picked CSV. My target is to create a Selenium Test that takes Username and Password from CSV file and login to web application. Its better you separate Selenium Test to one class and reading data from csv to another class. If you building as a framework I recommend to package is separate. Lets say we have a class call ReadInData.java and my file looks like this,

CSV File with Username & Password
lets write few methods to parse this data. Keep in mind that we need to use this data in the test and any method that does the manipulation should return an Array, a Map, or List with user name and password.I decided to use a HashMap implementation and return a HashMap with username and password.

Next thing is to create two methods, one is that take a single username and password and click the login button to login and other to extract username and password from HashMap and put them in to our previous method.
Use XPath to get respective text boxes and create a simple method as shown below, keep in mind that I am returning an instance of the class. Developers have mix feelings about the chain effect. But here I have used simply because I was planning on developing a framework and who ever use this framework to generate selenium test will have a very easy time on putting a test together with the help of the chain effect.
<a rel="attachment wp-att-304" href="http://anublog.colombounplug.com/?attachment_id=304"><img class="aligncenter size-full wp-image-304" title="MultiUser" src="http://anublog.colombounplug.com/wp-content/uploads/2009/07/MultiUser.jpg" alt="MultiUser" width="1114" height="398" /></a>
<a rel="attachment wp-att-305" href="http://anublog.colombounplug.com/?attachment_id=305"><img class="aligncenter size-full wp-image-305" title="SingleUser" src="http://anublog.colombounplug.com/wp-content/uploads/2009/07/SingleUser.jpg" alt="SingleUser" width="788" height="286" /></a>
Now lets talk about creating a Selenium Test using above class and its methods. You should extend the class that has above methods to create the Junit Base selenium test cases,

So, This clearly shows that Selenium Test can be data driven and its all in the person’s hand who is writing the test. Enjoy!
Posted: May 1st, 2009 | Author: Anuradha Uduwage | Filed under: Facebook, Java Ruled | Tags: Data Mining, Facebook | No Comments »
So far the Our Data Mining Implementation for Facebook Data is going really good, I am currently working on an algorithm to identify 1 and n items sets out of our raw data set using the extraction I build earlier. But I just finished writing a sweet little code to pivot 3 million user records.
Our implementation has a DB.java file that handles all our DB call and direct sql stuff, I know what you thinking we could have use some fancy hibernate but this is fast paced development so we dont have time to work with hibernate stuff.
// connect to the database, any database connection changes should take
// place in DB.java
DB db = new DB();
DB db2 = new DB();
db.init();
db2.init();
Call a DB.java to get disntinct type sub type facebook groups, and dump them in Java String Vector.
// get the type and sub type
Vector<Vector<String>> grpTypeSubType = new Vector<Vector<String>>(
db.getTypeSubType());
// printing all the type sub type pairs as column headers
//System.out.print("UserId, ");
ps1.print("UserId, ");
for (Object object : grpTypeSubType) {
if(!object.toString().equals(null)) {
System.out.print(object.toString() + ",");
ps1.print(object.toString() + ",");
}
}
Here we go fun begins, this loop ran 38 hours and finished the pivoting for 3m records.
// get user id vector and find type and subtype for each userid.
Vector<Long> users = new Vector<Long>(db.getDistinctUID());
ResultSet fbUsers = db.getUsers();
System.out.println();
ps1.println();
System.out.println("Start Pivot..");
while (fbUsers.next()) {
Long userId = fbUsers.getLong(1);
//System.out.print(userId + ",");
ps1.print(userId + ",");
String groupType = null;
String typeSubtype = null;
int count = 0;
for (Vector<String> vs : grpTypeSubType) {
groupType = vs.get(0);
typeSubtype = vs.get(1);
if(groupType != null && typeSubtype != null) {
count = db2.getTypeSubTypeCount(userId, groupType, typeSubtype);
if (count > 0) {
//System.out.print("Y, ");
ps1.print("Y, ");
} else {
//System.out.print("N, ");
ps1.print("N, ");
}
}
}
//System.out.println();
ps1.println();
}
fbUsers.close();
ps1.close();
System.out.println("Done pivot, check the file");
}
You can get more information on our Data Extraction and FB Data Mining implementation at Google Code under GNU General Public License v3. Also you are more than welcome to use multiple Preprocessed data sets that I formatted to fit in applications like Weka etc.
Posted: January 22nd, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled | Tags: Google | 3 Comments »
Thanks to my friend Nayana who is a Googler, I got a new Android Dev Phone. He put a request to send the Android phone that he got as a X’Mass present from Google. Phone directly came from Mountain View. It looks great I love the Graphics and the Android sign at the back of the phone. This is not the T-Mobile version, and I don’t think those graphics are in T-Mobile version of the Android Phone. During Android Developer Challenge I developed few applications but they were not sophisticated enough to be on front line. Hopefully I can use this along with the emulator to build better Android Application. I do have an idea, so let see if I can deliver it this time, but sorry guys I just have to keep it for myself, at least for now…
Here are some pictures, Once again big ups for my boy Nana…
Posted: January 20th, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled, Microsoft | Tags: Microsoft, Travel | 5 Comments »
Sometime in November I saw email which I never expected. Recruiting Organizer from Microsoft email me to find out possible dates for me to fly to Seattle for the Microsoft onsite interview. Her name was Tejpreet and I must say that she was really helpful. When I contacted her, she said that she will be the person who is scheduling my interview dates and other arrangements during my trip to Seattle.
Over the past month or so, we had to over come few confusions related the position that I was planning to apply interms of Internship or full-time position. Only because Microsoft wanted to setup appropriate interview. Once we clear that out, we had to clear out few scheduling conflicts. But Thanks to Tejpreet, all those conflicts were solved and changes were made to satisfy both the parties.
So Yesterday, I got the ticket and hotel details and its final that I will be flying to Seattle Microsoft Office to get interviewed by the Giant in Software World.
One more thing, My recruiter told that I will be getting interviewed by two teams within MSSQL team.
Posted: January 12th, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled | Tags: Java | No Comments »
I recently update my java version to build 11 and first thing I found out that GWT SDK doesn’t have the latest addition from java build to reflect @override.
If you are like me who use eclipse, when you create a method like this.
public class Ex1 implements EntryPoint {
@override
public void onModuleLoad() {
GWT.log("Out Put", null);
final Label myLabel = new Label("Hello World");
RootPanel.get().add(myLabel);
}
}
Eclipse will automatically will add @override which help the compiler to understand the behavior of the method. This is a addition in java 1.6 build 11, But GWT SDK doesn’t have this update so your compiler will cough on you.
Posted: September 6th, 2007 | Author: Anuradha Uduwage | Filed under: Its all about me, Java Ruled | 2 Comments »
I was shocked, excited, and couldn’t believe my eyes. I opened up my email account and there was a email where the subject was saying “Hello From Google”. I thought it was may be from Gmail or some sort of Google maintenance email. I read the email and it was from a Google recruiter who has found my profile. I always thought of applying but never thought that they would find me before I apply to Google. Since I am so fascinated and highly talk about Google among my friends, I started to think this could be one of my friend trying to pull my leg. But it was not, it was really a recruiter from Google who is interest on finding out my experiences for possible hiring.
Recent Comments