如何从HP ALM中获取所有测试用例包含的操作名称?
Hey there! Let's figure out how to extract all operation names (step names) from your massive HP ALM test cases. I’ve got three solid methods tailored to different technical skill levels:
This is the easiest option if you prefer a point-and-click approach:
- Log into HP ALM and navigate to the Test Plan module. Select the folder containing your test cases (or select all test cases if needed).
- Go to the top menu bar:
Tools > Export > Excel - In the export wizard, make sure to check the Test Steps (or just Steps, depending on your ALM version) field group. This will include each step's operation name (usually labeled "Step Name" or "Description").
- Once exported to Excel, you can clean up the data: use the
UNIQUE()function (Excel 365/2021+) to pull out all distinct operation names, or use filters to sort and deduplicate manually.
If you need to automate this process or handle extremely large datasets, the REST API is your friend:
- Authenticate: First, send a POST request to your ALM server's authentication endpoint:
Include your ALM username and password in the request headers or as form data.POST http://<your-alm-server>/qcbin/rest/authentication-point/authenticate - Fetch Test Cases: Send a GET request to retrieve all manual test cases (adjust the query if you need other test types):
GET http://<your-alm-server>/qcbin/rest/domains/<your-domain>/projects/<your-project>/tests?query={{test-type["Manual"]}} - Extract Steps: For each test case, send a GET request to fetch its steps using the test ID:
GET http://<your-alm-server>/qcbin/rest/domains/<your-domain>/projects/<your-project>/tests/<test-id>/steps - Collect Operation Names: Parse the JSON response from each steps request, extract the
nameordescriptionfield (depending on your ALM setup), and add them to a set to automatically deduplicate.
Here’s a quick Python snippet to illustrate the workflow:
import requests # Configure your ALM details ALM_BASE_URL = "http://your-alm-server/qcbin/rest/domains/your-domain/projects/your-project" USERNAME = "your-username" PASSWORD = "your-password" # Set up session and authenticate session = requests.Session() session.post(f"{ALM_BASE_URL}/authentication-point/authenticate", auth=(USERNAME, PASSWORD)) # Fetch all manual tests tests_response = session.get(f"{ALM_BASE_URL}/tests?query={{test-type[\"Manual\"]}}") tests = tests_response.json()["entities"] # Collect unique operation names unique_operations = set() for test in tests: test_id = test["Fields"]["Field"][0]["value"] # Adjust index based on your ALM JSON structure steps_response = session.get(f"{ALM_BASE_URL}/tests/{test_id}/steps") steps = steps_response.json()["entities"] for step in steps: # Replace with the correct field index for your step name step_name = step["Fields"]["Field"][3]["value"] unique_operations.add(step_name) # Print results print("Unique Operation Names:") for op in unique_operations: print(op) # Logout session.post(f"{ALM_BASE_URL}/authentication-point/logout")
Note: The JSON field indices might vary between ALM versions—use Postman or a similar tool to inspect the API response structure first.
If you have access to Open Quality Center (OQC) tools, you can use VBScript or Java to directly interact with ALM's COM interface:
Here’s a VBScript example to extract step names:
' Initialize ALM connection Set tdConn = CreateObject("TDApiOle80.TDConnection") tdConn.InitConnectionEx "http://your-alm-server/qcbin" tdConn.Login "your-username", "your-password" tdConn.Connect "your-domain", "your-project" ' Create a dictionary to track unique operations Set uniqueOps = CreateObject("Scripting.Dictionary") ' Fetch all manual tests Set testFactory = tdConn.TestFactory Set allTests = testFactory.NewList("") For Each test In allTests If test.Type = "MANUAL" Then ' Get steps for the test Set stepFactory = test.TestStepFactory Set allSteps = stepFactory.NewList("") For Each step In allSteps If Not uniqueOps.Exists(step.StepName) Then uniqueOps.Add step.StepName, 1 End If Next End If Next ' Output results WScript.Echo "Unique Operation Names:" For Each opName In uniqueOps.Keys WScript.Echo opName Next ' Clean up connection tdConn.Logout tdConn.ReleaseConnection
内容的提问来源于stack exchange,提问作者James

