Skip to content

Test Metadata Feature - #5685

Merged
pekkaklarck merged 9 commits into
robotframework:masterfrom
imbus:feature/custom-metadata
Aug 4, 2026
Merged

pekkaklarck merged 9 commits into
robotframework:masterfrom
imbus:feature/custom-metadata

Conversation

@febb0e

@febb0e febb0e commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Closes #4409

Overview

Add support for testcase metadata via the normal test setting syntax:

  • [Metadata] Name Value

This metadata is now carried through execution, written to output.xml, parsed back from XML, into the log.

What changed

  • Test case settings now accept Metadata.
  • Test model (running + result) now includes metadata on test cases.
  • Suite runner copies test metadata from parsed data to result objects.
  • XML logger writes test metadata as <meta name="...">...</meta> under each <test>.
  • XML result parsing accepts and restores test-level <meta> entries.
  • JS model/log rendering now includes test metadata (same as already used for suite metadata).

Compatibility

  • Existing suite metadata behavior is unchanged.
  • XML parsing remains compatible.

Tests

Added acceptance suite for the core flow:

  • parse test metadata from test settings
  • verify metadata in in-memory result model
  • verify metadata in output.xml
  • verify metadata survives rebot processing
  • verify metadata is present in log output

Notes

This change is only about explicit [Metadata] in test cases.
It does not introduce custom bracket settings like [Owner] or a new CLI filtering flag.

Usage example

*** Test Cases ***
Login With Valid Credentials
	[Metadata]    Owner     QA Team
	[Metadata]    Ticket    RF-4409
	[Metadata]    Component     Authentication
	Open Application
	Login With Credentials
	Click Login Button
	Dashboard Should Be Visible
	[Teardown]    Close Application

Copilot AI review requested due to automatic review settings June 15, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for per-test-case metadata end-to-end (parsing → running model → result model → XML output → Rebot → log/report JS model + HTML rendering).

Changes:

  • Parse [Metadata] in test cases and store it on running/result TestCase models.
  • Persist test metadata in output.xml (<meta name="...">value</meta>) and read it back.
  • Expose test metadata in JS log model, update log.html template, and add acceptance tests.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
utest/reporting/test_jsmodelbuilders.py Updates expected JS model structure to include metadata for tests.
src/robot/running/suiterunner.py Passes parsed test metadata into the execution result test object.
src/robot/running/model.py Extends running test model constructor to carry metadata.
src/robot/running/builder/transformers.py Collects per-test metadata during parsing/model transformation.
src/robot/result/xmlelementhandlers.py Allows <meta> children under <test> when building results from XML.
src/robot/result/model.py Extends result test model constructor to accept metadata.
src/robot/reporting/jsmodelbuilders.py Emits test metadata into the JS model used by logs/reports.
src/robot/parsing/lexer/settings.py Enables Metadata setting within test case settings.
src/robot/output/xmllogger.py Writes test metadata into output.xml as <meta> elements.
src/robot/model/testcase.py Adds metadata to the data model and includes it in to_dict().
src/robot/htmldata/rebot/testdata.js Parses metadata from the JS model and shifts indices accordingly.
src/robot/htmldata/rebot/model.js Stores parsed metadata on the JS Test object.
src/robot/htmldata/rebot/log.html Renders test metadata rows in the log.
atest/testdata/output/testcase_metadata.robot New test data exercising [Metadata] in test cases.
atest/robot/output/testcase_metadata.robot New acceptance tests covering model, XML, Rebot, and log rendering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/robot/running/suiterunner.py Resolved
Comment on lines +283 to +288
{{each metadata}}
<tr>
<th>{{html $value[0]}}:</th>
<td class="doc">{{html $value[1]}}</td>
</tr>
{{/each}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be true and we also seem to have the same issue with existing suite metadata.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it @febb0e so that also keys are escaped and using {{html ...}} is safe (and actually required to avoid double escaping)?

Comment thread src/robot/model/testcase.py Outdated
Comment on lines +215 to +219
data["doc"] = self.doc
if self.tags:
data["tags"] = tuple(self.tags)
if self.metadata:
data["metadata"] = self.metadata
Comment thread src/robot/model/testcase.py Outdated
tags: "Tags | Sequence[str]" = (),
timeout: "str | None" = None,
lineno: "int | None" = None,
metadata: "dict | None" = None,
Comment thread src/robot/model/testcase.py Outdated
return Tags(tags)

@setter
def metadata(self, metadata: "dict|None") -> Metadata:
@Noordsestern

Copy link
Copy Markdown
Member

Makes #5495 obsolete

@pekkaklarck

pekkaklarck commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

I took a somewhat quick look at the changes and they look great! It's pretty cool how little changes were actually needed. I also looked at the AI review comments and agreed with most of them. Things to do before this can be merged:

  1. Fix conflicts. I didn't actually spot any conflicts myself, but GitHub UI complains about them and at the moment merge isn't even possible.
  2. Fix issues reported by AI.
  3. A bit more thorough review by me. At that point I plan to test the changes locally as well.
  4. Fix possible issues found in the review. I can fix simple things myself.

After this has been merged, the functionality still needs to be documented. Could you @febb0e take a look at that as well? Probably better to open a separate PR for that.

Overall this looks so good that I move the related issue back to RF 7.5 scope. This most likely won't make it to the first alpha/beta that I plan to release this week, but I see no problems getting this in before the final version.

@pekkaklarck pekkaklarck mentioned this pull request Jul 16, 2026
@pekkaklarck

Copy link
Copy Markdown
Member

One thing that's missing is that XML and JSON schemas need to be updated. I can take care of that if needed.

@febb0e

febb0e commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Hey @pekkaklarck
thanks for your response. I will take care of the review suggestions and update this PR accordingly.
Will also look into why there are any merge-conflicts showing up.
you will have an update on this soon from me. And yes I should document the functionality, will do this as you requested in a separate PR.

@febb0e

febb0e commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Hey @pekkaklarck

Thanks again for the review! I went through all of the AI comments and fixed the ones that turned out to be real issues:

  • changed the metadata type annotations in model/testcase.py to match Mapping[str, str] | None and be consistent with the suite side.
  • Fixed to_dict() to return a plain dictioanry instead of the Metadata object.
  • Added the missing test-level metadata entries to XML and JSON schemas.

One comment (the log.html escaping one) is a false positive in my opinion, the key and value are already escaped via the same html_escape/html_format that the suite metadata uses, so I left that as is.

While working on this I found a handful of small bugs in the surrounding code that showed up when testing the feature end-to-end.

  • Test metadata was missing from native JSON output (--output out.json) and from the Listener API v2 attribute dict — both places already had that for suites.
  • Variables in test-level [Metadata] Key ${VAR} values weren't being resolved at all (suite metadata resolves them fine), so they were showing up as ${VAR} in the output.
  • The Testdoc tool was missing per-test metadata in its model.
  • Also had to update one pre-existing test test_case_settings.robot that explicitly asserted [Metadata] is invalid in a test case, which is now false with this PR :)

I did consider adding a Set Test Metadata keyword + ${TEST_METADATA} variable for symmetry with the suite metadata side. But that's a new keyword/variable, so I didn't want to put it into this PR. Let me know what you think here.

Also let me know if you want anything split out or done differently!
I will now continue on the documentation of the feature, but this will happen in a different PR :)

@febb0e
febb0e requested a review from pekkaklarck July 22, 2026 11:42
@febb0e febb0e changed the title Custom Metadata Feature Test Metadata Feature Jul 22, 2026
@pekkaklarck

Copy link
Copy Markdown
Member

Thanks for the update! I'm back from holiday and will review this now. Hopefully we get this in soon and can then create RF 7.5 rc 1!

Great that you found and fixed those issues surrounding the main logic. It's hard to remember to get all of such cases covered, and I'd be surprised if we didn't need to make some adjustments still in the subsequent releases.

I agree Set Test Metadata keyword and ${TEST METADATA} variable can be left out for now. Adding them before RF 7.5 final is still possible, but I don't consider it a big problem if they were added only in the next release. Let's anyway concentrate on getting the main logic implemented, tested and documented.

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good!

