我希望使用 REST API 自动将新测试用例添加到 HP-ALM。我在文档中没有找到任何可以帮助我实现这一目标的东西,我想知道是否有其他人在这方面取得了任何成功。
2 回答
通过 ALM 提供的 API 文档非常有用。
1) 验证会话 2) 捕获 Cookie 3) 创建测试(见下文 - 来自 ALM 文档)
使用您要创建的实体类型并指定适当的字段。
XML 示例
POST /qcbin/rest/domains/{domain}/projects/{project}/defects HTTP/1.1
Content-Type: application/xml
Accept: application/xml
Cookie: QCSession=xxx; LWSSO_COOKIE_KEY=xxx
数据
<Entity Type="defect">
<Fields>
<Field Name="detected-by">
<Value>henry_tilney</Value>
</Field>
<Field Name="creation-time">
<Value>2010-03-02</Value>
</Field>
<Field Name="severity">
<Value>2-Medium</Value>
</Field>
<Field Name="name">
<Value>Returned value not does not match value in database.</Value>
</Field>
</Fields>
</Entity>
JSON 示例
POST /qcbin/rest/domains/{domain}/projects/{project}/defects HTTP/1.1
Content-Type: application/json
Accept: application/json
Cookie: QCSession=xxx; LWSSO_COOKIE_KEY=xxx
数据
{"Fields":[{"Name":"detected-by","values":[{"value":"henry_tilney"}]}, {"Name":"creation-time","values":[{"value":"2010-03-02"}]},{"Name":"severity","values":[{"value":"2-Medium"}]},{"Name":"name","values":[{"value":"Returned value not does not match value in database.</ "}]}]}
我用于测试实体的示例 XML
<Entity Type="test">
<Fields>
<Field Name="name">
<Value>MY TEST CASE</Value>
</Field>
<Field Name="description">
<Value>Test created from api</Value>
</Field>
<Field Name="owner">
<Value>roglesby</Value>
</Field>
<Field Name = "subtype-id">
<Value>VAPI-XP-TEST</Value>
</Field>
<Field Name = "parent-id">
<Value>6209</Value>
</Field>
</Fields>
</Entity>
I have created a small module to send REST requests to HP ALM using python. For instance I am using the following command:
myCreate = self.nSession.post(entUrl, headers=self.header, data=xml_data)
After a correct Session is established, then I am using a simple POST action. The value in parenthesis are respectively:
entUrl = '{0}/rest/domains/{1}/projects/{2}'.format(self.server, self.domain, self.project) + you have to add the entity you want to create --> tests for instance.
{server}/qcbin/rest/domains/{domain}/projects/{project}/tests
headers is a dictionary containing all the headers needed to maintain the connection opened.
data is containing an xml or a JSON file format with all the information to create a test (for instance)
Hope this can help other users (since the question is quite old). Have a nice day.