Test cases stop execution for next test cases after using soft assertion



  • I have used soft assertion in my test cases, but it stops the execution of all the next test cases. what I know if we are adding soft assertion then particular test case should fail and it should jump to the next test case successfully. Below is

    my code:

    public static boolean verifySelectEquipmentDivision1(){
                try{
                    int count=0;
                 String[] eqipDiv={"A","A&B","CE"};
                 WebElement eqipDivdDropdown=Driver.getDriver().findElement(By.xpath(PageUtility.SELECT_EQUIPMENT_DIVISION));
                 Select selectTimePeriod=new Select(eqipDivdDropdown);
    
                 List<WebElement> eqipDivOptions=selectTimePeriod.getOptions();
                   for(WebElement we:eqipDivOptions){
                     for(int i=0;i<eqipDiv.length;i++){
                         if(we.getText().equalsIgnoreCase(eqipDiv[i])){
                             count++;
                         }
                     }
                   }
    
                    if(count==eqipDiv.length){
                        System.out.println("matched");
                    }
                    else{
                        System.out.println("not matched");
                    }
                  }
    
    
    
              catch(Exception e){
                  System.out.println("not selected");
    
              }
            return false;
    
    
    
              } 
    

    If am not adding assertAll(); it successfully execute my test cases, but to show this test case fail, I have added asserall() method and it stop execution of next test cases;

    public void verifyEqiDiv()
    SoftAssert ssoftassert=new SoftAssert();
    
    @Test
    softAssert.assertTrue(CommonAssertion.verifySelectEquipmentDivision1(), "selected eqip div not found");
        //    softAssert.assertAll();
            createNewReport.selectEquipmentDivision();
    
    
    }
    


  • Try Assert.assertFalse(message, condition) Using this the framework will not stop. Assert false will happen only when the required condition matches.

    example:

    int assetValue = 0;
    boolean isElementPresent;
    
    
    try{
    
    isElementPresent = driver.findElement("Locator of the element").isDisplayed();
    
    }
    
    catch (Exception e) 
    {
    isElementPresent = false;
    }
    
    if(isElementPresent)
    {
    
    assetValue ++;
    //Do the required operation
    
    }
    
    else 
    {
    
    Assert.assertFalse("Since the element is not present hence marking the test case as FAIL !!!", assetValue==0) 
    
    }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2