Browse Source

captureScreenshot

Daniel Zlotin 7 years ago
parent
commit
6cea5e1088

+ 12
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/BaseTest.java View File

1
 package com.reactnativenavigation.e2e.androide2e;
1
 package com.reactnativenavigation.e2e.androide2e;
2
 
2
 
3
+import android.graphics.Bitmap;
4
+import android.graphics.BitmapFactory;
3
 import android.support.test.runner.AndroidJUnit4;
5
 import android.support.test.runner.AndroidJUnit4;
4
 import android.support.test.uiautomator.By;
6
 import android.support.test.uiautomator.By;
5
 import android.support.test.uiautomator.BySelector;
7
 import android.support.test.uiautomator.BySelector;
13
 import org.junit.Before;
15
 import org.junit.Before;
14
 import org.junit.runner.RunWith;
16
 import org.junit.runner.RunWith;
15
 
17
 
18
+import java.io.File;
19
+
16
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
20
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
17
 import static org.assertj.core.api.Java6Assertions.assertThat;
21
 import static org.assertj.core.api.Java6Assertions.assertThat;
18
 
22
 
81
 		assertThat(device().findObject(selector).getVisibleCenter().y).isPositive().isLessThan(device().getDisplayHeight());
85
 		assertThat(device().findObject(selector).getVisibleCenter().y).isPositive().isLessThan(device().getDisplayHeight());
82
 	}
86
 	}
83
 
87
 
88
+	public Bitmap captureScreenshot() throws Exception {
89
+		File file = File.createTempFile("tmpE2E", "png");
90
+		device().takeScreenshot(file);
91
+		Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
92
+		file.delete();
93
+		return bitmap;
94
+	}
95
+
84
 	public void swipeOpenLeftSideMenu() {
96
 	public void swipeOpenLeftSideMenu() {
85
 		device().swipe(5, 152, 500, 152, 15);
97
 		device().swipe(5, 152, 500, 152, 15);
86
 	}
98
 	}