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

A Well Comprehensive Test plan for Manual Testing

  Scope Definition: Define the scope based on specifications and requirements provided. However, also include exploratory testing to uncover issues that might not be explicitly mentioned in the requirements. Consider factors like usability, accessibility, security, and performance to broaden the scope beyond just functional testing. Considering factors like usability, accessibility, and security in the scope definition is essential for ensuring a comprehensive testing approach that goes beyond functional requirements Test Case Design: Use a combination of traditional methods like boundary value analysis, equivalence partitioning, and decision tables for structured testing. Incorporate exploratory testing techniques to explore the application and identify unexpected behaviour or edge cases. Prioritize test cases based on risk assessment and criticality. can implement the shift-left approach in...

Pre conditions and Post conditions in Test Ng.

Pre conditions and PostConditions in Test Ng. Vision of Preconditions and Postconditions: 👉 Ensuring Test Isolation: By using preconditions and postconditions, you ensure that each test method is executed in isolation, with a clean and consistent state. 👉Promoting Reusability: Setup and teardown tasks defined in preconditions and postconditions can be reused across multiple test methods, promoting code reuse and reducing redundancy. 👉Maintainability: Clearly defined preconditions and postconditions enhance the maintainability of test code. Changes or additions to the setup and cleanup logic can be made centrally in these annotated methods. TestNG PreConditions and PostConditions flow.   Before Suite (once) Before Test (once for each <test> in the suite) Before Class (once for each class with test methods in the <test> ) Before Method (before each test method) Test method execution After Method (after each test method) After Class (after all test methods in ...

Essential of Creating Test plan in Testing

  Why Test Plan is Vital Document! Test Planning process and plan itself serve as vehicle for communicating with other members of the project team, tester, Dev, BA, Peer and other stakeholders. This communication allows the test plan to influence the project team and allows the project team to influence the test plan. We can accomplish this Communication through circulation of one or more test plan drafts and through review meeting. E.g.: Please tell me what the plan is for releasing the test items into the test lab for each cycle of test execution E.g.: Please let me know which version of the test tool   will be used for the regression tests of the previous increment. A test plan Document becomes the record of previous discussions and agreements. Test Plan helps us to Manage the change if you are in Agile , have to this as Handy. Ways to write a Test Plan Document. Analyze the Product: Understand the product's objectives, target users, specific...