TMAttach 接口用于将附件上载到测试或需求。下表显示了 TMAttach 接口的参数。
| 接口 URL | 参数 | 说明 |
|---|---|---|
|
http://<front-end URL>/servicesExchange?hid=TMAttach |
sid | 用于用户身份验证的 Web 服务令牌或会话标识符。您可以在 Silk Central UI 的设置页面中生成 Web 服务令牌。要访问此页面,请将鼠标光标悬停在 Silk Central 菜单中的用户名上,然后选择用户设置。您可以通过调用可用 Web 服务之一的 logonUser 方法来检索会话标识符。 |
| entityType | 目标实体类型:
(测试、需求或 TestStepParent) |
|
| entityID | 目标实体 ID:
(测试 ID、需求 ID 或手动测试 ID) |
|
| description | 附件说明:
URL 编码文本,用于描述附件。 |
|
| isURL | 如果为 true,则附件为 URL。如果为 false,则附件为文件。 | |
| URL | 可选 - 要附加的 URL。 | |
| stepPosition | 可选 - 测试步骤顺序。标识手动测试的步骤(例如,顺序第一步是 1)。如果 entityType 是 TestStepParent,则必须遵循顺序。 |
示例:http://<front-end URL>/servicesExchange?hid=TMAttach&entityType=<test, requirement, or TestStepParent>&entityID=<id>&description=<text>&isURL=<true or false>&URL=<URL>&stepPosition=<number>&sid=<webServiceToken>
以下代码使用 Apache HtmlClient 获取便捷的 HTTP-POST API,以便上载二进制附件。每个请求仅可上载一个附件。
每个请求仅可上载一个附件。要下载 Apache HttpComponents,请访问 http://hc.apache.org/downloads.cgi。请参阅组件文档,了解所需的库。
import org.apache.commons.httpclient.*; // Apache HttpClient
String webServiceToken = "e39a0b5b-45db-42db-84b2-b85028d954d5"; // Token generated in the UI
String testNodeID = null; // receiving test
File fileToUpload = null; // attachment
String AttachmentDescription = ""; // descriptive text
HttpClient client = new HttpClient();
String formURL = "http://localhost:19120/
servicesExchange?hid=TMAttach" +
"&sid=" + webServiceToken +
"&entityID=" + testNodeID +
"&entityType=Test" +
"&isURL=false";
PostMethod filePost = new PostMethod(formURL);
Part[] parts = {
new StringPart("description", attachmentDescription),
new FilePart(fileToUpload.getName(), fileToUpload)
};
filePost.setRequestEntity(new MultipartRequestEntity(parts,
filePost.getParams()));
client.getHttpConnectionManager().
getParams().setConnectionTimeout(60000);
// Execute and check for success
int status = client.executeMethod(filePost);
// verify http return code...
// if(status == httpStatus.SC_OK) ...