Skip to main content

A Complete Skeleton for developing a framework Using TestNG , Cucumber, Maven and Selenium

 

Creating a complete Maven structured framework with all the specified features and integrations is beyond the scope of a single response. However, I can provide you with a step-by-step guide to help you set up the framework and achieve the mentioned functionalities. This guide assumes that you are familiar with Java, Selenium, TestNG, Maven, and Jenkins.hashtaglearnAutomation
hashtagseleniumautomation
hashtagcucumber
My way of Developing of Automation framework Using Maven , TestNG Using Selenium .
I just Provided The skeleton of upcoming End To End Framework.
🎯 Create Maven Structured Framework with all necessary Automation
dependencies
🎯Select Sample Application to Automate the end-to-end flow
Implement Page object Model mechanism to drive the locators from
respective classes
🎯Drive object creation within Page object classes encapsulating it from Tests
🎯Create Base Test which sets browser configuration details and Global
properties
🎯Decide the Test Strategy, how tests should be clubbed & distributed with
appropriate annotations
🎯Create TestNG runner file to trigger the tests with one Single point of
execution control
🎯Introduce Grouping in TestNG.xml to categorize tests with different tags of execution
🎯Implement Data driven testing & Parameterization using TestNG Data
provider Hash Map & Json File readers
🎯Implement TestNG Listeners to capture Screenshot on automatic test
failures and logging
🎯Create Extent Report wrapper to generate excellent HTML reports for the
application
🎯Make Framework necessary changes to support parallel execution with
Thread safe mechanism
🎯Implement TestNG retry mechanism to rerun the failed flaky tests in the
application
🎯Run the Framework tests with Maven commands with TestNG Maven
integration plugin
🎯Implement Maven Run time variables to replace global parameters of test
data at run time
🎯Integrate the Framework with Jenkins with Parameterized Build Pipeline
Jobs & Schedule the jobs on specific time frames
🎯Add Cucumber Wrapper to existing framework with Cucumber TestNG
Runner
🎯Create Feature files & Step definitions to support Cucumber execution of
Selenium Tests
🎯Understanding how cucumber tags, Data driven & Parameterization works in
running the tests.

Here is the Project Structure and create a Maven Project with this structure
- src
  - main
    - java
      - com.example.framework
        - base
        - pages
        - utils
      - tests
  - test
    - resources
- config
- target
- testng.xml
- pom.xml
2.Add necessary dependencies to your pom.xml:
<!-- Selenium -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

<!-- TestNG -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.3.0</version>
</dependency>

<!-- Extent Reports -->
<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>4.1.5</version>
</dependency>

3.Create a BaseTest class to set up browser configuration and global properties.


package com.example.framework.base;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;


public class BaseTest {


    protected WebDriver driver;


    @BeforeMethod

    public void setUp() {

        // Set up browser configuration

        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

        driver = new ChromeDriver();

    }


    @AfterMethod

    public void tearDown() {

        // Close the browser

        driver.quit();

    }

}

4.Implement the Page Object Model with classes for each page.

package com.example.framework.pages; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; public class HomePage { private WebDriver driver; @FindBy(xpath = "//a[@id='login']") private WebElement loginButton; public HomePage(WebDriver driver) { this.driver = driver; } public void clickLogin() { loginButton.click(); } }

5.Write your TestNG tests using the Page Object Model.

package com.example.framework.tests; import com.example.framework.base.BaseTest; import com.example.framework.pages.HomePage; import org.testng.annotations.Test; public

Step 6: TestNG Annotations and Groups

Use TestNG annotations to control the test execution flow and group your tests.

package com.example.framework.tests; import com.example.framework.base.BaseTest; import com.example.framework.pages.HomePage; import org.testng.annotations.Test; public class LoginTest extends BaseTest { @Test(groups = "smoke") public void loginTest() { HomePage homePage = new HomePage(driver); homePage.clickLogin(); // Add login validation/assertions } }



Step 7: Data-Driven Testing

Implement data-driven testing using TestNG DataProvider, HashMap, and JSON file readers.

@DataProvider(name = "loginData") public Object[][] getLoginData() { // Read data from Excel, CSV, JSON, or any other source return new Object[][] { {"username1", "password1"}, {"username2", "password2"}, // Add more test data }; } @Test(dataProvider = "loginData") public void loginTest(String username, String password) { // Use username and password for login }



Step 8: TestNG Listeners

Implement TestNG listeners for capturing screenshots on test failures and logging.

public class CustomListener implements ITestListener { @Override public void onTestFailure(ITestResult result) { // Capture screenshot // Log the failure details } }



Step 9: Extent Reports

Create an Extent Report wrapper to generate HTML reports.

public class ExtentReportListener implements ITestListener { private ExtentReports extent = new ExtentReports(); @Override public void onStart(ITestContext context) { // Set up Extent Report configuration } @Override public void onTestSuccess(ITestResult result) { // Log success details in the report } @Override public void onTestFailure(ITestResult result) { // Log failure details in the report } @Override public void onFinish(ITestContext context) { // Flush and close the Extent Report extent.flush(); extent.close(); } }



Step 10: Parallel Execution

Make your framework thread-safe to support parallel execution.


public class ThreadSafeTest extends BaseTest { @Test(threadPoolSize = 3, invocationCount = 3, timeOut = 10000) public void parallelTest() { // Your test logic } }


 logic } }







Comments

Popular posts from this blog

Had you to design test cases for a complex feature. What factors did Tester consider, and how did prioritize test scenarios?

  Take an instance as new application has integrated into existing applications(i,e., Running on real time )Customer want to integrate their application into third party vendors in order to let the customer order their needs through our created app itself. Factors Consisdered : Error Handling , Functional Requirements , Edge cases , Non-Functional Parameters . Transaction Flow Flow1: Customer Land on third party vendors app and start picking their items. Flow2 : Picked Items has to go Cart Page and can see number of items added by visually. Flow3: Once click to checkout , it will allow the user to input their card details and processing transaction. Flow4:Once Transactions done, newly created app show the details of the order and online tracking number . Prioritize scenerios based on the Business Emergency and needs ,well in briefly communicate to team members to identify the Critical paths and prioritize the that test suite first and Start  the execution based on what need to...

Static and Non-Static

  What is the purpose of the static keyword in Java? The static keyword is used to declare class-level variables and methods . They belong to the class rather than instances of the class and can be accessed using the class name. can we use the static keyword for package level access? In Java, the static keyword is not used for controlling access levels. The static keyword is primarily used to define class-level members, such as variables and methods, that are associated with the class itself rather than with instances of the class. The concept of access levels, on the other hand, is controlled by access modifiers. public class MyClass {     public static int publicStaticVariable = 10;     static int packagePrivateStaticVariable = 20; // package-private by default     private static int privateStaticVariable = 30; } To summarize, while static is used to define class-level members, access modifiers (public, protected,...

Headed Vs Headless Operation

  Headless Mode: Purpose: Headless mode refers to running the browser without a visible GUI. The browser operates in the background, and there is no actual browser window displayed. Benefits: Faster execution : Headless mode often performs faster than headed mode because it doesn't need to render the graphical user interface. This can be advantageous when running a large number of automated tests. Resource efficiency : Since there is no need to render the UI, headless mode typically consumes fewer system resources, making it more efficient, especially for running tests in environments with limited resources. Server-side and continuous integration : Headless mode is commonly used in server environments, continuous integration (CI) systems, or when running tests on servers where a graphical environment is not available. Headed Mode: Purpose: Headed mode refers to running the browser with a visible graphical user interface (GUI). You can see the browser window opening and performing a...