Overview
The Fastlane is the automated tool for deploying the entire apk and screenshots of the application on the app store.
Fastlane has the following capabilities:
- Make a repeatable custom work process to build, upload and distribute new releases to the play store.
- Upload and deal with the more significant part of your application’s metadata including screen captures.
- Automatically submit new versions of your application for review.
Introduction
Fastlane helps developers by publishing/uploading an app screenshot along with all the necessary details with just a few commands.
In this part of the series, I’ll explain how to grab the screenshot automatically from the functionality of Fastlane. It allows you to:-
- Catch many screenshots in numerous languages on any simulator.
- Arrange it once, and store the setup so anybody on the group can run it.
- Get an outline of how your application looks like over every single supported devices and dialect.
- Accomplish something unique while the computer takes the screen captures for you. (Time-Saving)
We have finished the installation process in our previous Part 2 blog of Fastlane. Fastlane captures the screengrab automatically.
Setup the Espresso(If not found in gradle)
screengrab utilizes the capacities of Android’s worked in Instrumented tests joined with Espresso to drive communications with your application.
Add this dependency in your build.gradle file if it is not located(Generally, it is by default):-
dependencies { androidTestImplementation 'com.android.support.test:rules:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation ('com.android.support.test.espresso:espresso-core:3.0.2') { exclude group:'com.android.support', module:'support-v4' } }
Setup the Android JUnit Test Runner
AndroidJUnitRunner is necessary for Android Test coding so please don’t remove it from build.gradle if you, unfortunately, removed it then please add it again.
android { defaultConfig{ ..... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ..... } } dependencies { testCompile ‘junit:junit:4.12’ }
Setup the Screengrab
Open the terminal and run the following command to install the gem for screengrab.
sudo gem install screengrab
Add the test dependency in the build.gradle file.
dependencies { androidTestCompile 'tools.fastlane:screengrab:1.0.0' }
Permission to be needed for screen grabbing
Add the list of permission in your AndroidManifest.xml file to capture the screenshot and store the screenshot in the phone storage and change the locales for different languages.
<!-- Allows unlocking your device and activating its screen so UI tests can succeed --> <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <!-- Allows for storing and retrieving screenshots --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- Allows changing locales --> <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
Configure the Screengrab test code
- For automatically switching of locales you have to add the following code in your ExampleInstrumentedTest.java code.
@ClassRule public static final LocaleTestRule localeTestRule = new LocaleTestRule();
- For capturing the screenshots add the following line in your test code.
Screengrab.screenshot("Example.png");
Example Code
Here is the ExampleInstrumentedTest.java which will perform the sleeping activity and manage the locales for taking the screenshots. (Locale will help you when we have a single app with the multiple languages)
@RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @ClassRule public static final LocaleTestRule localeTestRule = new LocaleTestRule(); @Rule public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>(MainActivity.class); Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(MainActivity.class.getSimpleName(), null, false); @Test public void testTakeScreenshot() { Activity secondActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 5000); //This line will sleep upto 5 Seconds until my Splash screen is opened. Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); //Work with API level >=18 Screengrab.screenshot("Dashboard.png"); } @Test public void useAppContext() { } }
Edit the fastfile
Create the new lane for capturing the screenshots and upload it to the app store by adding the following lines to your fastfile.
lane :screenshots do screengrab( locales: ['en-US'], #uses when your app will running in multiple languages clear_previous_screenshots: 'true', ) capture_android_screenshots upload_to_play_store end