|
| 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="<your_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.api.project.get_project_info("<your_project_key>") |
| 31 | + |
| 32 | +# Obtain a project's versions/releases |
| 33 | +project_versions = zsquad.api.project.get_project_versions_by_id("<your_project_id>") |
| 34 | + |
| 35 | +# Get the data of a testcase |
| 36 | +test_case = zsquad.api.test_cases.get_test_case("<your_case_key>", fields="id") |
| 37 | + |
| 38 | +# Get the test steps from a testcase |
| 39 | +test_steps = zsquad.api.test_cases.get_test_steps("<your_step_id>") |
| 40 | + |
| 41 | +# Get the list of all test cycles for a specific release |
| 42 | +test_cycle = zsquad.api.test_cycles.get_test_cycle(project_id="<your_project_id>", version_id="<your_version_id>") |
| 43 | + |
| 44 | +# Get all folders from a test cycle |
| 45 | +test_cycle_folders = zsquad.api.folder.get_folder(cycle_id="<your_cycle_id>", project_id="<your_project_id>", version_id="<your_version_id>") |
| 46 | + |
| 47 | +# Get all test executions from a test case |
| 48 | +test_executions = zsquad.api.test_executions.get_test_execution(test_id_or_key="<your_case_id_or_key>") |
| 49 | + |
| 50 | +# Create a new test case for a project |
| 51 | +data = { |
| 52 | + "fields": { |
| 53 | + "assignee": { |
| 54 | + "name": "<jira_username>" |
| 55 | + }, |
| 56 | + "description": "<your_case_description>" |
| 57 | + } |
| 58 | +} |
| 59 | +ret_data = zsquad.api.test_cases.create_test_case(project_id="<your_project_id>", summary="<your_case_summary>", data=data) |
| 60 | + |
| 61 | +# Execute ZQL search query |
| 62 | +demo_query = "project = '<your_project_id>' AND cycleName = '<your_cycle_name>'" |
| 63 | +zql_search_res = zsquad.api.utils.run_zql_search(query=demo_query, maxRecords=200) |
| 64 | + |
| 65 | +# Create a new test cycle for a project based on an existing test case |
| 66 | +data = { |
| 67 | + "clonedCycleId": "<your_cycle_id>", |
| 68 | + "description": "<your_cycle_description>", |
| 69 | + "build": "", |
| 70 | + "startDate": "29/Nov/22", |
| 71 | + "endDate": "4/Dec/22", |
| 72 | + "environment": "" |
| 73 | +} |
| 74 | +ret_data = zsquad.api.test_cycles.create_test_cycle(project_id="<your_project_id>", version_id="<your_version_id>", cycle_name="<your_cycle_name>", data=data) |
| 75 | + |
| 76 | +# Create a new test folder for a test cycle |
| 77 | +data = { |
| 78 | + "cycleId": 1508, # it will be rewritten by the function |
| 79 | + "name": "<your_folder_name>", |
| 80 | + "description": "<your_folder_description>", |
| 81 | + "projectId": 10600, # it will be rewritten by the function |
| 82 | + "versionId": -1, # it will be rewritten by the function |
| 83 | + "clonedFolderId": -1 |
| 84 | +} |
| 85 | +ret_data = zsquad.api.folder.create_folder(project_id="<your_project_id>", version_id="<your_version_id>", cycle_id="<your_cycle_id>", data=data) |
| 86 | + |
| 87 | +# Add a new test case for a test cycle |
| 88 | +data = { |
| 89 | + "issues":["<your_case_key>"], |
| 90 | +} |
| 91 | +ret_data = zsquad.api.test_cases.add_test_to_cycle(project_id="<your_project_id>", cycle_id="<your_cycle_id>", method="1", data=data) |
| 92 | + |
| 93 | +# Obtain the execution details |
| 94 | +exec_details = zsquad.api.test_executions.get_execution_properties(exec_id="<execution_id>") |
| 95 | +# print(exec_details) |
| 96 | + |
| 97 | +# Obtain the execution steps from an execution |
| 98 | +exec_steps = zsquad.api.test_executions.get_test_steps(exec_id="<execution_id>") |
| 99 | + |
| 100 | +# Update the status of an execution step |
| 101 | +step_status = zsquad.api.test_executions.update_test_step_status(step_id="<execution_step_id>", status=2) |
| 102 | + |
| 103 | +# Update the status of an execution step |
| 104 | +exec_status = zsquad.api.test_executions.update_execution_status(exec_id="<execution_id>", status=2) |
| 105 | + |
| 106 | +# Update a folder name and description |
| 107 | +data = { |
| 108 | + "description": "<new_folder_decription>" |
| 109 | +} |
| 110 | +ret_data = zsquad.api.folder.update_folder(project_id="<your_project_id>", version_id="<your_version_id>", cycle_id="<your_cycle_id>", folder_id="<your_folder_id>", name="<your_new_folder_name>") |
| 111 | + |
| 112 | +# Delete 3 test executions |
| 113 | +delete_status = zsquad.api.test_executions.delete_bulk_execution(execution_id=["<your_exec_id_1>", "<your_exec_id_2>", "<your_exec_id_3>"]) |
0 commit comments