Search code examples
seleniumappium

Is there a way to use Soft Assert to be able to verify if the text contains a certain string


I do not want to use Assert as it would be a hard fail in case it does not find a match. So I am looking to use Soft Assert. But in my scenario I need to check if there is a partial text match. Please help.

Thanks, Divya


Solution

  • Here you can follow the below approach. Think your actual text is "Business process ID: 123456 has been updated", and you want to check whether it contains only the "has been updated" partial string.

    String actual = "Business process ID: 123456 has been updated";
    String partial = "has been updated";
    softAssert.assertTrue(actual.contains(partial), "partial string is not contained in the given text");
    softAssert.assertAll();