Skip to content

Instantly share code, notes, and snippets.

@up1
Last active February 12, 2016 12:26
Show Gist options
  • Select an option

  • Save up1/e4de0191fa4de153a511 to your computer and use it in GitHub Desktop.

Select an option

Save up1/e4de0191fa4de153a511 to your computer and use it in GitHub Desktop.
Fastlane with android app
<?xml version="1.0" encoding="utf-8"?>
<manifest package="up1.hello"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
</manifest>
...
androidTestCompile 'tools.fastlane:screengrab:0.2.0'
...
@RunWith(AndroidJUnit4.class)
public class E2EMessageTest {
@ClassRule
public static final LocaleTestRule localeTestRule = new LocaleTestRule();
@Rule
public ActivityTestRule<MainActivity> mMainActivityTestRule
= new ActivityTestRule<>(MainActivity.class);
@Test
public void show_message() {
//Arrange
Screengrab.screenshot("show_message_01");
onView(withId(R.id.firstOperand)).perform(typeText("5"));
onView(withId(R.id.secondOperand)).perform(typeText("5"));
Screengrab.screenshot("show_message_02");
onView(withId(R.id.calculate)).perform(click());
Screengrab.screenshot("show_message_03");
onView(withId(R.id.message)).perform(typeText("Hello world"), closeSoftKeyboard());
Screengrab.screenshot("show_message_04");
//Act
onView(withId(R.id.back)).perform(click());
Screengrab.screenshot("show_message_05");
//Assert
onView(withId(R.id.message)).check(matches(withText("Hello world")));
Screengrab.screenshot("show_message_06");
}
}
+-----------------------------+-----------------------------------------------------------+
| Summary for screengrab 0.2.0 |
+-----------------------------+-----------------------------------------------------------+
| android_home | /Users/somkiat/Library/Android/sdk |
| locales | ["en-US"] |
| clear_previous_screenshots | false |
| output_directory | fastlane/metadata/android |
| skip_open_summary | false |
| app_package_name | up1.hello |
| tests_package_name | up1.hello.test |
| test_instrumentation_runner | android.support.test.runner.AndroidJUnitRunner |
| ending_locale | en-US |
| app_apk_path | app/build/outputs/apk/app-debug.apk |
| tests_apk_path | app/build/outputs/apk/app-debug-androidTest-unaligned.apk |
| device_type | phone |
+-----------------------------+-----------------------------------------------------------+
[19:24:07]: Limiting the test classes run by `screengrab` to just those that generate screenshots can make runs faster.
[19:24:07]: Consider using the :use_tests_in_classes or :use_tests_in_packages option, and organize your tests accordingly.
[19:24:07]: $ adb devices -l
[19:24:07]: ▸ List of devices attached
[19:24:07]: ▸ 4d003e36f2a62200 device usb:337641472X product:core33gdc model:SM_G360HU device:core33g
[19:24:07]: $ adb -s 4d003e36f2a62200 shell echo \$EXTERNAL_STORAGE
[19:24:07]: ▸ /storage/emulated/legacy
[19:24:07]: Cleaning screenshots on device
[19:24:07]: $ adb -s 4d003e36f2a62200 shell rm -rf /data/data/up1.hello/app_screengrab
[19:24:07]: ▸ rm failed for /data/data/up1.hello/app_screengrab, Permission denied
[19:24:07]: Validating app APK
[19:24:07]: $ /Users/somkiat/Library/Android/sdk/build-tools/23.0.2/aapt dump permissions app/build/outputs/apk/app-debug.apk
[19:24:07]: ▸ package: up1.hello
[19:24:07]: ▸ uses-permission: name='android.permission.DISABLE_KEYGUARD'
[19:24:07]: ▸ uses-permission: name='android.permission.WAKE_LOCK'
[19:24:07]: ▸ uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
[19:24:07]: ▸ uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
[19:24:07]: ▸ uses-permission: name='android.permission.CHANGE_CONFIGURATION'
[19:24:07]: Installing app APK
[19:24:07]: $ adb -s 4d003e36f2a62200 install -r app/build/outputs/apk/app-debug.apk
[19:24:07]: ▸ 6167 KB/s (1188760 bytes in 0.188s)
[19:24:08]: ▸ pkg: /data/local/tmp/app-debug.apk
[19:24:15]: ▸ Success
[19:24:15]: Installing tests APK
[19:24:15]: $ adb -s 4d003e36f2a62200 install -r app/build/outputs/apk/app-debug-androidTest-unaligned.apk
[19:24:16]: ▸ 7398 KB/s (1196991 bytes in 0.157s)
[19:24:16]: ▸ pkg: /data/local/tmp/app-debug-androidTest-unaligned.apk
[19:24:31]: ▸ Success
[19:24:31]: Granting the permission necessary to change locales on the device
[19:24:31]: $ adb -s 4d003e36f2a62200 shell pm grant up1.hello android.permission.CHANGE_CONFIGURATION
[19:24:32]: $ adb -s 4d003e36f2a62200 shell getprop ro.build.version.sdk
[19:24:32]: ▸ 19
[19:24:32]: Running tests for locale: en-US
[19:24:32]: $ adb -s 4d003e36f2a62200 shell am instrument --no-window-animation -w \
-e testLocale en_US \
-e endingLocale en_US \
up1.hello.test/android.support.test.runner.AndroidJUnitRunner
[19:24:43]: ▸ up1.hello.CalculationWithDivideOperatorTest:....
[19:24:50]: ▸ up1.hello.CalculationWithMinusOperatorTest:...
[19:24:56]: ▸ up1.hello.CalculationWithMultiplyOperatorTest:...
[19:25:01]: ▸ up1.hello.CalculationWithPlusOperatorTest:...
[19:25:07]: ▸ up1.hello.E2EMessageTest:.
[19:25:17]: ▸ up1.hello.MainActivityTest:.....
[19:25:22]: ▸ up1.hello.MainActivityWithParameterTest:...
[19:25:22]: ▸ up1.hello.ResultActivityTest:.
[19:25:22]: ▸ Time: 48.518
[19:25:22]: ▸ OK (23 tests)
[19:25:22]: Pulling captured screenshots from the device
[19:25:23]: $ adb -s 4d003e36f2a62200 pull /data/data/up1.hello/app_screengrab fastlane/metadata/android
[19:25:23]: Screenshots copied to ./fastlane/metadata/android/en-US/images/phoneScreenshots
[19:25:23]: Opening screenshots summary
[19:25:23]: $ open fastlane/metadata/android/*/images/phoneScreenshots/*.png
[19:25:23]: Captured 6 screenshots! 📷✨
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment