@@ -27,8 +27,8 @@ public abstract class AbstractAppiumTest {
27
27
public static final int LONG_SLEEP = 10 ;
28
28
29
29
protected static Logger logger = LoggerFactory .getLogger (AbstractAppiumTest .class );
30
- private static long timeDifferenceStartTest ;
31
- private static long startTime ;
30
+
31
+
32
32
33
33
protected static AppiumDriver <MobileElement > driver ;
34
34
protected static int defaultWaitTime = 120 ;
@@ -129,58 +129,54 @@ public static AppiumDriver getAndroidDriver() throws Exception {
129
129
}
130
130
131
131
public static void takeScreenshot (String screenshotName ) throws IOException , InterruptedException {
132
- if (idevicescreenshotExists ) {
133
- // Keep Appium session alive between multiple non-driver screenshots
134
- driver .manage ().window ().getSize ();
135
- }
136
- timeDifferenceStartTest = (int ) ((System .nanoTime () - startTime ) / 1e6 / 1000 );
137
- long start_time = System .nanoTime ();
138
- //
139
- // if (new_step) {
140
- // counter = counter + 1;
141
- // retry_counter = 1;
142
- // } else {
143
- // retry_counter = retry_counter + 1;
144
- // }
145
- //
146
- // searchedImage = screenshotsFolder + getScreenshotsCounter() + "_" + screenshotName + getRetryCounter() + "_" + timeDifferenceStartTest + "sec";
147
- String fullFileName = System .getProperty ("user.dir" ) + "/" + screenshotsFolder + screenshotName + ".png" ;
132
+ if (idevicescreenshotExists ) {
133
+ // Keep Appium session alive between multiple non-driver screenshots
134
+ driver .manage ().window ().getSize ();
135
+ }
136
+
137
+ long start_time = System .nanoTime ();
138
+ String fullFileName = System .getProperty ("user.dir" ) + "/" + screenshotsFolder + screenshotName + ".png" ;
148
139
149
140
if (platformName .equalsIgnoreCase ("iOS" ) && idevicescreenshotExists ) {
150
- String [] cmd = new String []{"idevicescreenshot" , "-u" , udid , fullFileName };
151
- Process p = Runtime .getRuntime ().exec (cmd );
152
- BufferedReader in = new BufferedReader (new InputStreamReader (p .getInputStream ()));
153
- String line ;
154
- while ((line = in .readLine ()) != null )
155
- log (line );
156
-
157
- int exitVal = p .waitFor ();
158
- if (exitVal != 0 ) {
159
- log ("idevicescreenshot process exited with value: " + exitVal );
160
- }
161
- cmd = new String []{"sips" , "-s" , "format" , "png" , fullFileName , "--out" , fullFileName };
162
- p = Runtime .getRuntime ().exec (cmd );
163
- exitVal = p .waitFor ();
164
- if (exitVal != 0 ) {
165
- log ("sips process exited with value: " + exitVal );
166
- }
141
+ takeIDeviceScreenshot (fullFileName );
167
142
} else {
168
- // idevicescreenshot not available, using driver.getScreenshotAs()
169
- File scrFile = driver .getScreenshotAs (OutputType .FILE );
170
- try {
171
- File testScreenshot = new File (fullFileName );
172
- FileUtils .copyFile (scrFile , testScreenshot );
173
- logger .info ("Screenshot stored to {}" , testScreenshot .getAbsolutePath ());
174
- return ;
175
- } catch (IOException e ) {
176
- e .printStackTrace ();
177
- }
143
+ takeAppiumScreenshot (fullFileName );
178
144
}
179
-
180
- long end_time = System .nanoTime ();
181
- int difference = (int ) ((end_time - start_time ) / 1e6 / 1000 );
182
- logger .info ("==> Taking a screenshot took " + difference + " secs." );
183
- }
145
+ long end_time = System .nanoTime ();
146
+ int difference = (int ) ((end_time - start_time ) / 1e6 / 1000 );
147
+ logger .info ("==> Taking a screenshot took " + difference + " secs." );
148
+ }
149
+
150
+ private static void takeAppiumScreenshot (String fullFileName ) {
151
+ File scrFile = driver .getScreenshotAs (OutputType .FILE );
152
+ try {
153
+ File testScreenshot = new File (fullFileName );
154
+ FileUtils .copyFile (scrFile , testScreenshot );
155
+ logger .info ("Screenshot stored to {}" , testScreenshot .getAbsolutePath ());
156
+ } catch (IOException e ) {
157
+ e .printStackTrace ();
158
+ }
159
+ }
160
+
161
+ private static void takeIDeviceScreenshot (String fullFileName ) throws IOException , InterruptedException {
162
+ String [] cmd = new String []{"idevicescreenshot" , "-u" , udid , fullFileName };
163
+ Process p = Runtime .getRuntime ().exec (cmd );
164
+ BufferedReader in = new BufferedReader (new InputStreamReader (p .getInputStream ()));
165
+ String line ;
166
+ while ((line = in .readLine ()) != null )
167
+ log (line );
168
+
169
+ int exitVal = p .waitFor ();
170
+ if (exitVal != 0 ) {
171
+ log ("idevicescreenshot process exited with value: " + exitVal );
172
+ }
173
+ cmd = new String []{"sips" , "-s" , "format" , "png" , fullFileName , "--out" , fullFileName };
174
+ p = Runtime .getRuntime ().exec (cmd );
175
+ exitVal = p .waitFor ();
176
+ if (exitVal != 0 ) {
177
+ log ("sips process exited with value: " + exitVal );
178
+ }
179
+ }
184
180
185
181
//On a test run on the local machine this method will save the Reports folder in different folders on every test run.
186
182
public static void savePreviousRunReports () {
0 commit comments