Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Java SDK for [Visual Regression Tracker](https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker)

## Gradle
```
```yml
repositories {
maven { url 'https://jitpack.io' }
}
```
```
```yml
dependencies {
implementation group: 'com.github.visual-regression-tracker', name: 'sdk-java', version: '${VERSION}'
implementation group: 'com.github.visual-regression-tracker', name: 'sdk-java', version: '${REPLACE_THIS_VALUE}'
}
```
## Maven
```
```xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```
```
```xml
<dependency>
<groupId>com.github.Visual-Regression-Tracker</groupId>
<artifactId>sdk-java</artifactId>
<version>${VERSION}</version>
<version>${REPLACE_THIS_VALUE}</version>
</dependency>
```
[Available versions](https://github.com/Visual-Regression-Tracker/sdk-java/releases)
Expand All @@ -33,41 +33,41 @@ More info about https://jitpack.io/

## Usage
* Create config
```
```java
VisualRegressionTrackerConfig config = new VisualRegressionTrackerConfig(
// apiUrl - URL to Visual Regression Tracker backend
// apiUrl - URL where backend is running
"http://localhost:4200",

// projectId - copy from project details
// project - Project name or ID
"003f5fcf-6c5f-4f1f-a99f-82a697711382",

// apiKey - copy from user details
// apiKey - User apiKey
"F5Z2H0H2SNMXZVHX0EA4YQM1MGDD",

// branch - helps to identify version of application under test
// branch - Current git branch
"develop"
);
```
* Create an instance of `VisualRegressionTracker`
```
```java
VisualRegressionTracker visualRegressionTracker = new VisualRegressionTracker(config);
```
* Take a screenshot as String in Base64 format
```
```java
// Selenium example
String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
```
* Track image

Default options
```
```java
visualRegressionTracker.track(
"Name for test",
screenshotBase64
);
```
With specific options
```
```java
visualRegressionTracker.track(
"Name for test",
screenshotBase64,
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'io.visual-regression-tracker.sdk-java'
version '1.3.0'
version '2.0.0'

apply plugin: 'java'
apply plugin: "io.freefair.lombok"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class VisualRegressionTracker {
Gson gson = new Gson();
VisualRegressionTrackerConfig visualRegressionTrackerConfig;
String buildId;
String projectId;
OkHttpClient client;

public VisualRegressionTracker(VisualRegressionTrackerConfig visualRegressionTrackerConfig) {
Expand All @@ -27,7 +28,7 @@ void startBuild() throws IOException {
if (this.buildId == null) {
BuildRequest newBuild = BuildRequest.builder()
.branchName(this.visualRegressionTrackerConfig.branchName)
.projectId(this.visualRegressionTrackerConfig.projectId)
.project(this.visualRegressionTrackerConfig.project)
.build();

RequestBody body = RequestBody.create(gson.toJson(newBuild), JSON);
Expand All @@ -41,13 +42,14 @@ void startBuild() throws IOException {
try (ResponseBody responseBody = client.newCall(request).execute().body()) {
BuildResponse buildDTO = new Gson().fromJson(responseBody.string(), BuildResponse.class);
this.buildId = buildDTO.getId();
this.projectId = buildDTO.getProjectId();
}
}
}

TestRunResponse submitTestRun(String name, String imageBase64, TestRunOptions testRunOptions) throws IOException {
TestRunRequest newTestRun = TestRunRequest.builder()
.projectId(this.visualRegressionTrackerConfig.projectId)
.projectId(this.projectId)
.buildId(this.buildId)
.name(name)
.imageBase64(imageBase64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@AllArgsConstructor
public class VisualRegressionTrackerConfig {
String apiUrl;
String projectId;
String project;
String apiKey;
String branchName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

@Builder
public class BuildRequest {
String projectId;
String project;
String branchName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
@Getter
public class BuildResponse {
String id;
String projectId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ void tearDown() {
@Test
void shouldStartBuild() throws IOException, InterruptedException {
String buildId = "123123";
String projectId = "projectId";
BuildRequest buildRequest = BuildRequest.builder()
.branchName(this.config.branchName)
.projectId(this.config.projectId)
.project(this.config.project)
.build();
BuildResponse buildResponse = BuildResponse.builder()
.id(buildId)
.projectId(projectId)
.build();
server.enqueue(new MockResponse().setBody(gson.toJson(buildResponse)));

Expand All @@ -65,11 +67,13 @@ void shouldStartBuild() throws IOException, InterruptedException {
MatcherAssert.assertThat(request.getHeader(vrt.apiKeyHeaderName), CoreMatchers.is(config.apiKey));
MatcherAssert.assertThat(request.getBody().readUtf8(), CoreMatchers.is(gson.toJson(buildRequest)));
MatcherAssert.assertThat(vrt.buildId, CoreMatchers.is(buildId));
MatcherAssert.assertThat(vrt.projectId, CoreMatchers.is(projectId));
}

@Test
void shouldSubmitTestRun() throws IOException, InterruptedException {
String buildId = "123123";
String projectId = "projectId";
String name = "Test name";
String imageBase64 = "image";
TestRunOptions testRunOptions = TestRunOptions.builder()
Expand All @@ -80,7 +84,7 @@ void shouldSubmitTestRun() throws IOException, InterruptedException {
.diffTollerancePercent(5)
.build();
TestRunRequest testRunRequest = TestRunRequest.builder()
.projectId(this.config.projectId)
.projectId(projectId)
.buildId(buildId)
.name(name)
.imageBase64(imageBase64)
Expand Down