{"id":19048472,"url":"https://github.com/wwakabobik/testrail_api_reporter","last_synced_at":"2025-04-24T00:51:18.814Z","repository":{"id":65436022,"uuid":"531665863","full_name":"wwakabobik/testrail_api_reporter","owner":"wwakabobik","description":"TesRail API reporter","archived":false,"fork":false,"pushed_at":"2024-08-30T14:55:58.000Z","size":1469,"stargazers_count":4,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T05:23:14.183Z","etag":null,"topics":["chart","charts","confluence","confluence-api","pytest","pytest-report","python","python3","report","reporting","reports","slack","slack-api","testing","testing-tools","testrail","testrail-api","testrail-python","testrail-reporting"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/testrail-api-reporter/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wwakabobik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-01T19:51:20.000Z","updated_at":"2024-08-30T14:55:59.000Z","dependencies_parsed_at":"2023-02-13T21:20:16.463Z","dependency_job_id":"44966512-1f65-458a-adf0-2e89e07551c9","html_url":"https://github.com/wwakabobik/testrail_api_reporter","commit_stats":{"total_commits":65,"total_committers":3,"mean_commits":"21.666666666666668","dds":"0.19999999999999996","last_synced_commit":"21d52d4b308ef25a31940c9ab6901be5459f09c1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwakabobik%2Ftestrail_api_reporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwakabobik%2Ftestrail_api_reporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwakabobik%2Ftestrail_api_reporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwakabobik%2Ftestrail_api_reporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wwakabobik","download_url":"https://codeload.github.com/wwakabobik/testrail_api_reporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248510001,"owners_count":21116130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chart","charts","confluence","confluence-api","pytest","pytest-report","python","python3","report","reporting","reports","slack","slack-api","testing","testing-tools","testrail","testrail-api","testrail-python","testrail-reporting"],"created_at":"2024-11-08T23:07:01.127Z","updated_at":"2025-04-17T19:32:27.753Z","avatar_url":"https://github.com/wwakabobik.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TestRail reporter\n\n[![PyPI version](https://badge.fury.io/py/testrail-api-reporter.svg)](https://badge.fury.io/py/testrail-api-reporter)\n[![Linters](https://github.com/wwakabobik/testrail_api_reporter/actions/workflows/master_linters.yml/badge.svg)](https://github.com/wwakabobik/testrail_api_reporter/actions/workflows/master_linters.yml)\n[![Tests](https://github.com/wwakabobik/testrail_api_reporter/actions/workflows/master_tests.yml/badge.svg?branch=master)](https://github.com/wwakabobik/testrail_api_reporter/actions/workflows/master_tests.yml)\n[![Coverage Status](https://coveralls.io/repos/github/wwakabobik/testrail_api_reporter/badge.svg)](https://coveralls.io/github/wwakabobik/testrail_api_reporter)\n[![codecov](https://codecov.io/gh/wwakabobik/testrail_api_reporter/branch/master/graph/badge.svg?token=W7TH1XV2R4)](https://codecov.io/gh/wwakabobik/testrail_api_reporter)\n![PyPI - License](https://img.shields.io/pypi/l/testrail-api-reporter)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/testrail-api-reporter) \n[![Downloads](https://static.pepy.tech/badge/testrail_api_reporter)](https://pepy.tech/project/testrail_api_reporter)\n[![Downloads](https://static.pepy.tech/badge/testrail_api_reporter/month)](https://pepy.tech/project/testrail_api_reporter)\n\n## This is Testrail API reporter tools.\n\nThis package contains several tools to interact with [TestRail](https://www.testrail.com/) via [API](https://support.testrail.com/hc/en-us/categories/7076541806228-API-Manual).\n\nGeneral part is *TestRailResultsReporter*, which is designed to report test results via api. This part is close to \n[trcli](https://github.com/gurock/trcli),  but without nasty bugs.\n\nFirstly, you need to obtain test results in xml format. You can do it via running your testsuite, i.e. using pytest:\n\n```bash\npytest --junitxml \"junit-report.xml\" \"./tests\"\n```\n\nAlso, you need to add custom field (string type) to TestRails with name `automation_id`.\n\nNow, you ready to upload results to TestRails.\nTo it, use:\n\n```python\nurl='https://your_tr.testrail.io'\nemail='your@email.com'\npassword='your_password'\nproject_number=42\ntest_suite_number=66\napi=TestRailResultsReporter(url=url, email=email, password=password, project_id=project_id,\n                            suite_id=test_suite_id, xml_report='junit-report.xml')\n# then just call:\napi.send_results()\n```\nAfter this new testcases, test run and test results will be created. Testrun will have a name like \n```AT run 2022-09-01T20:25:51```\n\n![Test run created in TestRails](https://github.com/wwakabobik/testrail_api_reporter/blob/master/screenshots/tr_at_run_report.png)\n\n\nIf you fill `automation_id` for existing testcases using correct format \n`path.to.testfile.filename.test_class.test_step`, then in such case results will be added to existing testcases.\n\nAlso, you can customize test run by passing:\n- `title` param to send_results function - it will replace whole test run title.\n- `environment` - it will be added to end of string like `AT run 2022-09-01T20:25:51 on Dev`\n- `timestamp` - it will replace timestamp (obtained from XML file)\n- `run_id` - if specified, results will be added to test run, no new testrun will be created\n- `close_run` - may be `True` (by default) or `False` - if `True`, then every testrun will be closed\n- `run_name` - you may use run name (title) instead of it's ID, in this case run id will be ignored even if it's filled\n- `delete_old_run` - may be `True` or `False` (by default) - if `True`, then specified testrun will be deleted and new one will be created\n\n![Test run details in TestRails](https://github.com/wwakabobik/testrail_api_reporter/blob/master/screenshots/tr_at_run_detailed_report.png)\n\nAlso, you can set up other params separately without need to re-initialize api object:\n\n```set_project_id(project_id)``` - change project id\n```set_suite_id(suite_id)``` - change suite id\n```set_xml_filename(xml_filename)``` - change path/filename of xml report\n```set_at_report_section(section_name)``` - change default folder name where non-linked testcases will be created\n```set_timestamp(new_timestamp)``` - change default timestamp to custom\n\n---\n\n# TestRail coverage / distribution reporter\n\nSecond part of reporter it's visualization and reporting for test cases of TestRails.\nCurrently, TestRails machine does not contain functionality to track history data of some test cases attributes to make\nreports of dynamics of automation coverage of existing testcases, or distribution by custom areas. \nAlso, it would be great to pass results as charts and report it to, for example, to Confluence.\n\nSo, I have a solution, you can use `ConfluenceReporter`!\n\n```python\n# Create reporter\nconfluence_reporter = ConfluenceReporter(username='Liberator', password='NoWar', url=\"https://my.confluence.com\", confluence_page=\"1234\")\n# Now, generate several report at once!\nconfluence_reporter.generate_report(reports=automation_distribution, cases=area_distribution, values=priority_distribution, type_platforms=my_platforms,\n                        automation_platforms=my_automation_platforms)\n# for detailed info refer to code itself, you can use also separate calls:\nconfluence_reporter.history_type_chart(type_platforms=my_platforms)  # history report of coverage by sections\nconfluence_reporter.history_state_chart(automation_platforms=my_automation_platforms)  # history report of coverage by some attribute\nconfluence_reporter.test_case_area_distribution(cases=area_distribution)  # bar chart of area distribution\nconfluence_reporter.test_case_priority_distribution(values=priority_distribution)  # bar chart of priority distribution\nconfluence_reporter.automation_state(reports=automation_distribution)  # stacked bar chart using specific field as input\n```\n\n![Report in Confluence](https://github.com/wwakabobik/testrail_api_reporter/blob/master/screenshots/tr_confluence_report.png)\n\nOk, most likely, you wonder when you can obtain these distributions? You can do it by using `ATCoverageReporter`!\n\n```python\ntestrails_adapter = ATCoverageReporter(url=tr_url, email=tr_client_email, password=tr_client_password,\n                                 project=tr_default_project, priority=4, type_platforms=my_platforms,\n                                 automation_platforms=automation_platforms)\n# now get the values for charts!\nvalues = tr_reporter.test_case_by_priority()\ncases = tr_reporter.test_case_by_type()\nreports = tr_reporter.automation_state_report()                    \n```\n\nSo, I guess you still confused, what is the \"platforms\"? It's the settings, where and which data needs to be collected\n\n```python\n# You need specify where (at which top section) test cases for specific platform (or test type, whatever) is stored\n# Also you need to specify by which field is used as criteria for automation, default 'internal_name' is 'type_id' and\n# it is by default \"Automated\", \"Functional\", \"Other\", etc.\nautomation_platforms = (\n    {'name': 'Desktop Chrome', 'internal_name': 'type_id', 'sections': [4242]},\n    {'name': 'Desktop Firefox', 'internal_name': 'custom_firefox', 'sections': [2424]})\n# Also, when you don't need to obtain automation state for cases, you can simply use just passing of section:\ntype_platforms = (\n    {'name': 'UI', 'sections': [6969]},\n    {'name': 'API', 'sections': [9696]})\n```\n\nI hope now it's clear. But what if you do not use Confluence? Ok, well, you can draw charts directly:\n\n```python\nplotly_reporter = PlotlyReporter(type_platforms=type_platforms)\nplotly_reporter.draw_test_case_by_priority(filename='stacked_bar_chart.png', values=values)\nplotly_reporter.draw_test_case_by_area(filename='pie_chart1.png', cases=cases)\nplotly_reporter.draw_automation_state_report(filename=\"pie_chart2.png\", reports=reports)\nplotly_reporter.draw_history_type_chart(filename=\"line_stacked_chart.png\")\nfor item in automation_platforms:\n    plotly_reporter.draw_history_state_chart(chart_name=item['name'])\n```\n\n# More ways to share data\n\nIf you still want to share reports, you can do it via email using `EmailSender`:\n\n```python\nchart_drawings = ['report_chart.png', 'path/to/more_graphics.png']\nchart_captions = ['Priority distribution', 'AT coverage']\nemailer = EmailSender(email=\"my_personal@email.com\",\n                      password=\"my_secure_password\",\n                      server_smtp=\"smtp.email_server.com\",\n                      server_port=587)\nemailer.send_message(files=chart_drawings, captions=chart_captions, recipients=['buddy@email.com', 'boss@email.com'])\n```\n\nAlternatively, you can use GMail API with OAuth token instead of less secure auth:\n```python\nemailer = EmailSender(email=\"my_personal@gmail.com\",\n                      gmail_token=\"token.json\")\n```\n\nFor setup GMail OAuth credentials see the [Google API Reference](https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid).\n\n\n![Email Report](https://github.com/wwakabobik/testrail_api_reporter/blob/master/screenshots/tr_email_report.png)\n\nOr you can send as Slack message using `SlackSender`\n\n```python\nslack_sender = SlackSender(hook_url='https://hooks.slack.com/services/{your}/{api}/{key}')\nslack_sender.send_message(files=chart_drawings, captions=chart_captions)\n```\n\n![Slack Report](https://github.com/wwakabobik/testrail_api_reporter/blob/master/screenshots/tr_slack_report.png)\n\n\n# Backup Test Cases\n\nSometimes you need backup you progress. Minimum what you can do - it's backup test cases. So, you can do it using `TCBackup`\n\n```python\ntc_backup = TCBackup(tr_url, tr_email, tr_password, test_rails_suite=3)\ntc_backup.backup()  # this will produce backup.xml file\ntc_backup.get_archive_backup(suffix='')  # this will produce backup.zip file\n```\n\nYou still need to save it? Let's use Google Drive and `GoogleDriveUploader`\n\n```python\n# Google token needs to be configured firstly, to do it, you have to visit:\n# https://console.developers.google.com/apis/credentials?pli=1\n# Create Credentials =\u003e OAuth client ID =\u003e TV and limited Input Devices and get client_id and a client_secret\n# Then pass it as google_id = client_id and google_secret = client_secret\ngdrive = GoogleDriveUploader(google_id=client_id, google_secret=client_secret)\n# first run prompts you to enter user_code to your user account and activate API token, \n# but if you already have access tokens, do following:\ngdrive = GoogleDriveUploader(google_id=client_id, google_secret=client_secret, google_api_refresh_token=refresh_token)\n# now you may upload any file, but by default I assume you will use backup.zip\ngdrive.upload(filename='backup.zip', mime_type='application/zip')\n```\n\n\n![Backup in Google Drive](https://github.com/wwakabobik/testrail_api_reporter/blob/master/screenshots/tr_gdrive_backup.png)\n\n\n\n## Troubleshooting\n\nTo make plotly works, you need to set up Orca independently:\n```bash\nnpm install -g electron orca\n```\n\nPlease note, that Slack expecting urls instead of filenames, so, you must upload images to some hosting.\nAs option, you can do it using https://freeimage.host via function:\n\n```python\nimage_uploaded = upload_image(filename=chart_drawings[0], api_token=YOUR_SECRET_TOKEN)\n# now you can extract URL\nimage_url = image_uploaded['image']\n# or its thumbnail\nimage_thumb = image_uploaded['thumb']\n```\n\n## Donations\nIf you like this project, you can support it by donating via [DonationAlerts](https://www.donationalerts.com/r/rocketsciencegeek).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwwakabobik%2Ftestrail_api_reporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwwakabobik%2Ftestrail_api_reporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwwakabobik%2Ftestrail_api_reporter/lists"}