99import com .assertthat .selenium_shutterbug .utils .web .ScrollStrategy ;
1010import org .openqa .selenium .WebDriver ;
1111import org .openqa .selenium .WebElement ;
12+ import org .openqa .selenium .support .ui .ExpectedCondition ;
13+
14+ import java .util .function .Function ;
1215
1316/**
1417 * Created by Glib_Briia on 26/06/2016.
1518 */
1619public class Shutterbug {
1720
1821 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+ }
1928
2029 /**
2130 * Make screen shot of the viewport only.
@@ -73,34 +82,30 @@ public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll, in
7382 }
7483
7584 /**
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
7986 *
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
8590 */
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 ;
8895 }
8996
9097 /**
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
9499 *
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
99102 */
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 ;
102106 }
103107
108+
104109 /**
105110 * To be used when screen shooting the page
106111 * and need to scroll while making screen shots, either vertically or
@@ -109,11 +114,10 @@ public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll, bo
109114 * @param driver WebDriver instance
110115 * @param scroll ScrollStrategy How you need to scroll
111116 * @param useDevicePixelRatio whether or not take into account device pixel ratio
112- * @param afterScrollTimeout Timeout to wait after scrolling and before taking screenshot
113117 * @return PageSnapshot instance
114118 */
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 );
117121 }
118122
119123 /**
@@ -128,25 +132,14 @@ public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll, bo
128132 * @return PageSnapshot instance
129133 */
130134 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 ) {
147135 Browser browser = new Browser (driver , useDevicePixelRatio );
148136 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+ }
150143
151144 PageSnapshot pageScreenshot = new PageSnapshot (driver , browser .getDevicePixelRatio ());
152145 switch (scroll ) {
0 commit comments