gurock / trcli

TR CLI (trcli) is a command line tool for interacting with TestRail.
Mozilla Public License 2.0
49 stars 43 forks source link

Cypress Integration: KeyError: 'section_id' #238

Open Robert-Boily-Neuranet opened 5 months ago

Robert-Boily-Neuranet commented 5 months ago

TestRail CLI Version

1.9.5

CLI Environment

MacOS v11.3, Python v3.10.4

TestRail Version

8.0.4 Default (7036)

TestRail Instance Type

Professional Cloud

Current behavior

Cypress-TestRail integration was set up as per https://support.testrail.com/hc/en-us/articles/7523391639956-Integrating-with-Cypress#01G75119Y2H242KNXNAYXHR3G2 , Code-first approach.

When executing trcli -c parse_junit to record the tests in a local JUnit XML report to TestRail, we receive KeyError: 'section_id'. A Test Suite is successfully created in the project, as are the sections for the test cases. However the test cases are not added, which also means that no execution results are recorded.

Full console output:

> trcli -c trcli_config.yml parse_junit

TestRail CLI v1.9.5
Copyright 2024 Gurock Software GmbH - www.gurock.com
Parser Results Execution Parameters
> Report file: ./results/combined.xml
> Config file: trcli_config.yml
> TestRail instance: [REDACTED]
> Project: Cypress Integration Proof of Concept 2
> Run title: RB trcli PoC 1
> Update run: No
> Add to milestone: No
> Auto-create entities: True
Parsing JUnit report.
Processed 1 test cases in section file is generated for .
Checking project. Done.
Adding missing suites to project Cypress Integration Proof of Concept 2.
Found 1 test cases not matching any TestRail case.
Adding missing sections to the suite.
Adding missing test cases to the suite.
Adding test cases: 0/1
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/trcli", line 8, in <module>
    sys.exit(cli())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/cli.py", line 242, in main
    return super().main(windows_expand_args=False, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/commands/results_parser_helpers.py", line 101, in wrapper_common_options
    return f(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/commands/cmd_parse_junit.py", line 36, in cli
    result_uploader.upload_results()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/api/results_uploader.py", line 90, in upload_results
    added_test_cases, result_code = self.add_missing_test_cases()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/api/results_uploader.py", line 318, in add_missing_test_cases
    added_cases, result_code = self.prompt_user_and_add_items(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/api/results_uploader.py", line 342, in prompt_user_and_add_items
    added_items, error_message = add_function()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/api/api_request_handler.py", line 353, in add_cases
    responses, error_message = self.handle_futures(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/api/api_request_handler.py", line 517, in handle_futures
    response = future.result()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/trcli/api/api_request_handler.py", line 619, in _add_case_and_update_data
    response = self.client.send_post(f"add_case/{case_body.pop('section_id')}", case_body)
KeyError: 'section_id'

Sample report file:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="30" failures="0" time="565.202">
  <testsuite name="Root Suite" timestamp="2024-06-13T17:43:58" tests="0" file="integration/export.cy.js" time="0.000" failures="0"></testsuite>
  <testsuite name="Exports " timestamp="2024-06-13T17:43:58" tests="0" time="0.000" failures="0"></testsuite>
  <testsuite name="file is generated for " timestamp="2024-06-13T17:43:58" tests="30" time="565.202" failures="0">
    <testcase name="Exports  file is generated for  2cKigEKnxqC for Fixed JPG Offline (ZIP)." time="33.469" classname="2cKigEKnxqC for Fixed JPG Offline (ZIP)."></testcase>
  </testsuite>
</testsuites>

The config file is using the correct host, project, username, and API key. It also specifies the file, title, and auto_creation_response: true.

Our TestRail instance has custom fields set up as follows. automation_id is as per the docs at https://support.testrail.com/hc/en-us/articles/7523391639956-Integrating-with-Cypress#01G75119Y2H242KNXNAYXHR3G2; section_id was added at the direction of TestRail support. Screen Shot 2024-06-17 at 10 42 19 AM

TestRail support has been unable to resolve the problem (on their end, this is request #345546), and directed us to log an issue here.

Desired behavior

The test cases specified in the report are created in TestRail, and executions are recorded as per the details in the report.

More Details

No response

Testinator-X commented 5 months ago

Maybe this comment helps you finding a workaround:

https://github.com/gurock/trcli/issues/231#issuecomment-2146096874