Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Testing Models - Understanding V-Model from testing perspective

V-Model is a software development  Model which shows software development life cycle to follow a V shape. V-Model was developed with the intention to cover some of the problems found in waterfall Model with one of the main issue as defect uncovered late in the Software development life cycle.


The main purpose of representing in a V is to show the relationship between each phase of development life cycle with its associated phase in testing. The execution of processes happens in a sequential manner in this model. This is also sometimes called as Verification and Validation Model

During the initial stage, i.e. from requirement to Coding and Implementation are verification phase and then from Coding and Implementation to User Acceptance testing are Validation phases in the model.

Before continuing with understanding the responsibility of testing in various phases of a V-Model, we must distinguish between Verification and Validation.


Objective of Verification is to ensure the product is being built according to requirement .Walk-through, reviews, inspection are some of the activities, whereas objective of Validation is to ensure the product build meets the user requirement. Whereas Verification activities are mostly done during product building process, Validation is done post product is build

Understanding V-Model

Below are the activities performed by testing team during various stages of V-Model.

a. Requirement Analysis

 Testing tasks includes preparation of User Acceptance testing plan to be followed during UAT testing during the first phase of V-Model. Involvement of testing team early in the requirement help understanding the requirement and analyzing gaps and refining requirements based on scenarios identified for User Acceptance testing.   

b. System Design

 Once we have the requirement signed off by the customer, the developer and testers in parallel starts to work on system development design and system test design respectively.

c. Architecture Design

In this phase, test and plans related to integration testing of different modules are created. From development point of view, In this phase, high level design of the system is created starting from dividing requirement into different modules based on functionality and the interaction of modules defined with each other , external world as well as existing modules if the new functionality is an added functionality in the existing system.

d. Module Design

This phase from development point of view defines the low level design of each of the modules.  To ensure each module is working correctly, to test the internal structure of the module, we need to create unit test cases to test units in the module. Unit testing is mostly performed by developers as is mostly related to internal structure and design of modules.
   

e. Coding and Implementation

Next Phase in the V-model is implementation of low level design into code. So in all the above phases of the V-Model, similar to developers, testing phases occurs in parallel and does verification and analysis at each phase and prepares for testing.

f. Unit Testing 

 Once Coding and Implementation is completed, we need to execute unit test to verify the designed has been coded and implemented properly. Units are tested as they are developed. Unit tests prepared during Module designed are executed to unit test the modules individually

g. Integration Testing

Once the modules are unit tested individually, it is the time to test integration of modules with other modules and external systems. Integration test prepared during Architecture design are executed in this phase.

h. System Testing

 Once we have tested the modules followed by Integration of modules and external systems. Next step is to verify whether the system is working properly and as defined in the requirements
    

i. Acceptance Testing

 Once the system is tested properly by QA Team, it is passed on to customer to perform User acceptance test. This can be performed by client or UAT Team designated by client.Please note from  step f. on wards, we started in step a. to e., the necessary test preparation and analysis tasks.
  

Conclusion  On a whole, V-Model is a much disciplined Model with salient feature including testing starting as early as possible from requirement phase. Requirements are clear and properly analyzed by different perspective, i.e. business analysts, testers and developers. This model has shortcomings in case of some requirement changes in between the software development life cycle



Design Patterns in Selenium: An Introduction

Before creating tests in Selenium, we should look for design patterns to be followed in the test. 

Defining Design pattern to be used in automation helps in easier maintenance of the project once the number of tests increases. Design Pattern should be used in such a manner that rework due to of any code changes are minimum, creating new test uses the existing code.


Following are a few strategies or design patterns used in Selenium for making tests easier to create and maintain:

          1. Page Object Model

          2. Using Page Factory in Page object

          3. Loadable components


We will discuss each of the patterns in details in next articles, but to start with, we will brief on the design patterns in this article. 

When we write code for tests in Selenium, we can break down the code in such a manner that code maintenance is better. Suppose we have two tests. One tests for an image visible on home Page post login and another verifies welcome text post logging in the application. 

Writing the same code in two different tests will require code to be changed in two different places in case object property changes in login Page and at times in case we have large number of tests in the test suite, it will take considerable time to fix the automation code. We should refactor the code and create smaller private methods that are used in different tests.

So now, we can make change at one place and it will be reflected in many tests by refactoring the tests.

In Page Object Model, we create individual classes for each of the pages with all the methods pertaining to the Page. These methods specific to a page covers both positive and negative scenarios specific to page.

Page Object Model reduces the duplication of code, improves readability and increases robustness of the test. Also the code is lot more maintainable, which is specifically useful in case properties of objects in the application changes frequently.


Page Factory uses the factory class from web driver’s support library to define objects in the page in a better and simpler manner. We declare some fields on a PageObject that are Web Elements or List<Web Element>.initialize the page objects.

We can use Loadable components in the Page design providing a standard way of ensuring that pages are loaded successfully.

Together with this, we can use best practices to ensure the quality of code is highly robust, reusable and maintainable. We will discuss in details in upcoming articles how to code using Page Object Model, using Page Factory, Loadable Components in Selenium.
                                                                                                                                                

Element Identification using Selenium WebDriver: Questions and Answers

This post explains the questions on understanding how web elements are identified by Selenium WebDriver.This covers findElement, findElements, various locators and profiling using WebDriver.


Question 1: What is the method used to launch URL using Selenium WebDriver?

Answer: In Firefox, we can set the homepage as the required URL as shown in the code below. This will launch the URL set in homepage on launching the driver.

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("browser.startup.homepage","http://www.google.com");

//We will provide the profile used as argument for Firefox Driver.

WebDriver driver = new FirefoxDriver(profile);


In case, we do not want to use profile, we can use the get method to launch the URL.

WebDriver driver = new FirefoxDriver();

driver.get("https://www.google.com");


Question 2: What is the difference between findElement and findelements method in Selenium?

Answer: To locate an element in the page, we use findElement method whereas findElements gives the collection of web elements in the Page.

Syntax for findElement is:

WebElement tableinfo = driver.findElement(By.className("tableClsName"));


This will give the first element in the page with className as “tableClsName”. Now once the element is recognized, we can perform action on the WebElement. Suppose the element is a button, we can click on the button as shown below:

Tableinfo.click();


Suppose the WebElement is an input box, we can insert data in the input box as shown below:

Tableinfo.SendKeys(“This is a test”);


Syntax for findElements is:

List<WebElement> tabledata = tableinfo.findElements(By.tagName("td"));


This will give collection of all elements in the page with className as “td”.
We can further work on the collection of the object and extract the required information or perform actions on the required webElement as shown below:

List<WebElement> tabledata = tableinfo.findElements(By.tagName("td"));

for (int iCnt = 0;i<tabledata.size();iCnt++)

 {

String strData = tabledata.get(iCnt).getText() ;

If(strData.contentEquals(“this is the row”))

{

System.out.println(“Web Element Found”)

iCnt = tabledata.size()-1;

}

}


Question 3: What are the value ways to identify an object in Selenium WebDriver?

Answer: Below are the various locators by which elements can be identified in Selenium WebDriver:

            1. Id:  Identifies WebElement by the ‘Id’ attribute.

            2. ClassName: Identifies webelement by the ‘class’ attribute.

            3. cssSelector: Identifies element based on the css of the webElement.

            4. linkText: Identifies element by the actual text of the link. Text should match exactly with the link text.

            5. Name: Identifies webelement by the ‘name’ attribute.  

            6. partiallinkText: Identifies element by the actual text of the link. The link is identified on partial match of text.

           7. tagName: Identifies an object by the tagName of the webElement.

           8. xpath: Identifies an object by the xpath of the object.


Question 4: Below is a picture of google Page, how can we identify the inputbox for search using the various locators identifier?

Input box object identification

Answer: The WebElement can be identified by different locators as shown below:
         1.  Id:  WebElement Elem = driver.findElement(By.id(“gbqfq”));
         2.  ClassName:  WebElement Elem = driver.findElement(By.className(“gbqfif”);
         3.  cssSelector: WebElement Elem = driver.findElement(By.cssSelector(“input#gbqfq”);
         4.  linkText:  Not Applicable as the element is an input box
         5.  Name: WebElement Elem = driver.findElement(By.Name(“q”);
         6.  partiallinkText: Not Applicable as the element is an input box 
         7.  tagName:  WebElement Elem = driver.findElement(By.tagName(“input”);
         8.  xpath:  WebElement Elem = driver.findElement(By.xpath(“//input[@className = ‘gbqfif’]”);

Question 5: I want to identify the title of the page is displayed properly. What will be the code to verify this?

Answer: Using driver.getTitle, we can get the title of the current Page.

if(driver.getTitle().contentEquals("Rediff Home Page"))

{

         System.out.println(“Correct Page is displayed);

}

else

{

       System.out.println(“InCorrect Page is displayed);     

}