top of page
Writer's pictureNina Mandal

DEVELOPMENT OF HYBRID DRIVEN FRAMEWORK

What is Hybrid Framework?

A Hybrid Framework in Selenium is a comprehensive software testing framework combining primarily two testing methodologies: Data driven and Keyword driven.

Here, the keywords, as well as the test data, are externalized. Keywords are maintained in a separate Java class file and test data can be maintained either in a properties file/excel file/can use the data provider of a TestNG framework.




Lets see how to automate a Registration Page of the following Webpage?https://demo.opencart.com/en-gb?route=common/home

  • Open the above url.

  • Once the webpage is displayed. Click on MyAccount <HOME PAGE> (refer Image 1.1).

Image 1.1

  • Click on Register (refer Image 1.2).

Image 1.2


  • On the Register Account screen <REGISTRATION PAGE> fill the details and click on Continue button (refer Image 1.3 and 1.3.1).

Image 1.3

Image 1.3.1


SOLUTION:

STEP 1 - Create and Configure a Project in Eclipse

  • Precondition: Ensure that the Eclipse is installed in your PC.

    [Follow link to download the installer https://www.eclipse.org/downloads/]

  • Click on Start and Open Eclipse IDE.

  • Firstly, create a new Maven project and configure pom.xml.

    - To create a Maven project Click File >> New >> Maven Project (refer Image 2.1)

Image 2.1

- On the Popup window select Create a simple project & Use default workplace location, then click Next

button (refer Image 2.2).

Image 2.2


                  - Enter Group Id and Artifact Id and then click Finish button (refer Image 2.3).

[Note : Group ID: Specifies the id of the project group

Artifact ID: Specifies the id of the project]

Image 2.3


                  - By default Eclipse will create a folder structure (refer Image 2.4).

Image 2.4


                  - Open POM.xml (refer Image 2.5).

  Image 2.5


                  - Now add the following dependencies to pom.xml :-

Using below links


//FOR EXCEL FILES


//FOR GENERATING LOGS



//FOR REPORT GENERATION


                  - Additionally update/configure the pom.xml based on project Requirement update (refer Image 2.6).

Image 2.6


  • Secondly, organize the project related files in different folder and different format. Create different packages and folders in the project (see basic folder structure in Image 2.7).


Image 2.7


Here are some definitions related to the the folders/files in the project -

pageObjects: Each web page in an application has a corresponding page class.

test Cases:This package contains all the testcases.

utilities: This package contains all the utility files that can be reused.

testData: Folder contains all the test data(Excel files/json Files).Folder contains any type of files.

src/test/java:Inside this we can put all the application test source files. Classes and packages for the test artifact should be put in this folder.

src/test/resources: Stores all the files that a test need to run properly but aren't code files, non-source code files that are required during testing.

Example: Test Data Files like Excel,CSV,JSON,XML property file etc...


logs: logs all events in the form of text

screenshots: all the failure scenarios screenshots are stored into this folder.


[Note: logs,reports,screenshots folders should be created at project level]


STEP 2 - Automation of Registration Page & basic workflow

Solution: Automation using Hybrid Automation Framework

  1. Based on the problem statement (to automate registration page of the webpage), it is required to create two page objects:

    - Home page

    - Registration Page


  2. Create page Object class for each screen. Ensure that the Page Object class contains three parts:

a) Constructor

b) Locator


2.1 Create Constructor:

Constructor in a page object class is to pass and initialize the WebDriver .

The constructor helps pass the browser (WebDriver) to the page so that the code knows which browser to use when interacting with elements like buttons, fields.

In every class constructor we write PageFactory.initElements(driver, this); however it is recommended to separate the constructor in a separate class(BasePage), and that class can be extended from all the page object classes. create BasePage


2.2 Create BasePage (to achieve reusability):

i) BasePage contains only constructor and Webdriver variable.

ii) This BasePage is extended into every page Object class.

iii) BasePage is the parent of all page object classes.

iv) Since the constructor is same for all page object classes, instead of writing the below two lines in every class constructor we can create a base page (refer Image 2.8 to create a Basepage).

