Skip to content

Commit 8d342c8

Browse files
authored
Merge pull request #41 from Visual-Regression-Tracker/feature/38-ignore-areas
[38] Extend TestRunOptions with Ignored Area list
2 parents 827c0c6 + 0048336 commit 8d342c8

File tree

5 files changed

+99
-69
lines changed

5 files changed

+99
-69
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.visual_regression_tracker.sdk_java;
2+
3+
import lombok.Builder;
4+
import lombok.Data;
5+
6+
@Builder
7+
@Data
8+
public class IgnoredArea {
9+
10+
private final Long x;
11+
private final Long y;
12+
private final Long width;
13+
private final Long height;
14+
}

src/main/java/io/visual_regression_tracker/sdk_java/TestRunOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.visual_regression_tracker.sdk_java;
22

3+
import java.util.List;
4+
35
import lombok.Builder;
46
import lombok.Getter;
57

@@ -11,4 +13,5 @@ public class TestRunOptions {
1113
private final String viewport;
1214
private final String device;
1315
private final Float diffTollerancePercent;
16+
private final List<IgnoredArea> ignoredAreas;
1417
}

src/main/java/io/visual_regression_tracker/sdk_java/VisualRegressionTracker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ protected TestRunResponse submitTestRun(String name, String imageBase64,
138138
.viewport(testRunOptions.getViewport())
139139
.device(testRunOptions.getDevice())
140140
.diffTollerancePercent(testRunOptions.getDiffTollerancePercent())
141+
.ignoredAreas(testRunOptions.getIgnoredAreas())
141142
.build();
142143

143144
RequestBody body = RequestBody.create(JSON, gson.toJson(newTestRun));

src/main/java/io/visual_regression_tracker/sdk_java/request/TestRunRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.visual_regression_tracker.sdk_java.request;
22

3+
import java.util.List;
4+
5+
import io.visual_regression_tracker.sdk_java.IgnoredArea;
36
import lombok.Builder;
47
import lombok.Getter;
58

@@ -16,4 +19,5 @@ public class TestRunRequest {
1619
private final String device;
1720
private final Float diffTollerancePercent;
1821
private final String branchName;
22+
private final List<IgnoredArea> ignoredAreas;
1923
}

src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerTest.java

Lines changed: 77 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package io.visual_regression_tracker.sdk_java;
22

3+
import java.io.IOException;
4+
import java.util.Arrays;
5+
import java.util.Objects;
6+
37
import ch.qos.logback.classic.Level;
48
import ch.qos.logback.classic.Logger;
59
import ch.qos.logback.classic.spi.ILoggingEvent;
@@ -23,9 +27,6 @@
2327
import org.testng.annotations.DataProvider;
2428
import org.testng.annotations.Test;
2529

26-
import java.io.IOException;
27-
import java.util.Objects;
28-
2930
import static org.hamcrest.CoreMatchers.containsString;
3031
import static org.hamcrest.CoreMatchers.is;
3132
import static org.hamcrest.MatcherAssert.assertThat;
@@ -34,9 +35,9 @@
3435
import static org.mockito.Mockito.doCallRealMethod;
3536
import static org.mockito.Mockito.mock;
3637
import static org.mockito.Mockito.reset;
38+
import static org.mockito.Mockito.times;
3739
import static org.mockito.Mockito.verify;
3840
import static org.mockito.Mockito.when;
39-
import static org.mockito.Mockito.times;
4041

4142
public class VisualRegressionTrackerTest {
4243

@@ -81,16 +82,16 @@ public void tearDown() {
8182
@Test
8283
public void shouldStartBuild() throws IOException, InterruptedException {
8384
BuildRequest buildRequest = BuildRequest.builder()
84-
.branchName(this.config.getBranchName())
85-
.project(this.config.getProject())
86-
.build();
85+
.branchName(this.config.getBranchName())
86+
.project(this.config.getProject())
87+
.build();
8788
BuildResponse buildResponse = BuildResponse.builder()
88-
.id(BUILD_ID)
89-
.projectId(PROJECT_ID)
90-
.build();
89+
.id(BUILD_ID)
90+
.projectId(PROJECT_ID)
91+
.build();
9192
server.enqueue(new MockResponse()
92-
.setResponseCode(200)
93-
.setBody(gson.toJson(buildResponse)));
93+
.setResponseCode(200)
94+
.setBody(gson.toJson(buildResponse)));
9495

9596
vrt.start();
9697

@@ -106,11 +107,11 @@ public void shouldStopBuild() throws IOException, InterruptedException {
106107
vrt.buildId = BUILD_ID;
107108
vrt.projectId = PROJECT_ID;
108109
BuildResponse buildResponse = BuildResponse.builder()
109-
.id(BUILD_ID)
110-
.build();
110+
.id(BUILD_ID)
111+
.build();
111112
server.enqueue(new MockResponse()
112-
.setResponseCode(200)
113-
.setBody(gson.toJson(buildResponse)));
113+
.setResponseCode(200)
114+
.setBody(gson.toJson(buildResponse)));
114115

115116
vrt.stop();
116117

@@ -129,27 +130,34 @@ public void stopShouldThrowExceptionIfNotStarted() throws IOException {
129130
@Test
130131
public void shouldSubmitTestRun() throws IOException, InterruptedException {
131132
TestRunOptions testRunOptions = TestRunOptions.builder()
132-
.device("Device")
133-
.os("OS")
134-
.browser("Browser")
135-
.viewport("Viewport")
136-
.diffTollerancePercent(0.5f)
137-
.build();
133+
.device("Device")
134+
.os("OS")
135+
.browser("Browser")
136+
.viewport("Viewport")
137+
.diffTollerancePercent(0.5f)
138+
.ignoredAreas(Arrays.asList(IgnoredArea.builder()
139+
.x(100L)
140+
.y(100L)
141+
.height(1L)
142+
.width(1L)
143+
.build()))
144+
.build();
138145
TestRunRequest testRunRequest = TestRunRequest.builder()
139-
.projectId(PROJECT_ID)
140-
.branchName(config.getBranchName())
141-
.buildId(BUILD_ID)
142-
.name(NAME)
143-
.imageBase64(IMAGE_BASE_64)
144-
.os(testRunOptions.getOs())
145-
.browser(testRunOptions.getBrowser())
146-
.viewport(testRunOptions.getViewport())
147-
.device(testRunOptions.getDevice())
148-
.diffTollerancePercent(testRunOptions.getDiffTollerancePercent())
149-
.build();
146+
.projectId(PROJECT_ID)
147+
.branchName(config.getBranchName())
148+
.buildId(BUILD_ID)
149+
.name(NAME)
150+
.imageBase64(IMAGE_BASE_64)
151+
.os(testRunOptions.getOs())
152+
.browser(testRunOptions.getBrowser())
153+
.viewport(testRunOptions.getViewport())
154+
.device(testRunOptions.getDevice())
155+
.diffTollerancePercent(testRunOptions.getDiffTollerancePercent())
156+
.ignoredAreas(testRunOptions.getIgnoredAreas())
157+
.build();
150158
TestRunResponse testRunResponse = TestRunResponse.builder()
151-
.status(TestRunStatus.UNRESOLVED)
152-
.build();
159+
.status(TestRunStatus.UNRESOLVED)
160+
.build();
153161
server.enqueue(new MockResponse().setBody(gson.toJson(testRunResponse)));
154162
vrt.buildId = BUILD_ID;
155163
vrt.projectId = PROJECT_ID;
@@ -173,24 +181,24 @@ public void submitTestRunShouldThrowIfNotStarted() throws IOException {
173181

174182
@DataProvider(name = "trackErrorCases")
175183
public Object[][] trackErrorCases() {
176-
return new Object[][]{
184+
return new Object[][] {
177185
{
178186
TestRunResponse.builder()
179-
.url("https://someurl.com/test/123123")
180-
.imageName("imageName")
181-
.baselineName("baselineName")
182-
.diffName("diffName")
183-
.status(TestRunStatus.UNRESOLVED)
187+
.url("https://someurl.com/test/123123")
188+
.imageName("imageName")
189+
.baselineName("baselineName")
190+
.diffName("diffName")
191+
.status(TestRunStatus.UNRESOLVED)
184192
.build(),
185193
"Difference found: https://someurl.com/test/123123"
186194
},
187195
{
188196
TestRunResponse.builder()
189-
.url("https://someurl.com/test/123123")
190-
.imageName("imageName")
191-
.baselineName("baselineName")
192-
.diffName("diffName")
193-
.status(TestRunStatus.NEW)
197+
.url("https://someurl.com/test/123123")
198+
.imageName("imageName")
199+
.baselineName("baselineName")
200+
.diffName("diffName")
201+
.status(TestRunStatus.NEW)
194202
.build(),
195203
"No baseline: https://someurl.com/test/123123"
196204
}
@@ -228,19 +236,19 @@ public void trackShouldLogSevere(TestRunResponse testRunResponse, String expecte
228236

229237
@DataProvider(name = "shouldTrackPassCases")
230238
public Object[][] shouldTrackPassCases() {
231-
return new Object[][]{
239+
return new Object[][] {
232240
{
233241
TestRunResponse.builder()
234-
.id("someId")
235-
.imageName("imageName")
236-
.baselineName("baselineName")
237-
.diffName("diffName")
238-
.diffPercent(12.32f)
239-
.diffTollerancePercent(0.01f)
240-
.pixelMisMatchCount(1)
241-
.merge(false)
242-
.url("https://someurl.com/test/123123")
243-
.status(TestRunStatus.OK)
242+
.id("someId")
243+
.imageName("imageName")
244+
.baselineName("baselineName")
245+
.diffName("diffName")
246+
.diffPercent(12.32f)
247+
.diffTollerancePercent(0.01f)
248+
.pixelMisMatchCount(1)
249+
.merge(false)
250+
.url("https://someurl.com/test/123123")
251+
.status(TestRunStatus.OK)
244252
.build(),
245253
}
246254
};
@@ -270,7 +278,7 @@ public void shouldTrackOverload() throws IOException {
270278

271279
@DataProvider(name = "shouldReturnIsStartedCases")
272280
public Object[][] shouldReturnIsStartedCases() {
273-
return new Object[][]{
281+
return new Object[][] {
274282
{null, null, false},
275283
{null, "some", false},
276284
{"some", null, false},
@@ -291,22 +299,22 @@ public void shouldReturnIsStarted(String buildId, String projectId, boolean expe
291299
@Test
292300
public void handleRequestShouldThrowIfNotSuccess() throws IOException {
293301
String error = "{\n" +
294-
" \"statusCode\": 404,\n" +
295-
" \"message\": \"Project not found\"\n" +
296-
"}";
302+
" \"statusCode\": 404,\n" +
303+
" \"message\": \"Project not found\"\n" +
304+
"}";
297305
Request mockRequest = new Request.Builder()
298-
.url(config.getApiUrl())
299-
.build();
306+
.url(config.getApiUrl())
307+
.build();
300308

301309
String exceptionMessage = "";
302310
try {
303311
vrt.handleResponse(new Response.Builder()
304-
.request(mockRequest)
305-
.protocol(Protocol.HTTP_2)
306-
.code(404)
307-
.message("Not found")
308-
.body(ResponseBody.create(error, VisualRegressionTracker.JSON))
309-
.build(), Object.class);
312+
.request(mockRequest)
313+
.protocol(Protocol.HTTP_2)
314+
.code(404)
315+
.message("Not found")
316+
.body(ResponseBody.create(error, VisualRegressionTracker.JSON))
317+
.build(), Object.class);
310318
} catch (TestRunException ex) {
311319
exceptionMessage = ex.getMessage();
312320
}

0 commit comments

Comments
 (0)