Search code examples
javaseleniumtestingautomationtestlink

How to use assertion with test while executing tests in testlink


I am creating test in selenium with java and using testlink for test execution and result.Without assertion tests are working fine with testlink and showing result but when I am using assertion to verify expected and actual result like this:

try {

        driver.get("http://www.software-testing-tutorials-automation.com");     
        String ExpextedTitle="Software testing tutorials and automatio";
        String ActualTitle=driver.findElement(By.xpath("//h1[@class='title']")).getText();
        Assert.assertEquals(ActualTitle, ExpextedTitle);
        IntegrationWithTestLink.updateResult("GR-1", null, TestLinkAPIResults.TEST_PASSED);
     }catch(Exception e){
         System.out.println("Hiiiii");
         IntegrationWithTestLink.updateResult("GR-1", e.getMessage(), TestLinkAPIResults.TEST_FAILED);
     }
 }

I don't know why result are not showing in testlink in case for exception. Can anyone suggest me better approach to use Assertion here.


Solution

  • Assertion Error is not caught by catch block as your are catching exception not the error. To catch the Error change the code as given below.

    try {

        driver.get("http://www.software-testing-tutorials-automation.com");     
        String ExpextedTitle="Software testing tutorials and automatio";
        String ActualTitle=driver.findElement(By.xpath("//h1[@class='title']")).getText();
        Assert.assertEquals(ActualTitle, ExpextedTitle);
        IntegrationWithTestLink.updateResult("GR-1", null, TestLinkAPIResults.TEST_PASSED);
     }catch(AssertionError e){
         System.out.println("Hiiiii");
         IntegrationWithTestLink.updateResult("GR-1", e.getMessage(), TestLinkAPIResults.TEST_FAILED);
     }
    

    }

    It may work for you.