5
5
6
6
package com .assertthat .selenium_shutterbug .core ;
7
7
8
+ import com .assertthat .selenium_shutterbug .utils .web .ElementOutsideViewportException ;
8
9
import com .assertthat .selenium_shutterbug .utils .image .ImageProcessor ;
9
10
import com .assertthat .selenium_shutterbug .utils .web .Coordinates ;
10
11
import org .openqa .selenium .WebDriver ;
11
12
import org .openqa .selenium .WebElement ;
12
13
13
14
import java .awt .*;
15
+ import java .awt .image .RasterFormatException ;
14
16
15
17
/**
16
18
* Created by Glib_Briia on 17/06/2016.
@@ -29,7 +31,11 @@ public class PageSnapshot extends Snapshot {
29
31
* @return instance of type PageSnapshot
30
32
*/
31
33
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
+ }
33
39
return this ;
34
40
}
35
41
@@ -43,7 +49,11 @@ public PageSnapshot highlight(WebElement element) {
43
49
* @return instance of type PageSnapshot
44
50
*/
45
51
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
+ }
47
57
return this ;
48
58
}
49
59
@@ -58,7 +68,11 @@ public PageSnapshot highlight(WebElement element, Color color, int lineWidth) {
58
68
* @return instance of type PageSnapshot
59
69
*/
60
70
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
+ }
62
76
return this ;
63
77
}
64
78
@@ -75,9 +89,13 @@ public PageSnapshot highlightWithText(WebElement element, String text) {
75
89
* @return instance of type PageSnapshot
76
90
*/
77
91
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
+ }
81
99
return this ;
82
100
}
83
101
@@ -98,7 +116,11 @@ public PageSnapshot blur() {
98
116
* @return instance of type PageSnapshot
99
117
*/
100
118
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
+ }
102
124
return this ;
103
125
}
104
126
@@ -110,7 +132,11 @@ public PageSnapshot blur(WebElement element) {
110
132
* @return instance of type PageSnapshot
111
133
*/
112
134
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
+ }
114
140
return this ;
115
141
}
116
142
@@ -121,7 +147,11 @@ public PageSnapshot monochrome(WebElement element) {
121
147
* @return instance of type PageSnapshot
122
148
*/
123
149
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
+ }
125
155
return this ;
126
156
}
127
157
0 commit comments