|
| 1 | +""" |
| 2 | +Usage examples of Zephyr Scale Server API wrappers. |
| 3 | +""" |
| 4 | +import logging |
| 5 | + |
| 6 | +from zephyr import ZephyrScale |
| 7 | + |
| 8 | + |
| 9 | +# Enable logging with level Debug for more verbosity |
| 10 | +logging.basicConfig(level=logging.DEBUG) |
| 11 | + |
| 12 | + |
| 13 | +# Specify your Jira context to operate with: |
| 14 | +base_url = "https://http://localhost:2990/jira/rest/atm/1.0/" |
| 15 | + |
| 16 | + |
| 17 | +# Deside the type of authorization. It could be a token, username/password or cookies |
| 18 | +auth = {"token": "<your_jira_token>"} |
| 19 | +# auth = {"username": "<your_username>", "password": "your_pass"} |
| 20 | +# auth = {"cookies": "<your_cookie_dict>"} |
| 21 | + |
| 22 | +# Create an instance of Zephyr Scale |
| 23 | +zscale = ZephyrScale.server_api(base_url=base_url, **auth) |
| 24 | + |
| 25 | + |
| 26 | +# Now we can start playing with the Zephyr API! |
| 27 | +test_cases = zscale.api.test_cases |
| 28 | + |
| 29 | +# Get a test case: |
| 30 | +case_data = test_cases.get_test_case("<your_case_id>") |
| 31 | + |
| 32 | +# Create a test case: |
| 33 | +creation_data = test_cases.create_test_case("<your_project_key>", "Test case name") |
| 34 | + |
| 35 | +# Update a test case: |
| 36 | +test_script = { |
| 37 | + "type": "STEP_BY_STEP", |
| 38 | + "steps": [ |
| 39 | + { |
| 40 | + "description": "Description for the step 1", |
| 41 | + "testData": "Some test data", |
| 42 | + "expectedResult": "Expectations" |
| 43 | + }, |
| 44 | + { |
| 45 | + "description": "Step 2 description", |
| 46 | + "testData": "Some more test data", |
| 47 | + "expectedResult": "Expected result for the step 2" |
| 48 | + }]} |
| 49 | +update_data = test_cases.update_test_case("<your_case_id>", |
| 50 | + objective=f"New_test_objective", |
| 51 | + testScript=test_script) |
| 52 | + |
| 53 | +# Delete a test case: |
| 54 | +deleted = test_cases.delete_test_case("<case_id_you_don't_need_anymore>") |
| 55 | + |
| 56 | +# Get test case attachments: |
| 57 | +attachments = test_cases.get_attachments("<your_case_id>") |
| 58 | + |
| 59 | +# Create a test case attachment (upload): |
| 60 | +upload_result = test_cases.create_attachment("<your_case_id>", "path_to_attachment_file") |
| 61 | + |
| 62 | +# Get the latest execution result for the test case: |
| 63 | +execution_data = test_cases.get_latest_result("<your_case_id>") |
| 64 | + |
| 65 | +# Get attachments for a specified step: |
| 66 | +test_cases.get_step_attachments("<your_case_id>", "<step_id>") |
| 67 | + |
| 68 | +# Create an attachment for step: |
| 69 | +test_cases.create_step_attachment("<your_case_id>", "<step_id>", "path_to_attachment_file") |
| 70 | + |
| 71 | +# Search test cases with JQL: |
| 72 | +search = test_cases.search_cases(query='projectKey = "<your_awesome_porojects_key>"') |
0 commit comments