Google is moving everything to web, and taking over the world. I just opened my Google Voice account and what awsome concept. Imagine what this would do to a small business and single owner businesses.
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.
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!
Recent Comments