• What is Automation Testing - Advantages & Types of Tools
  • What is Selenium IDE, Selenium RC, Selenium WebDriver, Selenium Grid?
  • Selenium IDE, Firebug & Firepath Installation


  • Selenium WebDriver Architecture
  • Selenium Installation
  • Challenges and Limitations of Selenium
  • First Selenium WebDriver Script
  • Working with Firefox Browser
  • Solution - Failed To Launch Browser Using Selenium WebDriver
  • Working with Chrome Browser
  • Working with IE Browser
  • Difference Between FindElement & FindElements
  • Install Firebug, Fire path and other add on for Selenium
  • Locators in Selenium
  • Dynamic Xpath
  • Dynamic CSS
  • Handle drop-downs
  • How to work with file upload
  • Handle Alerts & Popups
  • Handle Multiple Windows
  • Mouse Hover event in Selenium
  • Right Click
  • Double Click
  • Drag and Drop
  • Capture Screenshots in Selenium
  • Parameterization
  • Synchronization
  • Implicit Wait, Explicit Wait and Fluent Wait in Selenium
  • Implicit Waits
  • Explicit WebDriver Waits
  • Fluent Wait In Selenium
  • Apache POI
  • How To Read Data From Excel File
  • How To Write Data In Excel File
  • Database Testing Using MSSQL
  • Database Testing Using MySQL
  • Database Testing Using DB2
  • Handle Ajax Call in Selenium
  • Listeners in Selenium
  • Handling JavaScript in Selenium
  • Stale Element Reference Exception in Selenium
  • Integrate Sikuli with Selenium
  • Headless Browser Testing 
  • Headless Browser Testing using HtmlUnitDriver
  • Headless Browser Testing using PhanthomJSDriver


  • TestNG Installation
  • TestNG Complete Tutorial


  • Extent Reports Introduction
  • Extent Reports Generation
  • Capturing Screenshots & Including In Extent Reports
  • Extent Reports Version 4


  • ANT Build Tool - How To Download & Install
  • Maven Build Tool - How To Download & Install
  • Creating Maven Selenium Project
  • GIT Integration with Selenium
  • Jenkins - How To Download & Install
  • Jenkins - Executing TestNG Scripts
  • Jenkins - Generating Reports After Test Execution
  • Jenkins - Executing Maven Project
  • Create build and Execute build for nightly execution
  • Send Email report based on build Status
  • Selenium Continuous Integration with Jenkins [Selenium – Maven – Git – Jenkins] – Step By Step Guide


  • Running Selenium Tests On BrowserStack
  • Kobiton - Mobile Testing Platform with Real Devices


  • Mobile Testing Platform with Real Devices


  • What is Framework & Types of Framework
  • Page Object Model Design Pattern
  • Data Driven Framework
  • How to explain Test Automation Framework or Selenium Automation Framework Architecture In Interview

  • API Testing:

  • Learn API Testing
  • Postman Tutorial (API Testing with Postman)


  • Test Automation Framework Interview Questions
  • Selenium Interview Questions
  • TestNG Interview Questions
  • Java Interview Questions
  • Python Interview Questions
  • API Testing Interview Questions


  • Automation Tester Resume
  • How To Use Soft Assert In TestNG | TestNG Tutorial

    Before knowing what is Soft Assert, first let’s see what is an Assert and what is the disadvantage in using Assert and why we are moving to Soft Assert.

    Must Read: Difference between Assert & Verify in Selenium

    Asserts are used to perform validations in the test scripts.

    There are two types of Assert:

    1. Hard Assert
    2. Soft Assert

    When an assert fails the test script stops execution unless handled in some form. We call general assert as Hard Assert

    Hard Assert – Hard Assert throws an AssertException immediately when an assert statement fails and test suite continues with next @Test

    The disadvantage of Hard Assert – It marks method as fail if assert condition gets failed and the remaining statements inside the method will be aborted.

    To overcome this we need to use Soft Assert. Let’s see what is Soft Assert.

    Soft Assert – Soft Assert collects errors during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement.

    If there is any exception and you want to throw it then you need to use assertAll() method as a last statement in the @Test and test suite again continue with next @Test as it is.

    We need to create an object to use Soft Assert which is not needed in Hard Assert.

    Check below video to see “Soft Assert in TestNG”

    Please be patient. The video will load in some time.

    If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

    Let’s see a practical example:

    Here I took two methods namely softAssert() and hardAssert().

    In the softAssert() method, I have used SoftAssert class and intentionally passing value false in the assertTrue() method to make it fail

    In thehardAssert() method, I simply used Assert and intentionally passing parameter value false in the assertTrue() method to make it fail

    Execute the above script and see the console output. You could see only one failure.

    Console Output:

    Soft Assert

    Below script is same as the first one but just added assertAll() method in the end of the first method (i.e., softAssert()).

    Note:  If you forget to call assertAll() at the end of your test, the test will pass even if any assert objects threw exceptions as shown in the above example. So don’t forget to add assertAll()

    Execute the above script and see the console output. There are two failures here. Second failure is due to assertAll() method

    Console Output:

    Soft Assert

    You could find the complete TestNG tutorial here.

    TestNG Complete Tutorial

    If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

    Soft Assert

    Get our latest blog posts delivered to your inbox

    Subscribe and get popular blog posts about software testing industry.


    11 thoughts on “How To Use Soft Assert In TestNG | TestNG Tutorial”

    1. Is there a way to combine both Hard and Soft Assertions in one method?

      Here’s an example:

      public void testMethod() {
      softAssert.assertEquals(“test”, “not test”, “This shoud fail”);
      hardAssert.assertTrue(false, “This should fail, too”);

      When I run this code, only the hardAssert gets reported because it already throws an exception. If I call on softAssert.assertAll() before hardAssert.assertTrue(), it only reports the softAssert failures.

      I would like for both failures in hard and soft assertions to be reported when the test completes.

      Thanks in advance!

      • Hi Mark, What do you want to achieve. Could you please share your thoughts.

    2. If asert.assertAll(); is there in one method can I access next method if test fails?

    3. My Test is getting failed when there is no assert :

      //Create an object for SoftAssert
      public static SoftAssert sa= new SoftAssert();

      public static void oracleTest()
      if(5 > 3)

    4. I am sorry,

      Its my mistake in the code, Instead of “sa.notifyAll();” I need to write “sa.AssertAll();”

      Thanks Raj for your write up on Soft Assertions

      • It’s fine Siva. Keep up your good work.

    5. lets say we have 5 assert statement in soft assert and 2 and 4 assert are failing after Assert all, I want to know exactly which assert statement failed and get email for that currently I am using it in after method but unable to get details on exactly which step it has failed.
      ITestResult doesn’t have that option is there any work around which you could suggest?
      public void closeBrowser(ITestResult result) throws EmailException

      if(ITestResult.FAILURE==result.getStatus()) {
      EmailPage.sendFailedEmail(ProperyReader.getProperty(“ukNonMemberEmailId”), ProperyReader.getProperty(“emailPassword”), ProperyReader.getProperty(“sendEmailTo”),result.getName());

      • Try result.getName() instead of result.getTestName()

        • Tried that didn’t work.IT doesn’t give me details as on which exact asserts did the test failed on.

        • I want email with #2 assert and #4 assert failed.

    6. Hi,
      can any one tell me the real time usage of BeforeTest and BeforeClass methods in Selenium script?when do we use these Methods .what kind of logics do we keep in these methods?

    Leave a Comment

    Share via
    Copy link
    Powered by Social Snap