Page Object Model and Implementation in Selenium

In testing department of today’s IT sector, Automation has a significant role. IT companies are leaning towards automation testing because there are endless advantages of automating an application. For programming language, automation gives flexibility. There are distinct types of frameworks that companies use for automating their applications. Some of which are mentioned below, and one of which is Page Object Model also popular as POM.

●    Page Object Model (POM)
●    Hybrid
●    Data Driven
●    Keyword Driven

POM is a type of framework which is very easy to understand and easy to implement while making architecture of any automation process. It basically enhances the test maintenance and reduces the possibility of duplication of code, which is very concerned thing in test automation. In other words POM is a structured base object repository design.

In POM we create a page class for each corresponding web page in the application. Now, the page class that we have created contains all the web-elements of that page and also that methods that we will perform on those web-elements, so the name that we give to a method should be according to its functionality, for example- for a log-in page, the name of the method can be login() which only has few elements like user-name, password, log-in button, forget password link, etc. and methods like passing strings in the field and clicking the buttons.

For making a robust and easy to maintain framework we use POM with data driven by collating excel with POM. The best combination would be POM with data driven through excels and run test cases through TestNG

Below mentioned the flowchart will make it clearer to understand:

Flow Chart

Implementation Example in Selenium 

  1. Create a new package file as Practice; we will be creating different packages for Page Objects, Utilities, Test Data, Test Cases and Modular actions. It is always recommended to use this structure, as it is easy to understand, simple to use and easy to maintain.
  2. Create a new class file and refer the name to the actual page from the test object. In our case it is Home Screen and Login Screen.
  3. Create a static method for each element in Home Screen. Each method will have an argument (driver) and returns a value (element).

package Practice;

   import org.openqa.selenium.By;

    import org.openqa.selenium.WebDriver;

    import org.openqa.selenium.WebElement;

public class Home_Screen {

    private static WebElement element = null;

public static WebElement MyAccount(WebDriver driver){

    element = driver.findElement(By.id(“id”));

    return element;

    }

public static WebElement LogOut(WebDriver driver){

    element = driver.findElement(By.id(“logout”));

return element;

    }

}

4.Reason of passing driver as argument selenium is able to locate the element on the browser (driver). Element is returned so that action can be performed on it.
5.Method is declared as public static so that it can be called in any other method without creating instance of the class.
6.Follow same rule for creating another class LogIn Screen.

package Practice;

import org.openqa.selenium.*;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

public class LogIn_Screen {

        private static WebElement element = null;

    public static WebElement UserName(WebDriver driver){

         element = driver.findElement(By.id(“id”));

         return element;

         }

     public static WebElement Password(WebDriver driver){

         element = driver.findElement(By.id(“id”));

         return element;

         }

     public static WebElement LogIn(WebDriver driver){

         element = driver.findElement(By.id(“id”));

         return element;

         }

}

7. Now create a new class which will be our test case, let’s say we are creating it in package called Framework by name POM.

package Framework;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

// Import package pageObject.*

import pageObjects.Home_Screen;

import pageObjects.LogIn_Screen;

public class POM{

private static WebDriver driver = null;

public static void main(String[] args) {

driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get(“http://www.store.demoqa.com”);

// Use page Object library now

Home_Screen.MyAccount(driver).click();

LogIn_Screen.UserName(driver).sendKeys(“testuser_1”);

LogIn_Screen.Password(driver).sendKeys(“Test@123”);

LogIn_Screen.LogIn(driver).click();

System.out.println(” Login Successfully, now it is the time to Log Off buddy.”)

Home_Screen.LogOut(driver).click();

driver.quit();

}

}

8.You will notice that once you type HomeScreen in your test script and the moment you press dot, all the methods in the Home Page will display. We can expose methods in order to reduce duplicated code. We are able to call these method multiple times. This will ensure a better maintainable test code, because we only have to make adjustments and improvements in one particular place.

**Implementation reference is taken from: toolsqa.com.

BDD (Behaviour-Driven Development) – Nuts & the Bolts

BDD (Behaviour-Driven Development) is an agile development technique which encourages collaboration between Business, Dev and QA. BDD first coined in 2009 by Dan North. It is an extensive approach of Test Driven Development, Acceptance Test-Driven Approach, and Domain Driven Design to snag down their drawbacks.

BDD came in to picture since requirements are often interpreted differently by teams. It leads loss of time in back and forth communication while refining the exact requirements. So as to save complexity in process BDD evolved and currently many organizations have adopted it.

BDD adopts three basic principles:

