To use our Java API to generate and download reports, use our classes as explained in Create the Java Results API client.
First instantiate a ResultsAPIClient
providing a URL and API key.
Then call method GenerateReport()
to generate a report, and method DownloadReport()
to download a report.
To configure your Java project, it is recommended to use Maven.
In a Java Maven project, you need to add a dependency to the Maven settings file (pom.xml) using the examples below:
<repositories>
<repository>
<id>neotys-public-releases</id>
<url>http://maven.neotys.com/content/repositories/releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.neotys.rest</groupId>
<artifactId>neotys-rest-api-results-client-olingo</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
If your project is not developed using Maven, it is necessary to include the JAR files available in the \api
folder of the NeoLoad installation directory:
<install-dir>
\api\Results API Client\Java
folder<install-dir>
\api\Common\Java
folderIn this example, we generate a PDF report for test result name “MyFirstTest”, we wait 3 seconds for the generation, and then we retrieve the byte array.
import com.neotys.rest.data.BinaryData;
import com.neotys.rest.results.client.ResultsAPIClient;
import com.neotys.rest.results.client.ResultsAPIClientFactory;
import com.neotys.rest.results.model.DownloadReportParams;
import com.neotys.rest.results.model.Format;
import com.neotys.rest.results.model.GenerateReportParams;
public class GenerateAndDownloadReportExample {
public static void main(String[] args) throws Exception {
// Instanciate ResultsAPIClient by specifying the connection URL
final ResultsAPIClient client = ResultsAPIClientFactory.newClient("http://localhost:7400/Results/v1/Service.svc/");
// Create the params to generate a report, based on test result "MyFirstTest" and format PDF
final GenerateReportParams generateReportParams = GenerateReportParams.newBuilder().testResultName("MyFirstTest").format(Format.PDF).build();
// Trigger the generation of the report and retrieve the report Id
final String reportId = client.generateReport(generateReportParams);
// Download the report from the id
final BinaryData reportBinary = client.downloadReport(new DownloadReportParams(reportId));
}
}
In this example, we generate a RTF comparison report for test result name “MyTest1” and “MyTest2”, we wait 3 seconds for the generation, and then we download the file on disk (folder C:\tmp).
import com.neotys.rest.results.client.ResultsAPIClient;
import com.neotys.rest.results.client.ResultsAPIClientFactory;
import com.neotys.rest.results.model.DownloadReportParams;
import com.neotys.rest.results.model.Format;
import com.neotys.rest.results.model.GenerateReportParams;
public class GenerateAndDownloadComparisonReportExample {
public static void main(String[] args) throws Exception {
// Instanciate ResultsAPIClient by specifying the connection URL
final ResultsAPIClient client = ResultsAPIClientFactory.newClient("http://localhost:7400/Results/v1/Service.svc/");
// Create the params to generate a report, based on test result "MyFirstTest" and format PDF
final GenerateReportParams generateReportParams = GenerateReportParams.newBuilder().comparisonReport(true).testResultName("MyTest1")
.otherTestResultName("MyTest2").format(Format.RTF).build();
// Trigger the generation of the report and retrieve the report Id
final String reportId = client.generateReport(generateReportParams);
// Download the report from the id
final String destinationFolder = "C:\\tmp";
client.saveReport(new DownloadReportParams(reportId), destinationFolder);
}
}