My comments seem to be only related to acceptance tests and they are mostly about style. Formatting metadata values definitely needs to be tested on acceptance test level, but it seems to be unit tested so the functionality ought to work fine.

I'm pretty sure there are some corner cases we have missed, but let's merge this now and fix possible problems afterwards. I can also fix the minor test issues myself at the same time as I experiment with this feature locally.

@@ -0,0 +1,41 @@
*** Settings ***
Resource atest_resource.robot
Suite Setup Run Tests --log log.html --report report.html output/testcase_metadata.robot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add validate output=True here to explicitly validate output.xml against the schema.

Schema validation can be enabled for all cases where output.xml is parsed with like atest/run.py -S. It slows execution a bit so it's not done by default, but explicitly enabling it where it makes sense is fine.

Should Be Equal ${ticket.text} RF-9999
${html} = Get Element ${OUTFILE} .//test[@name="Test With Metadata"]/meta[@name="Html"]
Should Be Equal ${html.text} <b>value</b> & data
Element Should Not Exist ${OUTFILE} xpath=.//test[@name="Test Without Metadata"]/meta

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't tested other constructs in XML this way. We have just validated that information is available in the model after parsing XML, like the previous test does, and also validated that outputs match the schema. That said, I don't see real harm in validating XML also like this so probably we can leave this test as it is.

Test Case Metadata Is Included In JSON Output
Copy Previous Outfile
Run Tests Without Processing Output -o output.json output/testcase_metadata.robot
Outputs Should Contain Same Data ${OUTFILE COPY} ${OUTDIR}/output.json ignore_timestamps=True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to explicitly validate that tests contains correct metadata also in this case. Validating that results contain same data regardless the output file format is probably a good idea as well, but that functionality may be buggy and ignore test metadata.

Test With Metadata
[Metadata] Owner Team Robot
[Metadata] Ticket RF-9999
[Metadata] Html <b>value</b> & data

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "Escaped" would be a better name than "HTML". The point here is that the value is escaped.

Related to the above, suite metadata values support formatting using Robot's own syntax (and the plan is to support Markdown in the future). There should thus be an entry like this as well:

[Metadata]    Formatting    Robot *rocks*!

and in HTML the value should be Robot <b>rocks</b>!.

Comment on lines +283 to +288
{{each metadata}}
<tr>
<th>{{html $value[0]}}:</th>
<td class="doc">{{html $value[1]}}</td>
</tr>
{{/each}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it @febb0e so that also keys are escaped and using {{html ...}} is safe (and actually required to avoid double escaping)?

@pekkaklarck

Copy link
Copy Markdown
Member

As I wrote in the review, this looks good enough to be merged, but I'll wait that test run finishes before that. If you @febb0e are online, you can look and possibly fix the small issues I commented while tests run, but I can also fix them myself after merging this.

The next major task related to this is documentation. After that we can still think about Set Test Metadata and ${TEST METADATA}. I also want to get a release candidate with this feature out soon so that your users have a possibility to test this before the final release.

@pekkaklarck
pekkaklarck merged commit 3cd488b into robotframework:master Aug 4, 2026
8 checks passed
pekkaklarck added a commit that referenced this pull request Aug 4, 2026
Related to issue #4409 and PR #5685.
pekkaklarck added a commit that referenced this pull request Aug 4, 2026
- Move test metadata files from `output` to `parsing` where other
  similar tests existed.
- Rename files in format `test_case_xxx.robot` and `testcase_xxx.robot`
  `test_xxx.robot` for consistency.

Somewhat related to issue #4409 and PR #5685.
@febb0e

febb0e commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Hey @pekkaklarck
I have started to implement the issues you have mentioned. I am trying to create a PR for every issue, starting with the missing report entry for the testcase metadata and enhancements to the test cases as mentioned.
See: #5743

Next thing was to add documentation, this was something I already prepared and just adjusted to your review.
See: #5744

And I also added the &{TEST METADATA} and Set Test Metadata implementation.
See: #5745

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test metadata

4 participants