createTestPlan 接口用于创建新测试。调用的 HTTP 响应包含已更改测试的 XML 结构。您可以从更新后的 XML 测试结构中获取新节点的标识符。
下表显示了 createTestPlan 接口的参数。
接口 URL | 参数 | 说明 |
---|---|---|
http://<front-end URL>/servicesExchange?hid=createTestPlan |
sid | 用于用户身份验证的 Web 服务令牌或会话标识符。您可以在 Silk Central UI 的设置页面中生成 Web 服务令牌。要访问此页面,请将鼠标光标悬停在 Silk Central 菜单中的用户名上,然后选择用户设置。您可以通过调用可用 Web 服务之一的 logonUser 方法来检索会话标识符。 |
parentNodeID | 测试树中要添加新测试的容器的 ID |
示例:http://<front-end URL>/servicesExchange?hid=createTestPlan&parentNodeID=<id>&sid=<webServiceToken>
XML 架构定义文件,用于验证测试计划可使用前端服务器 URL http://<前端服务器 URL>/silkroot/xsl/testplan.xsd下载,或是从前端服务器安装文件夹 <Silk Central installation folder>/wwwroot/silkroot/xsl/testplan.xsd 复制。
以下代码使用 Apache HttpClient 创建测试。
import org.apache.commons.httpclient.*; // Apache HttpClient string webServiceToken = "e39a0b5b-45db-42db-84b2-b85028d954d5"; // The token that you have generated in the UI URL service = new URL("http", mWebServiceHelper.getHost(), mWebServiceHelper.getPort(), String.format("/servicesExchange?hid=%s&sid=%s&parentNodeID=%d", "createTestPlan", webServiceToken, PARENT_NODE_ID)); HttpClient client = new HttpClient(); PostMethod filePost = new PostMethod(service.toExternalForm()); String xmlFile = loadTestPlanUtf8("testPlan.xml"); StringPart xmlFileItem = new StringPart("testPlan", 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。请参阅组件文档,了解所需的库。
以下代码显示可通过 createTestPlan 和 updateTestPlan 服务上载至 Silk Central 的示例测试。
<?xml version="1.0" encoding="UTF-8"?> <TestPlan xmlns="http://www.borland.com/TestPlanSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://<front-end URL>/silkroot/xsl/testplan.xsd"> <Folder name="Folder1" id="5438"> <Description>Description of the folder</Description> <Property name="property1"> <propertyValue>value1</propertyValue> </Property> <Test name="TestDef1" type="plugin.SilkTest"> <Description>Description of the test</Description> <Property name="property2"> <propertyValue>value2</propertyValue> </Property> <Property name="property3"> <propertyValue>value3</propertyValue> <propertyValue>value4</propertyValue> </Property> <Parameter name="param1" type="string">string1</Parameter> <Parameter name="param2" type="boolean">true</Parameter> <Parameter name="paramDate" type="date">01.01.2001</Parameter> <Parameter name="paramInherited" type="string" inherited="true"> inheritedValue1 </Parameter> <Step id="1" name="StepA"> <ActionDescription>do it</ActionDescription> <ExpectedResult>everything</ExpectedResult> </Step> <Step id="2" name="StepB"> <ActionDescription>and</ActionDescription> <ExpectedResult>everything should come</ExpectedResult> </Step> </Test> <Test name="ManualTest1" id="5441" type="_ManualTestType" plannedTime="03:45"> <Description>Description of the manual test</Description> <Step id="1" name="StepA"> <ActionDescription>do it</ActionDescription> <ExpectedResult>everything</ExpectedResult> </Step> <Step id="2" name="StepB"> <ActionDescription>and</ActionDescription> <ExpectedResult>everything should come</ExpectedResult> </Step> <Step id="3" name="StepC"> <ActionDescription>do it now"</ActionDescription> <ExpectedResult> everything should come as you wish </ExpectedResult> </Step> </Test> <Folder name="Folder2" id="5439"> <Description>Description of the folder</Description> <Property name="property4"> <propertyValue>value5</propertyValue> </Property> <Parameter name="param3" type="number">123</Parameter> <Folder name="Folder2_1" id="5442"> <Description>Description of the folder</Description> <Test name="TestDef2" type="plugin.SilkPerformer"> <Description>Description of the test</Description> <Property name="_sp_Project File"> <propertyValue>ApplicationAccess.ltp</propertyValue> </Property> <Property name="_sp_Workload"> <propertyValue>Workload1</propertyValue> </Property> </Test> <Test name="TestDef3" type="JUnitTestType" externalId="com.borland.MyTest"> <Description>Description of the test</Description> <Property name="_junit_ClassFile"> <propertyValue>com.borland.MyTest</propertyValue> </Property> <Property name="_junit_TestMethod"> <propertyValue>testMethod</propertyValue> </Property> <Step id="1" name="StepA"> <ActionDescription>do it</ActionDescription> <ExpectedResult>everything</ExpectedResult> </Step> <Step id="2" name="StepB"> <ActionDescription>and</ActionDescription> <ExpectedResult>everything should come</ExpectedResult> </Step> </Test> </Folder> </Folder> </Folder> </TestPlan>