9
9
import com .assertthat .selenium_shutterbug .utils .web .ScrollStrategy ;
10
10
import org .openqa .selenium .WebDriver ;
11
11
import org .openqa .selenium .WebElement ;
12
+ import org .openqa .selenium .support .ui .ExpectedCondition ;
13
+
14
+ import java .util .function .Function ;
12
15
13
16
/**
14
17
* Created by Glib_Briia on 26/06/2016.
15
18
*/
16
19
public class Shutterbug {
17
20
18
21
private static final int DEFAULT_SCROLL_TIMEOUT = 100 ;
22
+ private static Function <WebDriver ,?> beforeShootCondition ;
23
+ private static int beforeShootTimeout ;
24
+
25
+ private Shutterbug (){
26
+
27
+ }
19
28
20
29
/**
21
30
* Make screen shot of the viewport only.
@@ -73,34 +82,30 @@ public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll, in
73
82
}
74
83
75
84
/**
76
- * To be used when screen shooting the page
77
- * and need to scroll while making screen shots, either vertically or
78
- * horizontally or both directions (Chrome).
85
+ * Wait for condition to be true before taking screenshot
79
86
*
80
- * @param driver WebDriver instance
81
- * @param scroll ScrollStrategy How you need to scroll
82
- * @param betweenScrollTimeout Timeout to wait after scrolling and before taking screenshot
83
- * @param afterScrollTimeout Timeout to wait after scrolling and before taking screenshot
84
- * @return PageSnapshot instance
87
+ * @param cond condition
88
+ * @param timeout timeout wait for condition
89
+ * @return Shutterbug
85
90
*/
86
- public static PageSnapshot shootPage (WebDriver driver , ScrollStrategy scroll , int betweenScrollTimeout , int afterScrollTimeout ) {
87
- return shootPage (driver , scroll , betweenScrollTimeout , true , afterScrollTimeout );
91
+ public static Shutterbug wait (ExpectedCondition <?> cond , int timeout ) {
92
+ beforeShootCondition = cond ;
93
+ beforeShootTimeout = timeout ;
94
+ return null ;
88
95
}
89
96
90
97
/**
91
- * To be used when screen shooting the page
92
- * and need to scroll while making screen shots, either vertically or
93
- * horizontally or both directions (Chrome).
98
+ * Wait for before taking screenshot
94
99
*
95
- * @param driver WebDriver instance
96
- * @param scroll ScrollStrategy How you need to scroll
97
- * @param useDevicePixelRatio whether or not take into account device pixel ratio
98
- * @return PageSnapshot instance
100
+ * @param timeout timeout wait for condition
101
+ * @return Shutterbug
99
102
*/
100
- public static PageSnapshot shootPage (WebDriver driver , ScrollStrategy scroll , boolean useDevicePixelRatio ) {
101
- return shootPage (driver , scroll , 0 , useDevicePixelRatio );
103
+ public static Shutterbug wait (int timeout ) {
104
+ beforeShootTimeout = timeout ;
105
+ return null ;
102
106
}
103
107
108
+
104
109
/**
105
110
* To be used when screen shooting the page
106
111
* and need to scroll while making screen shots, either vertically or
@@ -109,11 +114,10 @@ public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll, bo
109
114
* @param driver WebDriver instance
110
115
* @param scroll ScrollStrategy How you need to scroll
111
116
* @param useDevicePixelRatio whether or not take into account device pixel ratio
112
- * @param afterScrollTimeout Timeout to wait after scrolling and before taking screenshot
113
117
* @return PageSnapshot instance
114
118
*/
115
- public static PageSnapshot shootPage (WebDriver driver , ScrollStrategy scroll , boolean useDevicePixelRatio , int afterScrollTimeout ) {
116
- return shootPage (driver , scroll , 0 , useDevicePixelRatio , afterScrollTimeout );
119
+ public static PageSnapshot shootPage (WebDriver driver , ScrollStrategy scroll , boolean useDevicePixelRatio ) {
120
+ return shootPage (driver , scroll , 0 , useDevicePixelRatio );
117
121
}
118
122
119
123
/**
@@ -128,25 +132,14 @@ public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll, bo
128
132
* @return PageSnapshot instance
129
133
*/
130
134
public static PageSnapshot shootPage (WebDriver driver , ScrollStrategy scroll , int betweenScrollTimeout , boolean useDevicePixelRatio ) {
131
- return shootPage (driver , scroll , betweenScrollTimeout , useDevicePixelRatio , 0 );
132
- }
133
-
134
- /**
135
- * To be used when screen shooting the page
136
- * and need to scroll while making screen shots, either vertically or
137
- * horizontally or both directions (Chrome).
138
- *
139
- * @param driver WebDriver instance
140
- * @param scroll ScrollStrategy How you need to scroll
141
- * @param betweenScrollTimeout Timeout to wait between each scrolling operation
142
- * @param afterScrollTimeout Timeout to wait after scrolling and before taking screenshot
143
- * @param useDevicePixelRatio whether or not take into account device pixel ratio
144
- * @return PageSnapshot instance
145
- */
146
- public static PageSnapshot shootPage (WebDriver driver , ScrollStrategy scroll , int betweenScrollTimeout , boolean useDevicePixelRatio , int afterScrollTimeout ) {
147
135
Browser browser = new Browser (driver , useDevicePixelRatio );
148
136
browser .setBetweenScrollTimeout (betweenScrollTimeout );
149
- browser .setAfterScrollTimeout (afterScrollTimeout );
137
+ if (beforeShootCondition != null ) {
138
+ browser .setBeforeShootTimeout (beforeShootTimeout );
139
+ browser .setBeforeShootCondition (beforeShootCondition );
140
+ }else if (beforeShootTimeout !=0 ){
141
+ browser .setBeforeShootTimeout (beforeShootTimeout );
142
+ }
150
143
151
144
PageSnapshot pageScreenshot = new PageSnapshot (driver , browser .getDevicePixelRatio ());
152
145
switch (scroll ) {
0 commit comments