Skip to content

Commit 8a7fc7f

Browse files
committed
Add option to test only specific region of PDF(s)/Image(s)
1 parent 5a06ca2 commit 8a7fc7f

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ The tool build in java and requires minimal set of parameters the minimal comman
123123
**Example:** `-arg "300,300,500,100|500,500,200,200"` will create accessibility graphics regions at <br>
124124
+ x:300, y:300, with width:500, height:100 and <br>
125125
+ x:500, y:500, with width:200, height:200 <br>
126+
+ `-rc` - Capture only a particular region of PDFs/Images. <br>
127+
**Example:** `-rc "200,500,1000,1000"` instructs ImageTester to only test region with: <br>
128+
+ x:200, y:500, with width:1000, height:1000
126129

127130
### Using The Batch Mapper
128131
The Batch Mapper is a feature that allows you to specify tests from a CSV instead of supplying a path or file in the traditional way.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.applitools.imagetester</groupId>
66
<artifactId>ImageTester</artifactId>
7-
<version>3.1.5</version>
7+
<version>3.2.0</version>
88
<packaging>jar</packaging>
99
<properties>
1010
<maven.compiler.source>1.8</maven.compiler.source>

src/main/java/com/applitools/imagetester/ImageTester.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public static void main(String[] args) {
114114
config.setAccessibilityLargeTextRegions(cmd.getOptionValue("arl", null));
115115
config.setAccessibilityBoldTextRegions(cmd.getOptionValue("arb", null));
116116
config.setAccessibilityGraphicsRegions(cmd.getOptionValue("arg", null));
117+
config.setCaptureRegion(cmd.getOptionValue("rc", null));
117118

118119
// Full page for ac regions capability
119120
if (cmd.hasOption("arr") && config.accessibilityRegularTextRegions == null) {
@@ -217,6 +218,7 @@ private static void runTestWithBatchMapper(final Logger logger, final CommandLin
217218
currentConfiguration.setBatchInfo(cmd.getOptionValue("fb", null), cmd.hasOption("nc"));
218219
currentConfiguration.dontCloseBatches = cmd.hasOption("dcb");
219220
currentConfiguration.shouldThrowException = cmd.hasOption("te");
221+
currentConfiguration.setCaptureRegion(cmd.getOptionValue("rc", null));
220222

221223
try {
222224
File root = new File(currentBatch.filePath);
@@ -502,6 +504,12 @@ private static Options getOptions() {
502504
.hasArgs()
503505
.optionalArg(true)
504506
.build());
507+
options.addOption(Option.builder("rc")
508+
.longOpt("regionCapture")
509+
.desc("Tests specific region of images and PDFs.\nexample: `-rc 0,200,1000,1000`")
510+
.hasArgs()
511+
.optionalArg(false)
512+
.build());
505513

506514
EyesUtilitiesConfig.injectOptions(options);
507515
return options;

src/main/java/com/applitools/imagetester/TestObjects/ImagesCheckSettingsFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public ImagesCheckSettingsFactory(BufferedImage image, Config config) {
2020
this.config = config;
2121
}
2222
public ImagesCheckSettingsFactory(BufferedImage image, Config config, RectangleSize viewport) {
23-
this.imagesCheckSettings = new ImagesCheckSettings(image);
23+
this.imagesCheckSettings = config.captureRegion == null ?
24+
new ImagesCheckSettings(image) :
25+
new ImagesCheckSettings(image, config.captureRegion);
2426
this.config = config;
2527
this.viewPortRegion = new Region(0, 0, viewport.getWidth(), viewport.getHeight());
2628
}

src/main/java/com/applitools/imagetester/lib/Config.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class Config {
4949
public boolean accessibilityLargeTextFullPage = false;
5050
public boolean accessibilityBoldTextFullPage = false;
5151
public boolean accessibilityGraphicsFullPage = false;
52+
public Region captureRegion;
5253

5354
public void setViewport(String viewport) {
5455
if (viewport == null) return;
@@ -60,6 +61,19 @@ public void setViewport(String viewport) {
6061
Integer.parseInt(dims[1]));
6162
}
6263

64+
public void setCaptureRegion(String captureRegionSpecs) {
65+
if (captureRegionSpecs == null) return;
66+
String[] regionSpecs = captureRegionSpecs.split(",");
67+
if (regionSpecs.length != 4)
68+
throw new RuntimeException("Invalid region capture values, make sure the call is -rc <left>,<top>,<width>,<height>");
69+
this.captureRegion = new Region(
70+
Integer.parseInt(regionSpecs[0]),
71+
Integer.parseInt(regionSpecs[1]),
72+
Integer.parseInt(regionSpecs[2]),
73+
Integer.parseInt(regionSpecs[3])
74+
);
75+
}
76+
6377
public void setProxy(String[] proxy) {
6478
if (proxy != null && proxy.length > 0)
6579
if (proxy.length == 1) {

0 commit comments

Comments
 (0)