3

I'm looking to automate adding new test cases into HP-ALM using the REST API. I didn't find anything in the documentation to help me achieve this and I was wondering if anyone else had any success with it.

Koby Douek
  • 16,156
  • 19
  • 74
  • 103
redstapler
  • 131
  • 1
  • 8

2 Answers2

2

The API documentation provided through ALM is very helpful.

1) authenticate session 2) capture Cookie 3) create test (See below - FROM ALM DOCUMENTATION)

use the entity type you want to create and specify the appropriate fields.

Example with 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

Data

<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>

Example with 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

Data

{"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.</ "}]}]}

Example XML I Have Used for Test Entity

<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>
Roglesby
  • 59
  • 4
0

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.

Marco smdm
  • 1,020
  • 1
  • 15
  • 25