Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xray integration #1902 #2089

Merged
merged 2 commits into from
Aug 22, 2022
Merged

Xray integration #1902 #2089

merged 2 commits into from
Aug 22, 2022

Conversation

CMCunha
Copy link
Contributor

@CMCunha CMCunha commented Aug 16, 2022

Xray integration #1902

Description

Code to enable the addition of custom Junit tags in the scenarios that will generate a element in the XML report.

Set custom tags in env variables:

@BeforeClass
    public static void beforeClass() {
        System.setProperty("custom_tags", "test, requirement");
        System.setProperty("custom_xml_tags", "test_key, requirement");
    }

Use them in the Scenarios:

@requirement=CALC-2
@test=CALC-2
Scenario: custom tags are present in xml
    * print 'xray'

And it will generate a new XML Element in the report:
<properties><property name="requirement" value="CALC-2"/><property name="test_key" value="CALC-2"/></properties>

  • Relevant Issues : Xray integration #1902
  • Relevant PRs : (optional)
  • Type of change :
    • New feature
    • Bug fix for existing feature
    • Code quality improvement
    • Addition or Improvement of tests
    • Addition or Improvement of documentation

private static Element addCustomTags(Element testCase, Document doc, ScenarioResult sr){
//Adding requirement and test tags
Element properties = null;
String custom_tags = System.getProperty("custom_tags");
Copy link
Member

Choose a reason for hiding this comment

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

thanks ! first please edit the PR to target the develop branch.

what are these system properties ? is this some X-Ray thing custom_tags

Copy link
Contributor Author

@CMCunha CMCunha Aug 17, 2022

Choose a reason for hiding this comment

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

Edited to target the develop branch.

I wanted this change to be as generic as possible to serve Xray purpose but also to be able to be reused for other tools. As such it is possible to define the tags that will be used in the Scenarios and the correspondent tags that will appear in the Junit XML report. For that in the @BeforeAll or @BeforeClass we can define what we want:

@BeforeClass
    public static void beforeClass() {
        System.setProperty("custom_tags", "test, requirement");
        System.setProperty("custom_xml_tags", "test_key, requirement");
    }

We must use custom_tags and custom_xml_tags that is what this code change is searching for.

If this definition is set and match the tags added in the Scenario it will add the properties element to the Junit XML report, if not nothing will be added.

Copy link
Member

Choose a reason for hiding this comment

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

@CMCunha to be very honest I don't like this. karate snapshots the system.env when a suite starts (and I'm not sure what the life cycle is if junit 5 etc) and it is immutable. any config in my opinion should be driven via the cli Main or the Runner.Builder. so I vote for removing this. if this is some accepted industry standard, we can add a method similar to outputCucumberJson() but right now I'm not convinced

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks you for your feedback @ptrthomas .
The other options you suggested were adding n option in the cli Main (like you suggested) in a specific new option or by the -D entry that means that every time I want to execute tests I need to add those options to the execution command, that doesn't seem an easy option for the user.

Or adding an option in the Runner.Builder that will enable and configure this feature, like adding a method custom_tags(), did I get the right idea?

I saw that there is a config file in Karate, I tried to add configuration values there but were unable to get those in the ReportUtils.java class, do you think it is possible?

Copy link
Member

Choose a reason for hiding this comment

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

@CMCunha how about we just release this without this system property thing. I was curious if this is documented somewhere as a standard e.g the custom_tags name etc.

and after users try it and really feel / explain why they need some extra configuration, we can consider. I don't want to waste time on this if no-one needs it

Copy link
Contributor Author

@CMCunha CMCunha Aug 18, 2022

Choose a reason for hiding this comment

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

Ok @ptrthomas, I removed the system property as suggested.

Now all tags that follow format @key=value will be added to a properties element in XML report.

@CMCunha CMCunha changed the base branch from master to develop August 17, 2022 08:11

/**
*
* @author pthomas3
*/
public class KarateJunitTest {

@BeforeClass
Copy link
Member

Choose a reason for hiding this comment

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

thanks ! just remove these and I will merge immediately

@ptrthomas ptrthomas merged commit 50c7700 into karatelabs:develop Aug 22, 2022
ptrthomas added a commit that referenced this pull request Aug 22, 2022
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.

2 participants