Thursday, September 9, 2010

Web application Automation testing –Part4 – Automation Library

Understanding Automation Library


In My previous post we got the concept of PageObject . Now designing a single page object is not going to do all the required tricks that we really needed in test automation. Website is collection of different pages with data flowing from one page to another. So we need to establish the connection between different pages so that we can go from one page to other without losing a data and can use data entered on one page to be validated on other page and so on.

Please have a look at the block diagram of the framework





Above is the block diagram I have created for test automation framework, Here Webdriver API sits in the bottom. Automation library is nothing but the wrapper written over Webdriver API to perform the required actions as required by our website.

Using our automation library QA or dev team can write their test fixtures and we can make it test driven by providing a test data in a file. I generally prefer a XML files to store test data because those are simple and can be easily read and write using java or .NET code.

I have created a common functions library which is generally used for writing custom functions like database read / write, File reader, Reporter etc.

Now what exactly the automation library is???

Automation library is nothing but the collection of all page objects with their defined functionalities in it.

But how these pages will be linked to each other??

So the answer is whenever we are writing a function in a pageobject for navigating to some other page and if we want to perform some actions on the page where we are landing then our current function must return the object of the next page where it is navigating the control

Below is the snippet of the code.

public LogInPage NavigateToGmailLoginPage()

{

browser.FindElement(By.LinkText("Gmail")).Click();

return new LogInPage(this);

}

Here the return value of the navigate Function is the Object of the LoginPage where it is landing

Once you get the object of the login page now you can use it to perform further actions on that page.

End test fixture should look like

//Test Case 1

public void TestValidLogin()

{

HomePage p = new HomePage("test1", "Test", "IE", "HomePage");

LogInPage p1 = p.NavigateToGmailLoginPage();

p1.LogIn("username","Password);

//Insert Assert here to check the exact output p1.LogOut();

}

//Test Case 2

public void TestInvalidLogin()

{

HomePage p = new HomePage("test1", "Test", "IE", "HomePage");

LogInPage p1 = p.NavigateToGmailLoginPage();

p1.LogIn("username","InvalidPassword);

//Insert Assert here to check the exact output p1.LogOut();

}

In this way we can achieve a good automation framework which can be enhanced at any moment of time. The main advantage of this automation framework is your scripts will remain untouched even if there is any change in the page like if a link is changed to button still you wrapper function will remain the same only the inside find element method will get changed.

This is just a starter for you!! You can always make it more flexible and robust as per your need J

This is all about automation framework designing I can think of as of now!!!