Saturday, 13 August 2016

Basic Concepts of Automation Testing

Hello, Guys welcome to let me introduce myself to you.

I am Prosenjit Majumder working professional in a beautiful city Bangalore India. I basically hail from City Of Joy, Kolkata.

I have passion towards automation testing since last 6-7 years I started with Selenium then I got chance to work with other tools like Maven, Ant, Git, GitHub, Jenkins, Sikuli etc.

Today let us see some of the basic concepts of Automation Testing:

Q1-What is Automation Testing
Answer- When you talk about Software testing or Quality assurance of any product it means we have to deliver our application bug free it means no defect in our application. In order to achieve quality we perform testing in our application it means we perform several test case it can be functional test cases and nonfunctional test cases also.

In order to save our time and resource we can automate manual test cases, which save human effort and time as well.

Scenario – If we need to test same scenario 100 times manually and each time we are checking the same result then better to automate this test case and run it number of times and verify the result.

We have different tools available in the market, which gives us the liberty to automate our application

Q2- When Automation testing should be performed?
Answer- We can perform automation testing in our day to day testing activities it means when we have to execute some test case on regular basics then better to automate that test cases

Majorly we perform automation testing for regression testing, smoke testing and sanity testing as well.
Scenario- If you have 50 scenario that you have to execute on daily basis and you will be testing the same scenario for next couple of releases as well then manually running these test cases will be tedious task so here you can adopt automation testing.
Q3-Which test case cannot be automated?
1-This is very important and interesting question as well that which test cases cannot be automated, my answer is you should avoid test cases which is changes very frequently it means even if you will automate that test case next time it will fail because application feature will change so better to choose test case which is stable.
2- We should not automate test cases which has manual interaction like enter authorization code, capcha code etc.
Selenium introduction
Answer- Selenium is Open source Web Automation tool which was designed by Thought Works in 2004, It started by Selenium IDE then Selenium RC which is also known as Selenium 1 then Selenium Web driver which is also known as Selenium 2 Best selenium Training Institute in Bangalore
Selenium is very popular now days because of many reasons
·       It is open source tool, which means we do not have to purchase any license for this. We can download from their officially website and we can use.

·       It support many languages like Java, Java Script, C#, Python, Ruby etc.

·       We can perform cross browser testing as well. Selenium Webdriver support almost all browser which their latest version like Firefox, Chrome, IE, Safari, Opera etc.

·        It support the entire platform like Windows, UNIX, Linux, Apple etc.

·      Recently Selenium has introduced mobile testing as well, now we can automate Android testing using Selendroid, IPhone testing using appium and many more.

·      Selenium having compatibility with many tools well some example are AutoIT, Jenkins, Sikuli, Testng, Junit etc.                                                                                                               

Browser methods in WebDriver

Web Driver, The main interface to use for testing, which represents an idealised web browser. The methods in this class fall into three categories:

  1. Control of the browser itself
  2. Selection of Web Elements
  3. Debugging aids

Key methods are get(String), which is used to load a new web page, and the various methods similar to findElement(By), which is used to find WebElements. In this post we are going to learn browser controlling methods.


Load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete. it is best to wait until this timeout is over, since should the underlying page change whilst your test is executing the results of future calls against this interface will be against the freshly loaded page.


//Initialising driver
 WebDriver driver = new FirefoxDriver();
 //setting timeout for page load
 driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
 //Call Url in get method


Get a string representing the current URL that the browser is looking at. It returns the URL of the page currently loaded in the browser.


//Getting current url loaded in browser & comparing with expected url
 String pageURL = driver.getCurrentUrl();
 Assert.assertEquals(pageURL, "");


It returns the title of the current page, with leading and trailing whitespace stripped, or null if one is not already set.


//Getting current page title loaded in browser & comparing with expected title
 String pageTitle = driver.getTitle();
 Assert.assertEquals(pageTitle, "Google");


Get the source of the last loaded page. If the page has been modified after loading (for example, by Javascript) there is no guarantee that the returned text is that of the modified page.


//get the current page source
     String pageSource = driver.getPageSource();


Close the current window, quitting the browser if it's the last window currently open. If there are more than one window opened with that driver instance this method will close the window which is having current focus on it.


//Close the current window


Quits this driver, closing every associated window. After calling this method we can not use any other method using same driver instance.


//Quit the current driver session / close all windows associated with driver

These are all very useful methods available in Selenium 2.0 to control browser as required.  

Different Types of Locators to identify UI elements

Selenium uses different types of locators to identify the UI elements on the page.

The following is the list of locators based on the priority and recommendations to use:

1. ID
2. Name
3. Class Name
4. Link
5. CSS
6. XPath

i.e. Theoretically, you have to follow the below steps while finding the Locator for the selected UI element:
  1. Locate the UI element by using its Unique ID else you have to go to the next step
  2. Locate the UI element by using its Unique Name else you have to go to the next step
  3. Locate the UI element by using its Unique Class Name else you have to go to the next step
  4. Locate the UI element by using its Unique Link else you have to go to the next step
  5. Locate the UI element by using CSS selector locator else you have to go the next step
  6. Locate the UI element by using its XPath locator
Practically, most of the people will try to locate the UI element using a unique ID. If  unique ID value is not available, they 
will use CSS selector locator followed by XPath locator.

Why different types of locators are used instead of having only one kind of locator to identify the UI elements ?
While building the application code, it is seen as a good practice to make sure that every element you need to interact with has an ID attribute and a Name attribute. Unfortunately, developers may not have provided ID or Name attributes to some elements in your application. So identifying those kind of elements may not be possible if we don't use the other type of locators like XPath or CSS selector locators.