  • Enough is enough: The sufficient amount of time should be taken for planning, development, and testing.
  • Delivering value with quality: Shooting in the dark does not make sense as it hampers client, stakeholders, and users at the same time. So, proper analysis of requirements is a thumb up which BDD follows.
  • Behavior is the crux: Focuses more on behavior of product that will lead to better delivery and happy customers.

BDD (Behaviour-Driven Development) can be implemented using Gherkin language with BDD tool. Some of the widely used tools which BDD supports are Specflow in C#, Cucumber in Ruby, Freshen in PHP, and Jbehave is in Java.

A question may arise in your mind what is Gherkin? Everything needs a representation so does BDD, hence a form of representation Gherkin is introduced which is easy to understand domain-specific language or simply layman’s language. It defines the structure and syntax of the tests. Moreover, it also supports over 40 languages which boost documentation as well as test cases.

Gherkin Source file format has ‘.feature’ the extension which is commonly known as Feature file. Feature file is so simple which everybody across the board (developer, tester, BA and business) can understand. This feature file contains a list of independent scenarios, written using keywords like Given, When, Then etc. Mapping of requirement with scenarios is done using Feature file.

Now, the next step is binding these readable specifications to machine language which is achieved by using any BDD tool Specflow, Cucumber, etc. These tools convert human readable format into machine code.

How BDD works?

BA/ SME create Feature files in domain specific language then Feature and Scenarios are agreed by Dev, BA and QAE teams. Dev develops code for the same scenarios and QA creates BDD tests using tools and framework. These tests are run as a part of Continuous Integration for every build and finally, it is shared with the entire Sprint team.

Implementation of BDD using Specflow

As described above User Story are the requirements that are tied together. The User story is a scenario where an object performs an activity and end results or state of the activity are validated and tested later.

Once client or stakeholders are done with the requirements, it is converted into Feature files using Gherkin. Feature file is the entry point of the tests which works as the script as well as document. It may contain a scenario or a list of scenarios.

Gherkin has below-mentioned components that are used while writing the executable Scenarios:

  • Feature
  • Scenario
  • Given
  • When, And, Then, but
  • Scenario Outline
  • Examples

Later these Scenarios as converted into Step Definition using Specflow and Selenium. Every line in Feature file transforms into methods and code can be developed using Selenium and C# (depending on what BDD tool is being used). All together when enough Scenarios are covered, it is considered as deployed for all the Sprint teams.

Along with these positive aspects, BDD (Behaviour-Driven Development) holds some downside too. The primary downside is if any requirement is the unclear and User/Client not available to discuss then it becomes difficult to work with unclear feature. Also, clarification among teams consumes a lot of time every so often. On the first side BDD nails down all the leaps in the dark ensuring more successive approach, leveraging it many firms are boosting their client list and projects.

Core Benefits of Agile Project Management

The agile method implies an iterative and incremental method of project management and it is focused to help the tester team in maintaining focus on the fast delivery of business value. The methodologies used in the agile project follows the Agile Manifesto which is particularly based on flexibility, efforts by team members, regular improvement in product and delivery of results on time with high quality.

Earlier in software development generally referred Waterfall model method is used to develop the project which is totally different from agile method particularly because it is not iterative.

Customer satisfaction
In Agile methodology product owner always involved in the progress of development that are highly visible and flexible to change.

  • Customers also involve and engaged throughout the project.
  • Its highest priority is to satisfy the customer through the early and continuous delivery of valuable software.
  • Demonstrating working functionalities to customers in every sprint review.
  • It delivers product in market very quickly more often with every release.

Reduces risk
Using agile techniques could reduce the chance of project failure. It always had a working product, from starting off the first sprint so that no single agile project fails in upcoming future.

  • Developing in sprints ensures a short time between initial project investment and an approach will work.
  • It gives freedom when new changes require after implementation with a very little cost.

High product quality
In Agile Methodology, testing is integrated during the cycle, which means that there are continuous checkups to see the product work during the development. It also helps the product owner to make changes if needed and the working team is aware if there is an issue in the product.

