Search code examples
javaselenium-webdrivertestngtestlink

Multiple Assert verification Handling


In my test method below, this method has multiple asserts. I want it to run so that if all the asserts pass then it will log the status as "Passed" in my test management tool (we are integrating Test Link with Selenium)

But if any one assert fails than testNG generates an Assertion Error; in this situation I'm not able to update the status to "Failed" in my TMT, because this method's execution was stopped and the run has proceeded with the next method.

Please provide some help to solve this.

Test(dataProvider = "User_login")
public void StatusForm_Verification(String uname, String pwd)
        throws InterruptedException {
    NavigateToLogin();
    Dashboard RD = LoginAs_user(uname, pwd);
    Thread.sleep(2000);

        if (Integer.parseInt(ReviewedStatuscount) >= 1) {

            Assert.assertEquals("true",
                    revui.Btn_SaveReview.getAttribute("disabled"));
            Assert.assertEquals("true",
                    revui.Btn_submitReview.getAttribute("disabled"));
            Assert.assertEquals("true",
                    revui.Btn_Needmoreinfo.getAttribute("disabled"));
            status = TestLinkAPIResults.PASSED;

        } else {
            throw new SkipException(
                    "Test Skipping - Reviewed count is Zero");
        }
    }

My question is : if any one assert fails, than how can I update the status to Failed in the Testlink application (i.e status = TestLinkAPIResults.FAILED)?


Solution

  • You could use @after and check status after test execution

    @After
    public void statusCheck() {
        if (status!=TestLinkAPIResults.PASSED) {
            status = TestLinkAPIResults.FAILED;
        }
    }