Open simsekMcem opened 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.
I'll let you know tomorrow, thanks for the quick response
@grasshopper7 This works fine, thanks :)
@grasshopper7 This works fine, thanks :)
Can you please share the code how you did it? Much appreciated. Thanks!
@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.
@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();
}
}
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.
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.