(this.driver=driver;

PageFactory.initElements(driver, this);

Image 2.8


Few points to remember when creating Constructor and BasePage:

- The constructor name should be same as class name.

- Immediate parent class(BasePage), Method, Variable and constructor can be invoked by using super keyword.

- We have to create a constructor in page object class as well, without creating it , we cannot invoke the parent class constructor. This is inheritance, reusability.

- All page object classes should be derived from BasePage ,to achieve reusability.


      2.3 Create Page Object class for Home Page <HOME PAGE>

i) Create a constructor with class name "OpenCartHomePage"

ii) super(driver);-> Passing the driver to the parent class (BasePage) constructor.

iii) Parent class will receive the driver and will initiate the driver (refer Image 2.9).


Image2.9


      2.4 Create Locators for Home Page <HOME PAGE> elements

i) Account link and Register link

ii) For every element create an action method

[Note: Refer Image2.10]

Image2.10


      2.5 Create Locators and Action Methods for Registration page <REGISTRATION PAGE>

i) Extend the parent Class (Base Page)

ii) Find the WebElements

iii) For every Element we need to create an action method

Review Code snippet for action method 1:

public void setFirstName(String fname) {

txtfirstname.sendKeys(fname);

}

a) setFirstName is the action method name.

b) String fname gets the first name from the test case.

c) txtfirstname is the webElement,and we are passing the fname to that WebElement .

Getting the fname from test case and passing it to the WebElement.

  [Note: Refer Image2.11]

Image2.11


Review Code snippet for action method 2:

When the registration is successful ,a message is displayed as "Your Account Has Been Created!"

public String msgConfirmationtxt()

{

try {

return (msgConfirmation.getText());

} catch (Exception e) {

return (e.getMessage());

}

}


It will capture the text value((msgConfirmation.getText()) and will just return it. No validation is done here.

Based on this return value ,validation can be done in test case.

It will throw exception if the WebElement does not find any message in case of account registration failed.

[Note: Refer Image2.11.1]

Image 2.11.1


3. Create AccountRegistrationTest under package "testCases"

Code snippets for test class (refer Image 3.1):

@BeforeClass

public void setup()

{

This is responsible for launching the page, initialization of driver, deleting cookies.This function will be executed only once.

}

Image 3.1


Code snippet for test class, cont.....

@Test

public void verifyAccountRegistration()

{

To implement this test we have to take help of page object class. Access the functions of page object class. One test case can have multiple pageobject classes. This is an advantage of using page object classes.

Now the question is How to achieve this? We need to create object of the page object class and through that object we can access the methods.

For Registration we need to access the clickMyAccount and clickRegister methods from the pageObject class OpenCartHomePage (refer Image2.9).


OpenCartHomePage constructor is their ,constructor will be invoked at the runtime and it needs a driver. We need to pass the driver in the @Test.

OpenCartHomePage hp = new OpenCartHomePage(driver);

AccountRegisterPage register = new AccountRegisterPage(driver);

}

[Note refer Image 3.2]

Image 3.2




4.Create BaseClass under testCases package.

The reusbale methods in testCases can be moved into BaseClass so that all other testCase can extend the BaseClass and we can achieve reusability.

If we see into the code snippet of Image 3.1, @BeforeClass(setup method) and @Afterclass(tear down method) are the methods that will be used in every test class, so instead of rewriting that same code again and again we can move the common code to BaseClass,  to achieve reusability and avoid duplication.

This is the main objective for separating the common methods in a separate class. In future for any reusable methods that will be used by multiple classes, we can put them directly into the base class.


Image 3.3


5. Extend the BaseClass in "AccountRegistrationTest " test class


 Image 3.4



Code snippet for test class, cont.....

A tear down would help to clear artifacts that your tests created so that the next test can work without having to get interfered by what was left over from previous tests.


@AfterClass

public void teardown()

{

driver.quit();

}



**********************************************************END************************************************************

21 views

Recent Posts

See All
bottom of page