我用selenium编写测试,我用java和我用TestNG将它与testlink集成。因此,当我运行一个测试并且运行是正确的,它将正确地保存在testlink中。但是,当测试失败时,测试中会出现以下错误:
testlink.api.java.client.TestLinkAPIException:调用方没有提供所需的参数状态。
这是我的测试方法:
@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);
}
}xml很好,因为当测试通过时,xml就能工作了。
以及用于设置值的testlink方法。
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);
}发布于 2013-09-26 20:50:02
我认为原因是你永远无法到达这个条件的另一个块
Assert.assertTrue(test);
if(test){
resultado = TestLinkAPIResults.TEST_PASSED;
} else {
//
}当Asser失败时,就会出现新的AssertionError,因此您永远不会使其达到if条件。您也无法捕捉到此错误,因为Exception也是从Throwable和Error派生的。因此,您基本上可以删除该条件并尝试捕获Error --这并不是真正的最佳实践,但它会工作的。在这些情况下最好使用的东西是监听程序,但我不确定@Parameters是如何工作的。然而,你总是可以这样做的
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);
}https://stackoverflow.com/questions/19037885
复制相似问题