55
66package com .assertthat .selenium_shutterbug .core ;
77
8+ import com .assertthat .selenium_shutterbug .utils .web .ElementOutsideViewportException ;
89import com .assertthat .selenium_shutterbug .utils .image .ImageProcessor ;
910import com .assertthat .selenium_shutterbug .utils .web .Coordinates ;
1011import org .openqa .selenium .WebDriver ;
1112import org .openqa .selenium .WebElement ;
1213
1314import java .awt .*;
15+ import java .awt .image .RasterFormatException ;
1416
1517/**
1618 * Created by Glib_Briia on 17/06/2016.
@@ -29,7 +31,11 @@ public class PageSnapshot extends Snapshot {
2931 * @return instance of type PageSnapshot
3032 */
3133 public PageSnapshot highlight (WebElement element ) {
32- highlight (element , Color .red , 3 );
34+ try {
35+ highlight (element , Color .red , 3 );
36+ } catch (RasterFormatException rfe ) {
37+ throw new ElementOutsideViewportException ("Try to apply ScrollStrategy" , rfe );
38+ }
3339 return this ;
3440 }
3541
@@ -43,7 +49,11 @@ public PageSnapshot highlight(WebElement element) {
4349 * @return instance of type PageSnapshot
4450 */
4551 public PageSnapshot highlight (WebElement element , Color color , int lineWidth ) {
46- image = ImageProcessor .highlight (image , new Coordinates (element ), color , lineWidth );
52+ try {
53+ image = ImageProcessor .highlight (image , new Coordinates (element ), color , lineWidth );
54+ } catch (RasterFormatException rfe ) {
55+ throw new ElementOutsideViewportException ("Try to apply ScrollStrategy" , rfe );
56+ }
4757 return this ;
4858 }
4959
@@ -58,7 +68,11 @@ public PageSnapshot highlight(WebElement element, Color color, int lineWidth) {
5868 * @return instance of type PageSnapshot
5969 */
6070 public PageSnapshot highlightWithText (WebElement element , String text ) {
61- highlightWithText (element , Color .red , 3 , text , Color .red , new Font ("Serif" , Font .BOLD , 20 ));
71+ try {
72+ highlightWithText (element , Color .red , 3 , text , Color .red , new Font ("Serif" , Font .BOLD , 20 ));
73+ } catch (RasterFormatException rfe ) {
74+ throw new ElementOutsideViewportException ("Try to apply ScrollStrategy" , rfe );
75+ }
6276 return this ;
6377 }
6478
@@ -75,9 +89,13 @@ public PageSnapshot highlightWithText(WebElement element, String text) {
7589 * @return instance of type PageSnapshot
7690 */
7791 public PageSnapshot highlightWithText (WebElement element , Color elementColor , int lineWidth , String text , Color textColor , Font textFont ) {
78- highlight (element , elementColor , 0 );
79- Coordinates coords = new Coordinates (element );
80- image = ImageProcessor .addText (image , coords .getX (), coords .getY () - textFont .getSize () / 2 , text , textColor , textFont );
92+ try {
93+ highlight (element , elementColor , 0 );
94+ Coordinates coords = new Coordinates (element );
95+ image = ImageProcessor .addText (image , coords .getX (), coords .getY () - textFont .getSize () / 2 , text , textColor , textFont );
96+ } catch (RasterFormatException rfe ) {
97+ throw new ElementOutsideViewportException ("Try to apply ScrollStrategy" , rfe );
98+ }
8199 return this ;
82100 }
83101
@@ -98,7 +116,11 @@ public PageSnapshot blur() {
98116 * @return instance of type PageSnapshot
99117 */
100118 public PageSnapshot blur (WebElement element ) {
101- image = ImageProcessor .blurArea (image , new Coordinates (element ));
119+ try {
120+ image = ImageProcessor .blurArea (image , new Coordinates (element ));
121+ }catch (RasterFormatException rfe ) {
122+ throw new ElementOutsideViewportException ("Try to apply ScrollStrategy" , rfe );
123+ }
102124 return this ;
103125 }
104126
@@ -110,7 +132,11 @@ public PageSnapshot blur(WebElement element) {
110132 * @return instance of type PageSnapshot
111133 */
112134 public PageSnapshot monochrome (WebElement element ) {
113- image = ImageProcessor .monochromeArea (image , new Coordinates (element ));
135+ try {
136+ image = ImageProcessor .monochromeArea (image , new Coordinates (element ));
137+ } catch (RasterFormatException rfe ) {
138+ throw new ElementOutsideViewportException ("Try to apply ScrollStrategy" , rfe );
139+ }
114140 return this ;
115141 }
116142
@@ -121,7 +147,11 @@ public PageSnapshot monochrome(WebElement element) {
121147 * @return instance of type PageSnapshot
122148 */
123149 public PageSnapshot blurExcept (WebElement element ) {
124- image = ImageProcessor .blurExceptArea (image , new Coordinates (element ));
150+ try {
151+ image = ImageProcessor .blurExceptArea (image , new Coordinates (element ));
152+ }catch (RasterFormatException rfe ){
153+ throw new ElementOutsideViewportException ("Try to apply ScrollStrategy" ,rfe );
154+ }
125155 return this ;
126156 }
127157
0 commit comments