Skip to content

itsamuls/TestNG-testing-framework-using-selenium-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TestNG-testing-framework-using-selenium-api

TestNG is a testing framework commonly used in conjunction with Selenium for automating and organizing test cases in Java.

πŸ“” Project Description:

This project is a web automation framework designed to perform end-to-end testing of a web application using the TestNG testing framework, Selenium WebDriver for browser automation, and Maven for project management and build automation.

πŸ“” Key Components:

TestNG:

Purpose: TestNG is utilized for structuring and executing test cases. It provides annotations for defining test methods, supports parameterization, and facilitates the grouping of tests.

Selenium WebDriver:

Purpose: Selenium WebDriver is employed for automating interactions with the web application. It allows the scripting of browser actions such as clicking buttons, entering data, and validating page content.

Maven:

Purpose: Maven is used for project management and build automation. It simplifies the project setup, manages dependencies, and enables the execution of tests. Maven ensures a consistent and reproducible build process.

πŸ“” TestNG Feature covered in this project:

  • TestNG Annotations
  • Assertions in TestNG
    • Hard Assert and Soft Assert
  • Passing Parameters in TestNG
  • Prioritizing Selenium Test Cases using TestNG Feature
  • Grouping Tests in Selenium
  • DataProviders in TestNG
  • TestNG Listeners in Selenium
  • Reporting and logging in TestNG
  • Cross Browser Testing using Selenium and TestNG
  • Running Parallel Tests in Selenium with TestNG

πŸ“„ Annotations for Selenium Tests:

  • Annotations help define the order of execution and manage the test lifecycle. TestNG annotations such as @Test, @BeforeMethod and @AfterMethod are used to setup and tear down the Selenium test environment.

    Following annotation are used in the sample project:

    1. @Test – This marks a class or a method as a part of the test.
    2. @BeforeMethod – The @BeforeMethod method in TestNG will execute before each test method.
    3. @AfterMethod – The @AfterMethod method in TestNG will run after each test method is executed.
    4. @Parameters – This annotation is used to pass parameters to test methods.
    5. @DataProvider – The @DataProvider annotation in TestNG is used to supply test methods with data, allowing the same test method to be executed multiple times with different sets of data.

    • @BeforeMetod, @AfterMethod and @Paramters annotations used in BaseClass.

      Code:
      d9lcOA7ZBu

    • @Test annotation is used in the test classes.

      Code:
      w5OSLmtFCX

    • @DataProvider annotation is used in DataProvidersDemo class.

      Code:
      6LsqCaRw4c

πŸ“„ Assertions in TestNG

Assertions in TestNG are used to verify that the expected result and the actual result matches or not in the test case.

Following assertion methods are used in project :

  1. Assert.assertEquals(String actual, String expected) : This method is to check whether the actual value is equal to the expected value.

    Code:
    Z5lGeU94tB

    TestNG Xml file:
    lpBJOMLsNJ

    Output :
    eclipse_fnOOkVgWCi

    Report :
    chrome_vOvtoaBej0

  2. Assert.assertTrue(condition) : This method checks that a condition is true or not. If not, it will fail the test and an AssertionError is thrown.

    Code:
    blae8krkpL

    TestNG Xml file:
    UMznYb6fSi

    Output :
    eclipse_h7HEBNcfTk

    Report :
    chrome_up6YD5aQfo

πŸ“„ Hard Assert and Soft Assert:

  • Hard Assert : A "hard assert" refers to an assertion in testing that, when it fails, immediately stops the execution of the test.

    Code:
    my1I7Kzy02

    TestNG Xml file:
    sULIYSzISU

    Output:
    eclipse_OzxHv2LbM8

    Report :
    chrome_PP7gMrFKP2

  • Soft Assert : A "soft assert" refers to a mechanism in testing that allows the execution of a test to continue even after encountering a failure. Unlike a "hard assert," which immediately stops the test upon failure, a soft assert continues executing subsequent steps. If the first assertEquals condition fails, the subsequent steps and the additional assertions will still be executed. The assertAll() method at the end; collects all the failures and reports them together after the test execution is complete.

    Code:
    jghyxes31d

    TestNG Xml file:
    DhDc5cUrx8

    Output:
    eclipse_c8zqGCv7KL

    Report :
    chrome_UxFTaCMrzk

πŸ“„ Passing Parameters in TestNG

The @Parameters annotation is used to pass parameters to a test method. This annotation allows to define parameters at the method level and pass values from the XML suite configuration file.

Code:
d9lcOA7ZBu

TestNG Xml file:
dAVLaoYcDt

Output:
eclipse_dLMfkphB67

Report :
chrome_NjfIXR3dNi

πŸ“„ Prioritizing Selenium Test Cases using TestNG Feature

The priority attribute is used to specify the execution order of test methods within a test class. By assigning priority values to test methods, you can control the sequence in which these methods are executed during a test run.

Code:
cjSJw6DaEB

Testng XML file:
SmRpfIw6pB

Output:
eclipse_ufDGHk0F3c

Report:
chrome_eIkivS7gP6

πŸ“„ Grouping Tests in Selenium :

TestNG provides the ability to categorize tests into groups using the @Test(groups = "groupname") annotation.
The tests in this project are grouped as "Smoke" and "Regression". E.g: groups = {"Smoke", "Regression"}

Code:
Uym9czB3uo

Testng XML file: Following xml will only run test grouped under "Smoke"
tIbKBnlamZ

Report:
chrome_Ct6KTlJtop

Testng XML file: Following xml will only run test grouped under "Regression"
YfV4yOvTk8

Report:
chrome_RsIH8h93fp

πŸ“„ DataProviders in TestNG

The @DataProvider annotation is used to supply test methods with data. It allows to run the same test method with different sets of data, increasing the test coverage and flexibility.

Code: This is the dataprovider class which contains @DataProvider annotated method.
6LsqCaRw4c

The following code, the @Test annotation uses attribute dataProvider with name to access the data along with DataProvider class name hDp1yk52bi

Testng XML file:
CAedSSzxcO

Output:
eclipse_BHwaMfVFqf

Report:
4rDRlInO5G

πŸ“„ TestNG Listeners in Selenium

Listeners are useful for tasks such as logging, reporting, and taking actions based on the status of the test cases. ITestListener used in the project is an interface that allows to implement custom listeners to log the status of execution of test cases and also capture screenshot in case of test failure.

Code:
DJhzPyPSk0
ObzElcgzNf

Testng XML file:
9fzTf4K0gG

Output:
eclipse_l9VWhHTcE2

Report:
FgssKyip4g

Screenshot:
Following is the location the screenshot is getting captured. eclipse_YGIiMVrOWJ
Following is the screenshot captured. Screenshot_testToVerifyProductListPageIsDisplayedonClickingBackToProductsLink1700925625357

πŸ“„ Cross Browser Testing using Selenium and TestNG

TestNG makes it easy to implement cross-browser testing by allowing to parameterize tests and configure test methods to run on multiple browsers.

Testng XML file:
OH497xoiMm

Testng XML file:
eclipse_DVjbMQAstn

Output:
eclipse_l9VWhHTcE2

Report:
chrome_yMicYOv0ml

πŸ“„ Reporting and logging in TestNG

TestNG generates detailed HTML reports that provide information of the test executions. By default, TestNG generates an HTML report after each test run. The report named emailable-report.html is located in the project's output directory, the "test-output" folder. This report includes information such as the overall test results, test durations, and individual test method outcomes.

Testng XML file:
52Ih89RcpH

Report:
vDxiLlFlHo

About

TestNG is a testing framework commonly used in conjunction with Selenium for automating and organizing test cases in Java.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors