I'm trying to get the test case information about a scenario outline. I need the example ID to update the example in the XRay Test Run.
The rest API query I would like to use is:
PUT {{JIRA_BASEURL}}/rest/raven/2.0/api/testrun/{{TR2_ID}}/example/0?status=PASS
The 0 value should change depending on the example that I'm executing. Because of that, I need the example I'm executing for the scenario outline.
Feature: Login feature example
Scenario Outline: Login Test
When I login with the user "<user>" in site
Examples:
|user|
|validUser|
|invalidUser|
In the previous example validUser example will be the 0 and the invalid User will be 1. I can do it with a counter, but I suppose there are a better way to do it. Also, if I have parallel executions with multiple feature files...the counter option could be complicated to manage.
Debugging one execution I saw the TimeServiceEventBus evaluating this ((TimeServiceEventBus) ((SynchronizedEventBus) ((TestCaseState) scenario.delegate).bus).delegate).handlers
Digging more, inside this data structure I can see the examples ids under the exampleIndex and the rowIndex here, under a GherkinMessageExample class:
But, as you can imagine, I don't know which one of them is running, and the access to this data seem complicated.
Do you know a way to get the example that I'm executing in a simple way?
Thank you in advance.


I'd recommend you import cucumber execution results to Jira-Xray in one go. Xray has quite a simple approach to do this, for example with Cucumber JSON report
You just add 'json:cucumber.json' plugin to your @CucumberOptions, which will generate the cucumber.json file for you after all tests are finished.
Then you just upload the generated JSON to Jira, and all the results should be updated (timings, statuses, pieces of evidence). I use it in one of my projects, and it works like a charm.
But there are 2 downsides to this approach:
If you still want to stick with the singular update, then counter seems to be a good option.
Create some kind of Scenario registry, a HashMap/ConcurrentHashMap for example, with the key of your scenario id/name, and the value null by default (fill it in some Before hook, make sure it's synchronized).
Then, in After hook (where you do the update) refer to the registry to get the current value of the running scenario (make sure it's synchronized). If the value is null - update it to 0, and use 0 for your PUT call, if the value is 0, update it to 1 and use 1, and so on.