Skip to content

Commit 2b69fe4

Browse files
committed
Mass refactoring
1 parent 8d4a940 commit 2b69fe4

File tree

17 files changed

+122
-136
lines changed

17 files changed

+122
-136
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: java
22
script: ./gradlew build
33

4-
jdk: oraclejdk8
4+
jdk: oraclejdk7

build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
group 'com.assertthat'
22
version '0.1'
33

4-
apply plugin: 'groovy'
4+
apply plugin: 'java'
55

6-
sourceCompatibility = 1.8
6+
sourceCompatibility = 1.7
77

88
repositories {
99
mavenCentral()
1010
}
1111

1212
dependencies {
13-
testCompile 'org.codehaus.groovy:groovy-test:2.4.3'
1413
testCompile 'junit:junit:4.12'
1514
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.53.0'
1615
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = 'selenium-screenshotter'
1+
rootProject.name = 'shutterbug'
22

src/main/java/com/assertthat/selenium_screenshotter/core/ElementScreenshot.java

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.assertthat.shutterbug.core;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.WebElement;
5+
6+
/**
7+
* Created by Glib_Briia on 17/06/2016.
8+
*/
9+
public class ElementSnapshot extends Snapshot {
10+
11+
ElementSnapshot(WebDriver driver, WebElement element) {
12+
this.driver = driver;
13+
}
14+
15+
@Override
16+
protected ElementSnapshot self() {
17+
return this;
18+
}
19+
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.assertthat.selenium_screenshotter.core;
1+
package com.assertthat.shutterbug.core;
22

3-
import com.assertthat.selenium_screenshotter.utils.image.ImageProcessor;
4-
import com.assertthat.selenium_screenshotter.utils.web.Coordinates;
3+
import com.assertthat.shutterbug.utils.image.ImageProcessor;
4+
import com.assertthat.shutterbug.utils.web.Coordinates;
55
import org.openqa.selenium.WebDriver;
66
import org.openqa.selenium.WebElement;
77

@@ -10,9 +10,9 @@
1010
/**
1111
* Created by Glib_Briia on 17/06/2016.
1212
*/
13-
public class PageScreenshot extends Screenshot<PageScreenshot> {
13+
public class PageSnapshot extends Snapshot {
1414

15-
PageScreenshot(WebDriver driver) {
15+
PageSnapshot(WebDriver driver) {
1616
this.driver = driver;
1717
}
1818

@@ -21,9 +21,9 @@ public class PageScreenshot extends Screenshot<PageScreenshot> {
2121
* and line width 3.
2222
*
2323
* @param element WebElement to be highlighted
24-
* @return instance of type PageScreenshot
24+
* @return instance of type PageSnapshot
2525
*/
26-
public PageScreenshot highlight(WebElement element) {
26+
public PageSnapshot highlight(WebElement element) {
2727
highlight(element, Color.red, 3);
2828
return this;
2929
}
@@ -35,9 +35,9 @@ public PageScreenshot highlight(WebElement element) {
3535
* @param element WebElement to be highlighted
3636
* @param color color of the line
3737
* @param lineWidth width of the line
38-
* @return instance of type PageScreenshot
38+
* @return instance of type PageSnapshot
3939
*/
40-
public PageScreenshot highlight(WebElement element, Color color, int lineWidth) {
40+
public PageSnapshot highlight(WebElement element, Color color, int lineWidth) {
4141
image = ImageProcessor.highlight(image, new Coordinates(element), color, lineWidth);
4242
return this;
4343
}
@@ -50,9 +50,9 @@ public PageScreenshot highlight(WebElement element, Color color, int lineWidth)
5050
* and line width 3
5151
* @param text test to be places above highlighted element with
5252
* Color.red, font "Serif", BOLD, size 20
53-
* @return instance of type PageScreenshot
53+
* @return instance of type PageSnapshot
5454
*/
55-
public PageScreenshot highlightWithText(WebElement element, String text) {
55+
public PageSnapshot highlightWithText(WebElement element, String text) {
5656
highlightWithText(element, Color.red, 3, text, Color.red, new Font("Serif", Font.BOLD, 20));
5757
return this;
5858
}
@@ -67,9 +67,9 @@ public PageScreenshot highlightWithText(WebElement element, String text) {
6767
* @param text text to be placed above the highlighted element
6868
* @param textColor color of the text
6969
* @param textFont text font
70-
* @return instance of type PageScreenshot
70+
* @return instance of type PageSnapshot
7171
*/
72-
public PageScreenshot highlightWithText(WebElement element, Color elementColor, int lineWidth, String text, Color textColor, Font textFont) {
72+
public PageSnapshot highlightWithText(WebElement element, Color elementColor, int lineWidth, String text, Color textColor, Font textFont) {
7373
highlight(element, elementColor, 0);
7474
Coordinates coords = new Coordinates(element);
7575
image = ImageProcessor.addText(image, coords.getX(), coords.getY() - textFont.getSize() / 2, text, textColor, textFont);
@@ -79,9 +79,9 @@ public PageScreenshot highlightWithText(WebElement element, Color elementColor,
7979
/**
8080
* Blur the entire page.
8181
*
82-
* @return instance of type PageScreenshot
82+
* @return instance of type PageSnapshot
8383
*/
84-
public PageScreenshot blur() {
84+
public PageSnapshot blur() {
8585
image = ImageProcessor.blur(image);
8686
return this;
8787
}
@@ -90,9 +90,9 @@ public PageScreenshot blur() {
9090
* Blur provided element within the page only.
9191
*
9292
* @param element WebElement to be blurred
93-
* @return instance of type PageScreenshot
93+
* @return instance of type PageSnapshot
9494
*/
95-
public PageScreenshot blur(WebElement element) {
95+
public PageSnapshot blur(WebElement element) {
9696
image = ImageProcessor.blurArea(image, new Coordinates(element));
9797
return this;
9898
}
@@ -102,9 +102,9 @@ public PageScreenshot blur(WebElement element) {
102102
* Original colors remain on the rest of the page.
103103
*
104104
* @param element WebElement within the page to be made 'monochrome'
105-
* @return instance of type PageScreenshot
105+
* @return instance of type PageSnapshot
106106
*/
107-
public PageScreenshot monochrome(WebElement element) {
107+
public PageSnapshot monochrome(WebElement element) {
108108
image = ImageProcessor.monochromeArea(image, new Coordinates(element));
109109
return this;
110110
}
@@ -113,15 +113,15 @@ public PageScreenshot monochrome(WebElement element) {
113113
* Blurs all the page except the element provided.
114114
*
115115
* @param element WebElement to stay not blurred
116-
* @return instance of type PageScreenshot
116+
* @return instance of type PageSnapshot
117117
*/
118-
public PageScreenshot blurExcept(WebElement element) {
118+
public PageSnapshot blurExcept(WebElement element) {
119119
image = ImageProcessor.blurExceptArea(image, new Coordinates(element));
120120
return this;
121121
}
122122

123123
@Override
124-
protected PageScreenshot self() {
124+
protected PageSnapshot self() {
125125
return this;
126126
}
127127

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
package com.assertthat.selenium_screenshotter.core;
1+
package com.assertthat.shutterbug.core;
22

3-
import com.assertthat.selenium_screenshotter.utils.image.ImageProcessor;
4-
import com.assertthat.selenium_screenshotter.utils.web.Browser;
5-
import com.assertthat.selenium_screenshotter.utils.web.ScrollStrategy;
3+
import com.assertthat.shutterbug.utils.image.ImageProcessor;
4+
import com.assertthat.shutterbug.utils.web.Browser;
5+
import com.assertthat.shutterbug.utils.web.ScrollStrategy;
66
import org.openqa.selenium.WebDriver;
77
import org.openqa.selenium.WebElement;
88

99
/**
1010
* Created by Glib_Briia on 26/06/2016.
1111
*/
12-
public class ScreenshotFactory {
12+
public class Shutterbug {
1313

1414
/**
1515
* Make screenshot of the viewport only.
1616
* To be used when screenshotting the page
1717
* and don't need to scroll while making screenshots (FF, IE).
1818
*
1919
* @param driver WebDriver instance
20-
* @return PageScreenshot instance
20+
* @return PageSnapshot instance
2121
*/
22-
public static PageScreenshot page(WebDriver driver) {
22+
public static PageSnapshot shootPage(WebDriver driver) {
2323
Browser browser = new Browser(driver);
24-
PageScreenshot pageScreenshot = new PageScreenshot(driver);
24+
PageSnapshot pageScreenshot = new PageSnapshot(driver);
2525
pageScreenshot.setImage(browser.takeScreenshot());
2626
return pageScreenshot;
2727
}
@@ -33,11 +33,11 @@ public static PageScreenshot page(WebDriver driver) {
3333
*
3434
* @param driver WebDriver instance
3535
* @param scroll ScrollStrategy How you need to scroll
36-
* @return PageScreenshot instance
36+
* @return PageSnapshot instance
3737
*/
38-
public static PageScreenshot page(WebDriver driver, ScrollStrategy scroll) {
38+
public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll) {
3939
Browser browser = new Browser(driver);
40-
PageScreenshot pageScreenshot = new PageScreenshot(driver);
40+
PageSnapshot pageScreenshot = new PageSnapshot(driver);
4141
switch (scroll) {
4242
case HORIZONTALLY:
4343
pageScreenshot.setImage(browser.takeScreenshotScrollHorizontally());
@@ -56,11 +56,11 @@ public static PageScreenshot page(WebDriver driver, ScrollStrategy scroll) {
5656
*
5757
* @param driver WebDriver instance
5858
* @param element WebElement instance to be screenshotted
59-
* @return ElementScreenshot instance
59+
* @return ElementSnapshot instance
6060
*/
61-
public static ElementScreenshot element(WebDriver driver, WebElement element) {
61+
public static ElementSnapshot shootElement(WebDriver driver, WebElement element) {
6262
Browser browser = new Browser(driver);
63-
ElementScreenshot elementScreenshot = new ElementScreenshot(driver, element);
63+
ElementSnapshot elementScreenshot = new ElementSnapshot(driver, element);
6464
browser.scrollToElement(element);
6565
elementScreenshot.setImage(browser.takeScreenshot());
6666
elementScreenshot.setImage(ImageProcessor.getElement(elementScreenshot.getImage(), browser.getBoundingClientRect(element)));

src/main/java/com/assertthat/selenium_screenshotter/core/Screenshot.java renamed to src/main/java/com/assertthat/shutterbug/core/Snapshot.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
package com.assertthat.selenium_screenshotter.core;
1+
package com.assertthat.shutterbug.core;
22

3-
import com.assertthat.selenium_screenshotter.utils.file.FileUtil;
4-
import com.assertthat.selenium_screenshotter.utils.image.ImageProcessor;
5-
import com.assertthat.selenium_screenshotter.utils.web.Browser;
6-
import com.assertthat.selenium_screenshotter.utils.web.ScrollStrategy;
3+
import com.assertthat.shutterbug.utils.file.FileUtil;
4+
import com.assertthat.shutterbug.utils.image.ImageProcessor;
75
import org.openqa.selenium.WebDriver;
8-
import org.openqa.selenium.WebElement;
96

107
import java.awt.*;
118
import java.awt.image.BufferedImage;
129
import java.io.File;
1310
import java.nio.file.Path;
1411
import java.nio.file.Paths;
15-
import java.time.LocalDateTime;
16-
import java.time.format.DateTimeFormatter;
12+
import java.text.SimpleDateFormat;
13+
import java.util.Date;
1714

1815
/**
1916
* Created by Glib_Briia on 17/06/2016.
2017
*/
21-
public abstract class Screenshot<T extends Screenshot<T>> {
18+
public abstract class Snapshot<T extends Snapshot> {
2219

2320
private static final String extension = "PNG";
2421
protected BufferedImage image;
2522
protected BufferedImage thumbnailImage;
2623
protected WebDriver driver;
27-
private String fileName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss_SSS"))
24+
private String fileName = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS").format(new Date())
2825
+ "." + extension.toLowerCase();
2926
private Path location = Paths.get("./screenshots/");
3027
private String title;
@@ -34,7 +31,7 @@ public abstract class Screenshot<T extends Screenshot<T>> {
3431
/**
3532
* @param name file name of the resulted image
3633
* by default will be timestamp in format: 'yyyy_MM_dd_HH_mm_ss_SSS'.
37-
* @return instance of type Screenshot
34+
* @return instance of type Snapshot
3835
*/
3936
public T withName(String name) {
4037
if (name != null) {
@@ -46,7 +43,7 @@ public T withName(String name) {
4643
/**
4744
* @param title title of the resulted image.
4845
* Won't be assigned by default.
49-
* @return instance of type Screenshot
46+
* @return instance of type Snapshot
5047
*/
5148
public T withTitle(String title) {
5249
this.title = title;
@@ -61,12 +58,12 @@ public T withTitle(String title) {
6158
* @param path to save thumbnail image to
6259
* @param name of the resulting image
6360
* @param scale to apply
64-
* @return instance of type Screenshot
61+
* @return instance of type Snapshot
6562
*/
6663
public T withThumbnail(String path, String name, double scale) {
6764
File thumbnailFile = new File(path.toString(), name);
6865
thumbnailFile.mkdirs();
69-
thumbnailImage=ImageProcessor.scale(image,0.5);
66+
thumbnailImage=ImageProcessor.scale(image,scale);
7067
FileUtil.writeImage(thumbnailImage, extension, thumbnailFile);
7168
return self();
7269
}
@@ -76,7 +73,7 @@ public T withThumbnail(String path, String name, double scale) {
7673
* Will save different thumbnails depends on when it was called in the chain.
7774
*
7875
* @param scale to apply
79-
* @return instance of type Screenshot
76+
* @return instance of type Snapshot
8077
*/
8178
public T withThumbnail(double scale) {
8279
withThumbnail(Paths.get(location.toString(),"./thumbnails").toString(),"thumb_"+fileName,scale);
@@ -86,7 +83,7 @@ public T withThumbnail(double scale) {
8683
/**
8784
* Apply gray-and-white filter to the image.
8885
*
89-
* @return instance of type Screenshot
86+
* @return instance of type Snapshot
9087
*/
9188
public T monochrome() {
9289
this.image = ImageProcessor.convertToGrayAndWhite(this.image);
@@ -134,24 +131,24 @@ public void save(String path) {
134131
*/
135132
public boolean equals(Object o, double deviation) {
136133
if (this == o) return true;
137-
if (!(o instanceof Screenshot)) return false;
134+
if (!(o instanceof Snapshot)) return false;
138135

139-
Screenshot<?> that = (Screenshot<?>) o;
136+
Snapshot that = (Snapshot) o;
140137

141138
return getImage() != null ? ImageProcessor.imagesAreEquals(getImage(), that.getImage(), deviation) : that.getImage() == null;
142139
}
143140

144141
/**
145142
* @param o Object to compare with
146-
* @return true if the the provided object is of type Screenshot
143+
* @return true if the the provided object is of type Snapshot
147144
* and images are strictly equal.
148145
*/
149146
@Override
150147
public boolean equals(Object o) {
151148
if (this == o) return true;
152-
if (!(o instanceof Screenshot)) return false;
149+
if (!(o instanceof Snapshot)) return false;
153150

154-
Screenshot<?> that = (Screenshot<?>) o;
151+
Snapshot that = (Snapshot) o;
155152

156153
return getImage() != null ? ImageProcessor.imagesAreEquals(getImage(), that.getImage(), 0) : that.getImage() == null;
157154
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.assertthat.selenium_screenshotter.utils.file;
1+
package com.assertthat.shutterbug.utils.file;
22

33

4-
import com.assertthat.selenium_screenshotter.utils.web.UnableTakeScreenshotException;
4+
import com.assertthat.shutterbug.utils.web.UnableTakeScreenshotException;
55
import org.apache.commons.io.IOUtils;
66

77
import javax.imageio.ImageIO;

0 commit comments

Comments
 (0)