createLibraries 接口用于创建新库。调用的 HTTP 响应包含已更改库的 XML 结构。您可从已更新的 XML 库结构中获取新节点的标识符。
下表显示了 createLibraries 接口的参数。
| 接口 URL | 参数 | 说明 |
|---|---|---|
|
http://<front-end URL>/servicesExchange?hid=createLibraries |
sid | 用于用户身份验证的 Web 服务令牌或会话标识符。您可以在 Silk Central UI 的设置页面中生成 Web 服务令牌。要访问此页面,请将鼠标光标悬停在 Silk Central 菜单中的用户名上,然后选择用户设置。您可以通过调用可用 Web 服务之一的 logonUser 方法来检索会话标识符。 |
示例:http://<front-end URL>/servicesExchange?hid=createLibraries&sid=<webServiceToken>
用于验证库的 XML 架构定义文件可以使用前端服务器 URL http://<前端服务器 URL>/silkroot/xsl/libraries.xsd 下载或从前端服务器安装文件夹 <Silk Central installation folder>/wwwroot/silkroot/xsl/libraries.xsd 复制。
以下代码使用 Apache HttpClient 创建库。
import org.apache.commons.httpclient.*; // Apache HttpClient
String webServiceToken = "e39a0b5b-45db-42db-84b2-b85028d954d5";
URL service = new URL("http", mWebServiceHelper.getHost(),
mWebServiceHelper.getPort(), String.format("/servicesExchange?hid=%s&sid=%s",
"createLibraries", webServiceToken));
HttpClient client = new HttpClient();
PostMethod filePost = new PostMethod(service.toExternalForm());
String xmlFile = loadTestPlanUtf8("libraries.xml");
StringPart xmlFileItem = new StringPart("libraries", xmlFile, "UTF-8");
xmlFileItem.setContentType("text/xml");
Part[] parts = {xmlFileItem};
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
client.getHttpConnectionManager().getParams().setConnectionTimeout(60000);
int status = client.executeMethod(filePost);
System.out.println(filePost.getStatusLine());
要下载 Apache HttpComponents,请访问 http://hc.apache.org/downloads.cgi。请参阅组件文档,了解所需的库。
以下代码显示可通过 createLibraries 服务上载至 Silk Central 的示例库。除非在 GrantedProjects 部分中定义了一个或多个项目,否则新库并不仅限于在某些项目中使用。
<?xml version="1.0" encoding="UTF-8"?>
<LibraryStructure xmlns="http://www.borland.com/TestPlanSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://<front-end URL>/silkroot/xsl/libraries.xsd">
<Library name="Library 1">
<Folder name="Folder 1">
<Folder name="Folder 1.1">
<SharedSteps name="Basic create user steps">
<Step name="Login">
<ActionDescription>
Login with user admin.
</ActionDescription>
<ExpectedResult>Succesful login.</ExpectedResult>
<CustomStepProperty name="Step Property 1">
<propertyValue>Step Property Value</propertyValue>
</CustomStepProperty>
</Step>
<Step name="Create User">
<ActionDescription>Create user tester</ActionDescription>
<ExpectedResult>User created</ExpectedResult>
<CustomStepProperty name="Step Property 1">
<propertyValue>Step Property Value</propertyValue>
</CustomStepProperty>
</Step>
<Step name="Logout">
<ActionDescription>
Logout using start menu
</ActionDescription>
<ExpectedResult>Logged out.</ExpectedResult>
<CustomStepProperty name="Step Property 1">
<propertyValue>Step Property Value</propertyValue>
</CustomStepProperty>
</Step>
</SharedSteps>
</Folder>
</Folder>
<GrantedProjects>
<ProjectId>0</ProjectId>
<ProjectId>1</ProjectId>
</GrantedProjects>
</Library>
</LibraryStructure>