Generate report directory

38 views
Skip to first unread message

Sathvik P

unread,
Oct 21, 2024, 6:13:05 AM10/21/24
to Maven JMeter Plugin Users
Hi,

I am trying to have a timestamp in the folder name created by jmeter for reports generated. Intent is to have a custom directory to save each html result generated through maven. 
Is this possible?

Thanks

Er. Heera Babu

unread,
Oct 21, 2024, 7:39:14 AM10/21/24
to Maven JMeter Plugin Users
Yes, it is possible to customize the directory for saving JMeter reports with a timestamp in the folder name when generating reports through Maven. You can use a combination of Maven commands, JMeter properties, and shell scripting (or similar techniques) to achieve this.

Here is a step-by-step guide:

### Step 1: Modify Maven `pom.xml`

Ensure your `pom.xml` includes the JMeter Maven plugin configuration. For adding a custom directory with a timestamp, you can set the property `jmeter.save.saveservice.output_directory` in your Maven build command or define it in the plugin configuration.

Add the following to your `pom.xml`:

```xml
<build>
    <plugins>
        <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <id>jmeter-tests</id>
                    <goals>
                        <goal>jmeter</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- Specify your result output directory with timestamp -->
                <resultFilesDirectory>${project.build.directory}/jmeter-results-${timestamp}</resultFilesDirectory>
                <generateReports>true</generateReports>
            </configuration>
        </plugin>
    </plugins>
</build>
```

You can define the timestamp dynamically during the Maven build.

### Step 2: Use Maven Properties for Dynamic Timestamp

You can pass a timestamp to Maven using a property. You can add a timestamp during the Maven build by using the `mvn` command with a property:

```bash
mvn clean verify -Dtoday=$(date +%Y-%m-%d_%H-%M-%S) -Djmeter.save.saveservice.output_directory=target/jmeter-report-${today}
```

This will create a custom directory for the generated JMeter reports with the timestamp in the format `YYYY-MM-DD_HH-MM-SS`.

### Step 3: Add a GET API Test in JMeter

To add a GET API test in your JMeter test plan:

1. **Open JMeter GUI** and create a test plan.
2. **Add a Thread Group**: Right-click on the Test Plan → Add → Threads (Users) → Thread Group.
3. **Add an HTTP Request Sampler**: Right-click on the Thread Group → Add → Sampler → HTTP Request.
    - In the HTTP Request:
        - Set the `Server Name or IP` field to the API URL (without the protocol).
        - Set the `Path` field to the endpoint you are testing.
        - Set the HTTP Method to `GET`.

4. **Add a Listener** to view the results:
    - Right-click on the Thread Group → Add → Listener → View Results Tree.

5. Save the test plan as `.jmx` file.

### Step 4: Run JMeter Test with Maven

Once your `jmx` test file is ready, you can run it using Maven:

```bash
mvn clean verify -Djmeter.testfiles=your_test_file.jmx
```

This will execute the test, and the results will be stored in the custom directory specified earlier with the timestamp.

By following these steps, you can create a custom directory for each report generated by JMeter using Maven with a timestamp, and your GET API test will be included in the results.

Vincent Daburon

unread,
Oct 24, 2024, 11:34:57 AM10/24/24
to Maven JMeter Plugin Users
May be use (not tested)

maven.build.timestamp
The timestamp that denotes the start of the build (UTC). Since Maven 2.1.0-M1
    <project>
      ...
      <properties>
        <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
      </properties>
      ...
    </project>

and
<resultFilesDirectory>${project.build.directory}/jmeter-results-${ maven.build.timestamp}</resultFilesDirectory>

Vincent Daburon

unread,
Oct 24, 2024, 11:38:42 AM10/24/24
to Maven JMeter Plugin Users
You need to change the timestamp format because the character ":" is not allowed  in a filename
better :
<maven.build.timestamp.format>yyyy-MM-dd'T'HH'h'mm'm'ss's'</maven.build.timestamp.format>
e.g: 2024-10-24T18h34m12s

Vincent Daburon

unread,
Nov 7, 2024, 6:41:45 AM11/7/24
to Maven JMeter Plugin Users
Hi,
I add explanation about the reportDirectory configuration.
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/wiki/Generating-Reports

===================================================

By default the result directory is set to "${project.build.directory}/jmeter/reports" but you can change the report directory with add to configuration <reportDirectory>${project.build.directory}/report-new-directory</reportDirectory>.

You could use the maven variable ${maven.build.timestamp} to add the timestamp in the report directory name.

  1. Change the timestamp format without character':' likes <properties><maven.build.timestamp.format>yyyy-MM-dd'T'HH'h'mm'm'ss's'</maven.build.timestamp.format></properties>
  2. In the configuration, set the reportDirectory likes : <reportDirectory>${project.build.directory}/report-${maven.build.timestamp}</reportDirectory> , e.g directory name : target/report-2024-11-07T11h19m21s
On Monday, October 21, 2024 at 12:13:05 PM UTC+2 Sathvik P wrote:
Reply all
Reply to author
Forward
0 new messages