extentreports-cucumber6-adapter icon indicating copy to clipboard operation
extentreports-cucumber6-adapter copied to clipboard

Cannot read environment variables or provide dynamic variables in extent properties file

Open simsekMcem opened this issue 3 years ago • 7 comments

Hi,

I am a little bit confused and might be trying something awkward. In the end, I explained what I have found in the code.

This is what I am trying to do:

In extent.properties file, I am trying to set my environment variables as systeminfo so that I can generate a section which contains some relevant information about the environment that the tests are running. Unfortunately, I am not able to do that.

Scenario:

In git action, the runner OS has an environment variable called GITHUB_ACTIONS. If this variable exists and equals to true, I want to see some details such as OS version, github sha or github ref on the report. What I am trying to do may not be proper for the systeminfo but It would be very nice to see those information on the report. I'd like to hear what you think about this approach.

Attempts:

  • In CucumberRunner, I have implemented a method with @AfterClass. I used Properties class and load the extent.properties file and tried to change it in the runtime. It worked but changing properties file in the runtime might not be the best solution.

  • Before starting test run, I append some props in extent properties and run the tests. This worked too but I think this is not the best approach as well as the first one. This approach is actually as same as providing these variable with maven command (-Dsysteminfo.temp="temp"). I'd like to avoid this approach.

  • Again, in CucumberRunner, I have implemented a method with annotation @AfterClass (also tried with @BeforeClass). I tried to use System.setProperties() method to add an environment variable like systeminfo.temp or systeminfo.osversion. For example, System.setProperties("systeminfo.temp","temp"). Unfortunately, this doesn't work.


So, basically, what I was trying is extent properties can read system properties somehow. For example,

systeminfo.runnerOs=${osRelatedEnvVariableName} systeminfo.githubref=${githubRefEnvVariableName}

or

tempVariable=temp systeminfo.temp=${tempVariable}

both of them won't work.

In the repository, I found out that in class com.aventstack.extentreports.service.extentservice.java, addSystemInfo is doing the parsing and setting env variable. I cannot dynamically read and replace the systeminfo variable because value is being sent as String as always. Therefore, systeminfo.temp=${ANYTHING} is being sent as string. Is sending value as string a proper approach?

Is there any workaround or something you suggest? I'd like to hear thoughts.

simsekMcem avatar Mar 31 '21 21:03 simsekMcem