|
13 | 13 |
|
14 | 14 | public class SauceLabsCustomScreenshot {
|
15 | 15 |
|
16 |
| - private static final AtomicInteger screenshotId = new AtomicInteger(1); |
| 16 | + private static final AtomicInteger screenshotId = new AtomicInteger(1); |
17 | 17 |
|
18 |
| - public static void capture(String screenshotName) { |
19 |
| - try { |
20 |
| - screenshotName = String.format("%04d-%s", screenshotId.getAndIncrement(), screenshotName); |
| 18 | + public static void capture(String screenshotName) { |
| 19 | + try { |
| 20 | + screenshotName = String.format("%04d-%s", screenshotId.getAndIncrement(), screenshotName); |
21 | 21 |
|
22 |
| - ScreenCapture capture = Screenshot.capture(); |
23 |
| - capture.setFormat(Bitmap.CompressFormat.PNG); |
24 |
| - capture.setName(screenshotName); |
| 22 | + ScreenCapture capture = Screenshot.capture(); |
| 23 | + capture.setFormat(Bitmap.CompressFormat.PNG); |
| 24 | + capture.setName(screenshotName); |
25 | 25 |
|
26 |
| - SauceLabsScreenCaptureProcessor processor = new SauceLabsScreenCaptureProcessor(); |
27 |
| - processor.process(capture); |
| 26 | + SauceLabsScreenCaptureProcessor processor = new SauceLabsScreenCaptureProcessor(); |
| 27 | + processor.process(capture); |
28 | 28 |
|
29 |
| - String savedScreenshotPath = new File(processor.getPathForFile(screenshotName) + ".png").getPath(); |
| 29 | + String savedScreenshotPath = new File(processor.getPathForFile(screenshotName) + ".png").getPath(); |
30 | 30 |
|
31 |
| - Log.i("SauceLabs", String.format("Screenshot saved to %s", savedScreenshotPath)); |
32 |
| - } catch (Exception e) { |
33 |
| - Log.e("SauceLabs", "Failed to capture screenshot", e); |
34 |
| - } |
35 |
| - } |
| 31 | + Log.i("SauceLabs", String.format("Screenshot saved to %s", savedScreenshotPath)); |
| 32 | + } catch (Exception e) { |
| 33 | + Log.e("SauceLabs", "Failed to capture screenshot", e); |
| 34 | + } |
| 35 | + } |
36 | 36 |
|
37 |
| - private static class SauceLabsScreenCaptureProcessor extends BasicScreenCaptureProcessor { |
| 37 | + private static class SauceLabsScreenCaptureProcessor extends BasicScreenCaptureProcessor { |
38 | 38 |
|
39 |
| - private static final String SAUCE_LABS_CUSTOM_SCREENSHOTS = "sauce_labs_custom_screenshots"; |
| 39 | + private static final String SAUCE_LABS_CUSTOM_SCREENSHOTS = "sauce_labs_custom_screenshots"; |
40 | 40 |
|
41 |
| - public SauceLabsScreenCaptureProcessor() { |
42 |
| - super(); |
| 41 | + public SauceLabsScreenCaptureProcessor() { |
| 42 | + super(); |
43 | 43 |
|
44 |
| - File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); |
45 |
| - File screenshotsDir = new File(downloadsDir, SAUCE_LABS_CUSTOM_SCREENSHOTS); |
46 |
| - this.mDefaultScreenshotPath = screenshotsDir; |
47 |
| - } |
| 44 | + File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); |
| 45 | + File screenshotsDir = new File(downloadsDir, SAUCE_LABS_CUSTOM_SCREENSHOTS); |
| 46 | + this.mDefaultScreenshotPath = screenshotsDir; |
| 47 | + } |
48 | 48 |
|
49 |
| - public String getPathForFile(String name) { |
50 |
| - File file = new File(mDefaultScreenshotPath, getFilename(name)); |
51 |
| - return file.getAbsolutePath(); |
52 |
| - } |
53 |
| - } |
| 49 | + public String getPathForFile(String name) { |
| 50 | + File file = new File(mDefaultScreenshotPath, getFilename(name)); |
| 51 | + return file.getAbsolutePath(); |
| 52 | + } |
| 53 | + } |
54 | 54 | }
|
0 commit comments