Im writing tests in selenium webdriver, in java and i have it integrated with testlink using TestNG. So when i run a test and the run is correct, it saves correctly in testlink. But when the test fails the following error appear on the test:

testlink.api.java.client.TestLinkAPIException: The required parameter status was not provided by the caller.

this is my test method:

@Parameters({"nombreBuild", "nombrePlan", "nomTL_validacionCantidadMensajes"})
    @Test
    public void validarMensajes(String nombreBuild, String nombrePlan, String nomTL_validacionCantidadMensajes) throws Exception {
        String resultado = null;
        String nota = null;
        boolean test;
        try{
            homePage = new HomePageAcquirer(driver);
            homePage.navigateToFraudMonitor();
            fraud = new FraudMonitorPageAcquirer(driver);
            test = fraud.validarCantidadMensajes();
            Assert.assertTrue(test);
            if(test){
                resultado = TestLinkAPIResults.TEST_PASSED;
            }else {
                nota = fraud.getError();
                System.out.println(nota);
                resultado = TestLinkAPIResults.TEST_FAILED;
            }
        }catch (Exception e){
            resultado = TestLinkAPIResults.TEST_FAILED;
            nota = fraud.getError();
            e.printStackTrace();
        }finally{
            ResultadoExecucao.reportTestCaseResult(PROJETO, nombrePlan, nomTL_validacionCantidadMensajes, nombreBuild, nota, resultado);
        }
    }

The xml is fine beacuse when the test passes it works.

And the testlink method to set the values.

 public static void reportTestCaseResult(String projetoTeste, String planoTeste, String casoTeste, String nomeBuild, String nota, String resultado) throws TestLinkAPIException {
    TestLinkAPIClient testlinkAPIClient = new TestLinkAPIClient(DEVKEY, URL);
    testlinkAPIClient.reportTestCaseResult(projetoTeste, planoTeste, casoTeste, nomeBuild, nota, resultado);

}
有帮助吗?

解决方案

I think the reason is that you will never get to the else block of this condition

Assert.assertTrue(test);
if(test){
    resultado = TestLinkAPIResults.TEST_PASSED;
} else {
    //
}

When Asser fails, new AssertionError occurs so you never make it even to the if condition. You also can't catch this error because Exception derives from Throwable and Error too. So you basically can remove the condition and try to catch Error - which is not really best practice but it will work. The best thing to use in these situations is listener but I am not sure how this works with @Parameters. However, you can always do it like this

try{
    Assert.assertTrue(test);
    resultado = TestLinkAPIResults.TEST_PASSED;
} catch (AsertionError e){
     resultado = TestLinkAPIResults.TEST_FAILED;
     nota = fraud.getError();
     e.printStackTrace();
 }finally{
     ResultadoExecucao.reportTestCaseResult(PROJETO, nombrePlan, nomTL_validacionCantidadMensajes, nombreBuild, nota, resultado);
 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top