testlink php xmlrpc,JAVA连接TestLink自动写入执行结果

连接TestLink

1.下载相关的jar包

c3e89edee26636a71fdb39ae6ec3bb82.png

这个几个包好像都需要用到,单独使用TestLink会出问题的,但是我比较懒直接建了一个Maven的项目让Maven帮我导入的jar包。

Maven的xml配置: 在pom.xml中加入如下代码

br.eti.kinoshita

testlink-java-api

1.9.8-1

2.取到testlink的url和key,注意:url不是testlink的连接地址,是连接地址+/lib/api/xmlrpc.php(这个地址也不是一定的,视情况而定)

99bd033c81b3b06b9470c0d868dac95f.png

3.测试是否连接成功public static void main(String args[]) {

String url = "http://test.tl.gmsd.lan/lib/api/xmlrpc.php";

String devKey = "223f929e98e3d74fa3c000b67668e305";

TestLinkAPI api = null;

URL testlinkURL = null;

try     {

testlinkURL = new URL(url);

} catch ( MalformedURLException mue )   {

mue.printStackTrace( System.err );

System.exit(-1);

}

//api = new

try     {

api = new TestLinkAPI(testlinkURL, devKey);

} catch( Exception te) {

te.printStackTrace( System.err );

System.exit(-1);

}

System.out.println(api.ping());

}

运行后,出现hello即表明连接成功

更改测试用例结果://获取Plan

TestPlan plan =api.getTestPlanByName(planName, projectName);

//获取版本

Build[] build=api.getBuildsForTestPlan(plan.getId());

//获取用用例id

Integer  caseID = api.getTestCaseIDByName("12313", "test2", projectName, null);

//设置用例结果  通过

api.reportTCResult(caseID, null, plan.getId(), ExecutionStatus.PASSED, null, build[1].getName(), "自动化上传结果的备注", null, null, null, null, null, null);

具体每个参数是什么意思,可以自己敲一个同样的根据里面每个参数的提示就会明白,这个不是需要把所有的参数全部都写了才可以执行.

上传下载附件://上床文件

//  File attFile = new File("C:\\temp.txt");

//  String fileContent = "";

//  try {

//  byte[] byteArray = FileUtils.readFileToByteArray(attFile);

//  fileContent = new String(Base64.encodeBase64(byteArray));

//  } catch (IOException e) {

//  }

//  api.uploadTestCaseAttachment(caseID, "自动化上传", "自动的", "测试用", ".txt", fileContent);

//下载文件

//  String dir = "C:\\te";

// File file = new File(dir);

// if (!file.exists()) {

// file.mkdirs();

// }

// Attachment[] atts = api.getTestCaseAttachments(caseID, null);

// for (Attachment att : atts) {

// byte[] decoded = Base64.decodeBase64(att.getContent().getBytes());

// FileOutputStream fos;

// try {

// fos = new FileOutputStream(new File(file + File.separator + att.getFileName())+ att.getFileType());

// fos.write(decoded);

// fos.flush();

// fos.close();

// } catch (FileNotFoundException e) {

// } catch (IOException e) {

// }

// }

完整代码:package cn.testlink.TestTestLink;

import java.net.MalformedURLException;

import java.net.URL;

import br.eti.kinoshita.testlinkjavaapi.TestLinkAPI;

import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus;

import br.eti.kinoshita.testlinkjavaapi.model.Build;

import br.eti.kinoshita.testlinkjavaapi.model.TestPlan;

public class TestLinkMyTest {

public static void main(String[] args) {

// TODO 自动生成的方法存根

//项目名

String  projectName= "Test";

//计划名

String planName="yx";

TestLinkAPI api = null;

//TestLink api连接

String url = "http://testlink.vlife.com/lib/api/xmlrpc/v1/xmlrpc.php";

//key

String devKey = "b683e89cca796958b9481231f655261d";

//    String devKey ="2137b4119c2783d3e3bbf7d19ff183e8";

URL testlinkURL = null;

try     {

testlinkURL = new URL(url);

} catch ( MalformedURLException mue )   {

mue.printStackTrace( System.err );

System.exit(-1);

}

try     {

api = new TestLinkAPI(testlinkURL, devKey);

} catch( Exception te) {

te.printStackTrace( System.err );

System.exit(-1);

}

System.out.println(api.ping());

//获取Plan

TestPlan plan =api.getTestPlanByName(planName, projectName);

//获取版本

Build[] build=api.getBuildsForTestPlan(plan.getId());

//获取用用例id

Integer  caseID = api.getTestCaseIDByName("12313", "test2", projectName, null);

//设置用例结果  通过

api.reportTCResult(caseID, null, plan.getId(), ExecutionStatus.PASSED, null, build[1].getName(), "自动化上传结果的备注", null, null, null, null, null, null);

//上床文件

//  File attFile = new File("C:\\temp.txt");

//  String fileContent = "";

//  try {

//  byte[] byteArray = FileUtils.readFileToByteArray(attFile);

//  fileContent = new String(Base64.encodeBase64(byteArray));

//  } catch (IOException e) {

//  }

//  api.uploadTestCaseAttachment(caseID, "自动化上传", "自动的", "测试用", ".txt", fileContent);

//下载文件

//  String dir = "C:\\te";

// File file = new File(dir);

// if (!file.exists()) {

// file.mkdirs();

// }

// Attachment[] atts = api.getTestCaseAttachments(caseID, null);

// for (Attachment att : atts) {

// byte[] decoded = Base64.decodeBase64(att.getContent().getBytes());

// FileOutputStream fos;

// try {

// fos = new FileOutputStream(new File(file + File.separator + att.getFileName())+ att.getFileType());

// fos.write(decoded);

// fos.flush();

// fos.close();

// } catch (FileNotFoundException e) {

// } catch (IOException e) {

// }

// }

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值