  • Elaborates and defines the requirements just in time so that the knowledge of the product is as relevant as possible to all team.
  • Continuous integration and daily testing into the development process make the development team address that issue at the right time.
  • Perfect use of automation testing tools.
  • It conducts Sprint retrospectives that allow the scrum team to improve the process and work continuously.

Predictable costs and schedule
The cost of the product is predictable and limited to the amount of work that can be performed by the team in the fixed schedule time box. It is also combined with estimates provided by Client prior to each Sprint..

  • Individuals and interactions over processes and tools.
  • Working software over comprehensive documentation.
  • Customer collaboration over contract negotiation.
  • Responding to change over plan.

Focuses on users
It generally uses user stories with business-focused Acceptance Criteria which define the product features by focusing on the needs of real users, each feature incrementally delivers value. It also provides the opportunity to beta test software after each sprint.

  • All activities are focused on providing tangible business values.
  • All activities are focused on providing (business) value through ensuring a useful, usable and engaging product.
  • The customer is not defined as the project stakeholders, but the end users as well.

Bottom line
In today’s ever-changing world, organizations look for the flexible approach to delivering projects and want to become more Agile. However, for Organizations, the delivering projects and programs and where traditional project management processes still exist, the informality of the agile approach is challenging and considered too risky. A mature agile approach entails agile & Scrum training which help professionals evolve as scrum masters and improve business value.

Growing Demand from Performance Testing to Engineering

In the modern era, companies have been investing enormously in building next-gen products and platforms using cutting-edge technologies. Yet, there are the plethora of companies leave the assurance for scalability for quite late in the development cycle or do not follow the testing path enough. This in future lead to disruption in services and later can profoundly impact the customer loyalty, brand image, and ROI (or revenue). If the specific website is undergoing slow or poor performance, customers will have no choice but to explore alternating channels. As a better website experience is like a worthy brand, once gone astray, it becomes tricky to retain the customers. Considering the significance of speed-to-market for the success of the project, businesses need the appropriate processes, tools, and skills for an agile delivery. This is where most advantageous performance engineering and testing comes into the picture and assist your enterprise to think out of the box and stay ahead of the curve.

Why Implementing a robust strategy crucial?

Performance engineering, though, is a wide set of processes, and it is also an art based on years of scrutiny and observation that have led to proven practices. Putting into practice a robust strategy has been a cognizant and strategic decision for all types of enterprises operating across varied businesses. Today, validating and ensuring the responsiveness, speed, and stability of an application is absolutely business critical. The range of facets of Performance Testing has been adopted for the same, confirming that the app does not vacillate under unexpected conditions. Though, there has been a shift in conceptual thinking, where the awareness has shifted more from Performance Testing towards Performance Engineering. It critically refers to the techniques that are being applied in the application development lifecycle, which make sure the non-functional necessities. Some of the key necessities are ensuring usage, throughput, and latency of the memory. These features are required to confirm and to judge that the systems are secure, precise, user-friendly, and scalable over even in the long run. As recommended, it is a significantly demanding practice for Agile and DevOps teams to validate the presentation and efficiency of the applications. The careful application of the ideology of performance engineering makes it possible for businesses to support employees, please customers, and boost returns, all at the same time.

The growing recognition is because of the growing complications with new-age apps and the emerging technologies that are creating these manifold layers. Most of the apps these days engage with multiple third-party vendors and parties to drive innovation as well as growth for the customers. For this reason, it is no more a single action driven growth, it just getting increasingly complicated.

Some of the supplementary benefits are given below:

  • Reduced system & hardware expenses
  • Early detection of bugs and application defects
  • Guaranteed customer satisfaction
  • Enhanced revenue & profits with higher conversions
  • Lesser cost of change related to performance tuning
  • Improved experience & quality from a user’s perspective

Within the Agile process, the methodologies for Performance Engineering can be effectively aligned with the ‘shift-left’ approach. It helps to determine the issues way ahead in the product development process. In this fashion, bottlenecks can be identified and reasons can also be uncovered too. Furthermore, the overall system performance can be optimized in this procedure. The well-thought-out Engineering & Test strategy can enable teams to deal with all sorts of the critical challenges that are being posed by inefficiently performing applications. It aids in benchmarking the app performance and eventually assessing against business critical scenarios for efficient test. The digital sphere has countless aspects that keep challenging the app’s flawless functioning and predictable parameters.

ImpactQA’s comprehensive Engineering Solutions is consistent in mounting business revenues and dropping costs. The experts help in benchmarking the app presentation and helps you recognize each and every business-critical scenarios for tests.