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.