|
| 1 | +""" |
| 2 | +Usage examples of Zephyr Squad Server API wrappers. |
| 3 | +""" |
| 4 | +import logging |
| 5 | + |
| 6 | +from zephyr import ZephyrSquad |
| 7 | + |
| 8 | +# Enable logging with level Debug for more verbosity |
| 9 | +logging.basicConfig(level=logging.DEBUG) |
| 10 | + |
| 11 | + |
| 12 | +# Specify your Jira context to operate with: |
| 13 | +base_url = "https://jira.hosted.com/" |
| 14 | + |
| 15 | +# Use the Jira certificate for TLS connections |
| 16 | +session_params = { |
| 17 | + "verify": "<path-to-certificate>" |
| 18 | +} |
| 19 | + |
| 20 | +# Create an instance of Zephyr Squad |
| 21 | +zsquad = ZephyrSquad( |
| 22 | + base_url=base_url, |
| 23 | + token="<token>", |
| 24 | + session_attrs=session_params |
| 25 | +) |
| 26 | + |
| 27 | +# Now we can start playing with the Zephyr API! |
| 28 | + |
| 29 | +# Obtain a project's information |
| 30 | +project_info = zsquad.actions.project.get_project_info("<project_key>") |
| 31 | + |
| 32 | +# Obtain a project's versions/releases |
| 33 | +project_versions = zsquad.api.util_resource.get_all_versions("<project_id>") |
| 34 | + |
| 35 | +# Get the data of a testcase |
| 36 | +test_case = zsquad.actions.test_cases.get_test_case("<case_key>", fields="id") |
| 37 | + |
| 38 | +# Get the test steps from a testcase |
| 39 | +test_steps = zsquad.api.teststep_resource.get_list_of_teststeps("<step_id>") |
| 40 | + |
| 41 | +# Get the information about a test cycle |
| 42 | +test_cycle = zsquad.api.cycle_resource.get_cycle_information(id="<cycle_id>") |
| 43 | + |
| 44 | +# Get the list of all test cycles for a specific release |
| 45 | +test_cycles = zsquad.api.cycle_resource.get_list_of_cycle(projectId="<project_id>", versionId="<version_id>") |
| 46 | + |
| 47 | +# Get all folders from a test cycle |
| 48 | +test_cycle_folders = zsquad.api.cycle_resource.get_the_list_of_folder_for_a_cycle(cycleId="<cycle_id>", projectId="<project_id>", versionId="<version_id>") |
| 49 | + |
| 50 | +# Get all test executions from a test case |
| 51 | +test_executions = zsquad.api.traceability_resource.get_list_of_search_execution_by_test(testIdOrKey="<case_id_or_key>") |
| 52 | + |
| 53 | +# Create a new test case for a project |
| 54 | +data = { |
| 55 | + "fields": { |
| 56 | + "assignee": { |
| 57 | + "name": "<jira_username>" |
| 58 | + }, |
| 59 | + "description": "<case_description>" |
| 60 | + } |
| 61 | +} |
| 62 | +ret_data = zsquad.actions.test_cases.create_test_case(projectId="<project_id>", summary="<case_summary>", data=data) |
| 63 | + |
| 64 | +# Execute ZQL search query |
| 65 | +demo_query = "project = '<project_id>' AND cycleName = '<cycle_name>'" |
| 66 | +zql_search_res = zsquad.api.execution_search_resource.execute_search_to_get_search_result(query=demo_query, maxRecords=200) |
| 67 | + |
| 68 | +# Create a new test cycle for a project based on an existing test case |
| 69 | +data = { |
| 70 | + "clonedCycleId": "<cycle_id>", |
| 71 | + "description": "<cycle_description>", |
| 72 | + "build": "", |
| 73 | + "startDate": "29/Nov/22", |
| 74 | + "endDate": "4/Dec/22", |
| 75 | + "environment": "" |
| 76 | +} |
| 77 | +ret_data = zsquad.api.cycle_resource.create_new_cycle(projectId="<project_id>", versionId="<version_id>", name="<cycle_name>", data=data) |
| 78 | + |
| 79 | +# Create a new test folder for a test cycle |
| 80 | +data = { |
| 81 | + "cycleId": 1508, # it will be rewritten by the function |
| 82 | + "name": "<folder_name>", |
| 83 | + "description": "<folder_description>", |
| 84 | + "projectId": 10600, # it will be rewritten by the function |
| 85 | + "versionId": -1, # it will be rewritten by the function |
| 86 | + "clonedFolderId": -1 |
| 87 | +} |
| 88 | +ret_data = zsquad.api.folder_resource.create_folder_under_cycle(projectId="<project_id>", versionId="<version_id>", cycleId="<cycle_id>", data=data) |
| 89 | + |
| 90 | +# Add a new test case for a test cycle |
| 91 | +data = { |
| 92 | + "issues":["<case_key>"], |
| 93 | +} |
| 94 | +ret_data = zsquad.api.execution_resource.add_test_to_cycle(projectId="<project_id>", cycleId="<cycle_id>", method="1", data=data) |
| 95 | + |
| 96 | +# Obtain the execution details |
| 97 | +exec_details = zsquad.api.execution_resource.get_execution_information(executionId="<execution_id>") |
| 98 | + |
| 99 | +# Obtain the execution steps from an execution |
| 100 | +exec_steps = zsquad.api.step_result_resource.get_list_of_step_result(executionId="<execution_id>") |
| 101 | + |
| 102 | +# Update the status of an execution step |
| 103 | +step_status = zsquad.api.step_result_resource.update_step_result_information(stepResultId="<execution_step_id>", status=2) |
| 104 | + |
| 105 | +# Update the execution status |
| 106 | +exec_status = zsquad.api.execution_resource.update_execution_details(executionId="<execution_id>", status=2) |
| 107 | + |
| 108 | +# Update a folder name and description |
| 109 | +data = { |
| 110 | + "description": "<new_folder_decription>" |
| 111 | +} |
| 112 | +ret_data = zsquad.api.folder_resource.update_folder_information(projectId="<project_id>", versionId="<version_id>", cycleId="<cycle_id>", folderId="<folder_id>", name="<new_folder_name>") |
| 113 | + |
| 114 | +# Delete 3 test executions |
| 115 | +delete_status = zsquad.api.execution_resource.delete_bulk_execution(executionId=["<exec_id_1>", "<exec_id_2>", "<exec_id_3>"]) |
| 116 | + |
| 117 | +# Show the progress of a job |
| 118 | +job_status = zsquad.api.execution_resource.get_job_progress_status(jobProgressToken="<job_progress_token>") |
0 commit comments