grasshopper7 / extentreports-cucumber6-adapter

Cucumber-JVM 6 Adapter for Extent Framework
https://ghchirp.online/2098/
MIT License
16 stars 15 forks source link

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

Open simsekMcem opened 3 years ago

simsekMcem commented 3 years ago

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:


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.

grasshopper7 commented 3 years ago

Currently the parsing of the properties file cannot handle dynamic properties. Will keep this in mind for a future release.

U can try by setting up these dynamic properties in the beforeclass method of the runner. Get the static ExtentReports INSTANCE using the getInstance() method of ExtentService. Then add the dynamic properties by using INSTANCE.setSystemInfo(key, String.valueOf(value));. The value can be generated or accessed from anywhere u want. Have not tried it but this could work.

Give it a try and let me know. Thanks.

simsekMcem commented 3 years ago

I'll let you know tomorrow, thanks for the quick response

simsekMcem commented 3 years ago

@grasshopper7 This works fine, thanks :)

bijit151288 commented 3 years ago

@grasshopper7 This works fine, thanks :)

Can you please share the code how you did it? Much appreciated. Thanks!

alpanakz commented 2 years ago

@simsekMcem & @grasshopper7 can you please share the code how you did this?

I want to set the basefolder.name using an environment variable. Can you please help with line of code?

What I tried is:

Public class TestRunner {

public static String currentOutputDir;  //To be used anywhere in the test as the base output dir for current execution
**public static final  ExtentReports extentReports = ExtentService.getInstance();**

@BeforeClass
public static void setUp() {
    LOGGER.info("\n\nCURRENT_OUTPUT_DIR={}\n\n", System.getenv("CURRENT_OUTPUT_DIR"));
    **extentReports.setSystemInfo("extent.reporter.html.start","true");
    System.out.println(System.getenv("CURRENT_OUTPUT_DIR")+"/CRITQA-BDD-Execution-ResultsHTML.html");
    extentReports.setSystemInfo("extent.reporter.html.out",String.valueOf(System.getenv("CURRENT_OUTPUT_DIR")+"/ BDD-Execution-ResultsHTML.html"));**
    extentReports.setSystemInfo("extent.reporter.html.config",String.valueOf("src/test/resources/com/aventstack/adapter/extent-html-config.xml"));
    LOGGER.info("Tests starting");

}

Please help.

simsekMcem commented 2 years ago

@alpanakz @bijit151288

I have created an additional static util class for this purpose and call its function in RunCucumberTest (cucumber start point) before tests are starting.

public static void generateReportMetadata() {      
      ExtentReports extentReports = ExtentService.getInstance();
      String some_env = System.getenv("some_env");
      extentReports.setSystemInfo("SOMEENV", some_env);
}
public class RunCucumberTest {
  @BeforeClass
  public static void prepareEnvironment() {
    ReportUtil.generateReportMetadata();
  }
}
Pawanrajbhar99 commented 6 months ago

Hi, By using extent.properties can possible to create html report name with time stamp. i try and search every i didn't get anything . using basefolder.datetimepattern property it create foldername with time stamp not a html file name. also i want set dynamic systeminfo for browser name and version can any one help please.