Skip to content

Commit bd780fa

Browse files
committed
Cleaning and extract image comparison #55
2 parents 567e1db + cad9412 commit bd780fa

File tree

17 files changed

+244
-188
lines changed

17 files changed

+244
-188
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Create a feature branch and start improving:
2020
% git checkout -b my-feature-branch
2121
```
2222

23-
HEAD-based development is prefered, which means all changes are applied
23+
HEAD-based development is preferred, which means all changes are applied
2424
directly on top of master.
2525

2626
### Step 3: Commit

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Selenium Shutterbug is a utility library written in Java for making screenshots
99

1010
## Code Example
1111

12-
Screenhot of the page with scrolling (for Chrome to make screenshot of the whole page but not viewport only):
12+
Screenshot of the page with scrolling (for Chrome to make screenshot of the whole page but not viewport only):
1313
```
1414
Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS).save("C:\\testing\\screenshots\\");
1515
```

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
<artifactId>commons-io</artifactId>
5252
<version>2.6</version>
5353
</dependency>
54+
<dependency>
55+
<groupId>org.projectlombok</groupId>
56+
<artifactId>lombok</artifactId>
57+
<version>1.18.8</version>
58+
</dependency>
5459
</dependencies>
5560

5661
<build>

src/main/java/com/assertthat/selenium_shutterbug/core/ElementSnapshot.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.assertthat.selenium_shutterbug.utils.web.Coordinates;
1010
import com.assertthat.selenium_shutterbug.utils.web.ElementOutsideViewportException;
1111
import org.openqa.selenium.WebDriver;
12-
import org.openqa.selenium.WebElement;
1312

1413
import java.awt.image.BufferedImage;
1514
import java.awt.image.RasterFormatException;

src/main/java/com/assertthat/selenium_shutterbug/core/PageSnapshot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
package com.assertthat.selenium_shutterbug.core;
77

8-
import com.assertthat.selenium_shutterbug.utils.web.ElementOutsideViewportException;
98
import com.assertthat.selenium_shutterbug.utils.image.ImageProcessor;
109
import com.assertthat.selenium_shutterbug.utils.web.Coordinates;
10+
import com.assertthat.selenium_shutterbug.utils.web.ElementOutsideViewportException;
1111
import org.openqa.selenium.WebDriver;
1212
import org.openqa.selenium.WebElement;
1313

src/main/java/com/assertthat/selenium_shutterbug/core/Snapshot.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public T withTitle(String title) {
6969
* @return instance of type Snapshot
7070
*/
7171
public T withThumbnail(String path, String name, double scale) {
72-
File thumbnailFile = new File(path.toString(), name);
72+
File thumbnailFile = new File(path, name);
7373
if(!Files.exists(Paths.get(path))) {
7474
thumbnailFile.mkdirs();
7575
}
@@ -90,15 +90,12 @@ public T withThumbnail(String path, String name, double scale) {
9090
* @return instance of type Snapshot
9191
*/
9292
public T withCroppedThumbnail(String path, String name, double scale, double cropWidth, double cropHeight) {
93-
File thumbnailFile = new File(path.toString(), name);
94-
if(!Files.exists(Paths.get(path))) {
95-
thumbnailFile.mkdirs();
96-
}
93+
File thumbnailFile = getFile(path, name);
9794
thumbnailImage=ImageProcessor.cropAndScale(image,scale, cropWidth, cropHeight);
9895
FileUtil.writeImage(thumbnailImage, EXTENSION, thumbnailFile);
9996
return self();
10097
}
101-
98+
10299
/**
103100
* Generate cropped thumbnail of the original screenshot.
104101
* Will save different thumbnails depends on when it was called in the chain.
@@ -111,15 +108,27 @@ public T withCroppedThumbnail(String path, String name, double scale, double cr
111108
* @return instance of type Snapshot
112109
*/
113110
public T withCroppedThumbnail(String path, String name, double scale, int maxWidth, int maxHeight) {
114-
File thumbnailFile = new File(path.toString(), name);
115-
if(!Files.exists(Paths.get(path))) {
116-
thumbnailFile.mkdirs();
117-
}
111+
File thumbnailFile = getFile(path, name);
118112
thumbnailImage=ImageProcessor.cropAndScale(image,scale, maxWidth, maxHeight);
119113
FileUtil.writeImage(thumbnailImage, EXTENSION, thumbnailFile);
120114
return self();
121115
}
122-
116+
117+
/**
118+
* Generate file for cropped thumbnail of the original screenshot.
119+
*
120+
* @param path to save thumbnail image to
121+
* @param name of the resulting image
122+
* @return instance of type File
123+
*/
124+
private File getFile(String path, String name) {
125+
File thumbnailFile = new File(path, name);
126+
if (!Files.exists(Paths.get(path))) {
127+
thumbnailFile.mkdirs();
128+
}
129+
return thumbnailFile;
130+
}
131+
123132
/**
124133
* Generate cropped thumbnail of the original screenshot.
125134
* Will save different thumbnails depends on when it was called in the chain.

src/main/java/com/assertthat/selenium_shutterbug/utils/file/FileUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static String getJsScript(String filePath) {
2424
try {
2525
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
2626
if (is == null) {
27-
// This is needed to load the files in an OSGI enviroment when enclosed in a bundle
27+
// This is needed to load the files in an OSGI environment when enclosed in a bundle
2828
is = FileUtil.class.getClassLoader().getResourceAsStream(filePath);
2929
}
3030
// if the input stream is still null, this will avoid a non descriptive null pointer exception

src/main/java/com/assertthat/selenium_shutterbug/utils/file/UnableSaveSnapshotException.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package com.assertthat.selenium_shutterbug.utils.file;
77

8-
import org.openqa.selenium.WebDriverException;
9-
108
/**
119
* Created by Glib_Briia on 17/06/2016.
1210
*/

0 commit comments

Comments
 (0)