{"id":35292,"date":"2024-08-21T12:51:00","date_gmt":"2024-08-21T16:51:00","guid":{"rendered":"https:\/\/app14743.cloudwayssites.com\/?p=35292"},"modified":"2025-01-24T14:49:35","modified_gmt":"2025-01-24T19:49:35","slug":"how-to-write-android-test-appium","status":"publish","type":"post","link":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/","title":{"rendered":"Writing Your First Appium Test For Android Mobile Devices"},"content":{"rendered":"\n<p><em>This is the second post in our Hello World introduction series to Appium, and we&#8217;ll discuss how to create your first Appium test for Android. You can read the first post where we discussed <a href=\"https:\/\/app14743.cloudwayssites.com\/blog\/what-is-appium-introduction-to-appium\/\" target=\"_blank\" rel=\"noreferrer noopener\">what Appium is<\/a>, including its core concepts and how to set up the Appium server.<\/em> <em>You can also read the next post on <a href=\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-appium-ios-test\/\" target=\"_blank\" rel=\"noreferrer noopener\">setting up your first Appium iOS test<\/a>.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-key-takeaways\">Key Takeaways<\/h2>\n\n\n\n<p>In this post, we\u2019ll build on top of earlier basics and focus on the following areas:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Setup Android SDK<\/li>\n\n\n\n<li>Setup Android emulator\/real devices<\/li>\n\n\n\n<li>Setup Appium Inspector<\/li>\n\n\n\n<li>Setup our first Android project with framework components<\/li>\n<\/ul>\n\n\n\n<p>We have lots to cover but don\u2019t worry, by the end of this post, you will have run your first Appium-based Android test. Excited? \u270a? Let&#8217;s go.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-setup-android-sdk\">Setup Android SDK<\/h2>\n\n\n\n<p>To run Android tests, we need to set up an <strong>Android SDK, ADB (Android debug bridge),<\/strong> and some other utilities.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Android SDK will set up Android on your machine and provide you with all the tools required to do the development or in this case automation.<\/li>\n\n\n\n<li><a href=\"https:\/\/developer.android.com\/studio\/command-line\/adb\" target=\"_blank\" rel=\"noreferrer noopener\">Android Debug Bridge (ADB)<\/a> is a CMD line tool that lets you communicate with the Android device (either emulator or physical device).<\/li>\n<\/ul>\n\n\n\n<p>The easiest way to set these up is to go to the <a href=\"https:\/\/developer.android.com\/studio\" target=\"_blank\" rel=\"noreferrer noopener\">Android site<\/a> and download <strong>Android Studio <\/strong>(An IDE to develop Android apps), which will install all the desired libraries and also give us everything we need to run our first Android test.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-setup-sdk-platforms-and-tools\">Setup SDK Platforms and Tools<\/h3>\n\n\n\n<p>Once downloaded and installed, open Android Studio, click on <strong>Configure,<\/strong> and then <strong>SDK Manager. <\/strong>Using this you can download any Android API version from <strong>SDK Platforms<\/strong>.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/sdk-manager.jpg\" alt=\"Shows Android studio home page and how someone can open SDK Manager by tapping on Configure button\"><\/p>\n\n\n\n<p>Also, you can install any desired SDK Tools from here.&nbsp;<\/p>\n\n\n\n<p>We\u2019ll go with the defaults for now. This tool can also install any required updates for these tools which is quite a convenient way of upgrading.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/sdk-tools.jpg\" alt=\"Shows SDK Tools in android studio\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-add-android-home-to-environment-variables\">Add Android Home to Environment Variables<\/h3>\n\n\n\n<p>The Appium server needs to know where the Android SDK and other tools like Emulator, Platform Tools are present to help us run the tests.&nbsp;<\/p>\n\n\n\n<p>We can do so by adding the variables below in the system environment.<\/p>\n\n\n\n<p>On Mac\/Linux:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add the below environment variables in the shell of your choice (.bash_profile for bash or .zshrc for zsh). These are usually the paths where Android Studio installs these.<\/li>\n\n\n\n<li>Run <code>source &lt;shell_profile_file_name&gt;<\/code> for e.g. <code>source.zshrc<\/code><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code lang-bash\"><code class=\"\">export ANDROID_HOME=$HOME\/Library\/Android\/sdk\nexport PATH=$ANDROID_HOME\/emulator:$PATH\nexport PATH=$ANDROID_HOME\/tools:$PATH\nexport PATH=$ANDROID_HOME\/tools\/bin:$PATH\nexport PATH=$ANDROID_HOME\/platform-tools:$PATH<\/code><\/pre>\n\n\n\n<p>If you are on Windows, you\u2019ll need to add the path to Android SDK in the <strong>ANDROID_HOME<\/strong> variable under System environment variables.<\/p>\n\n\n\n<p>Once done, run the adb command on the terminal to verify ADB is set up:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\u279c  appium-fast-boilerplate git:(main) adb\nAndroid Debug Bridge version 1.0.41\nVersion 30.0.5-6877874\nInstalled as \/Users\/gauravsingh\/Library\/Android\/sdk\/platform-tools\/adb<\/code><\/pre>\n\n\n\n<p>These are a lot of tedious steps and in case you want to set these up quickly, you can execute <a href=\"https:\/\/github.com\/anandbagmar\/AppiumJavaSample\/blob\/master\/setup_mac.sh\">this<\/a> excellent script written by <a href=\"https:\/\/twitter.com\/bagmaranand\" target=\"_blank\" rel=\"noreferrer noopener\">Anand Bagmar<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-set-up-an-android-emulator-or-real-device\">Set up an Android Emulator or Real Device<\/h2>\n\n\n\n<p>Our Android tests will run either on an emulator or a real Android device plugged in. Let\u2019s see how to create an Android emulator image.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open Android Studio<\/li>\n\n\n\n<li>Click Configure<\/li>\n\n\n\n<li>Click on AVD Manager<\/li>\n<\/ul>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/1-avd-manager.jpg\" alt=\"Shows Android studio home page and how someone can open AVD Manager by tapping on Configure button\"><\/p>\n\n\n\n<p>You\u2019ll be greeted with a blank screen with no virtual devices listed. Tap on Create a virtual device to launch the <strong>Virtual device Configuration<\/strong> flow:<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/2-create-virtual-device.jpg\" alt=\"Shows blank virtual devices screen with create virtual device button\"><\/p>\n\n\n\n<p>Next, select an Android device like TV, Phone, Tablet, etc., and the desired size and resolution combination.&nbsp;<\/p>\n\n\n\n<p>It\u2019s usually a good idea to set up an emulator with <strong>Play Store services<\/strong> available (see the Play Store icon under the column) as certain apps might need the latest play services to be installed.<\/p>\n\n\n\n<p>We\u2019ll go with Pixel 3a with Play Store available.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/3-select-device-image.jpg\" alt=\"Shows device definition screen to select a device model\"><\/p>\n\n\n\n<p>Next, we\u2019ll need to select which Android version this emulator should have. You can choose any of the desired versions and download the image. We\u2019ll choose Android Q (10.0 version).<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/4-select-android-image.jpg\" alt=\"Shows Android OS system image with option to Download and select one\"><\/p>\n\n\n\n<p>You need to give this image a name. We\u2019ll need to use this later in Appium capabilities so you can give any meaningful name or go with the default. We\u2019ll name it <strong>Automation<\/strong>.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/5-enter-name.jpg\" alt=\"Shows Android emulator configuration with AVD Name\"><\/p>\n\n\n\n<p>Nice, \u270b?We have created our emulator. You can fire it up by tapping the Play icon under the Actions section.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/6-start-emulator.jpg\" alt=\"Android Virtual Device Manager screen with and emulator named Automation \"><\/p>\n\n\n\n<p>You should see an emulator boot up on your device similar to a real phone.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-setting-up-a-real-device\">Setting up a Real Device<\/h2>\n\n\n\n<p>While the emulator is an in-memory image of the Android OS that you can quickly spin up and destroy, it does take physical resources like Memory, RAM, and CPU. It&#8217;s always a good idea to verify your app on a real device.<\/p>\n\n\n\n<p>We\u2019ll see how to set up a real device so that we can run automation on it.<\/p>\n\n\n\n<p>You need to connect your device to your machine via USB. Once done:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to About Phone.<\/li>\n\n\n\n<li>Tap on the Android build number multiple times until developer mode is enabled, you\u2019ll see a Toast message show up as you get closer to enabling this mode.<\/li>\n\n\n\n<li>Go to Developer Options and Enable USB Debugging.<\/li>\n<\/ul>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/7-android-developer-options-usb-debugging.jpg\" alt=\"USB Debugging under Developer Options\"><\/p>\n\n\n\n<p>And thats all you need to potentially run our automation on a connected real device.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-setting-up-appium-inspector\">Setting up Appium Inspector<\/h2>\n\n\n\n<p>Appium comes with a nifty inspector desktop app that can inspect your Application under test and help you identify element locators (i.e. ways to identify elements on the screen) and even play around with the app.&nbsp;<\/p>\n\n\n\n<p>It can easily run on any running Appium server and is really a cool utility to help you identify element locators and develop Appium scripts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-download-and-install-appium-inspector\">Download and Install Appium Inspector<\/h3>\n\n\n\n<p>You can download it by just going to the Appium Github repo, and <a href=\"https:\/\/github.com\/appium\/appium-inspector\" target=\"_blank\" rel=\"noreferrer noopener\">searching for appium-inspector<\/a>.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/appium-inspector-github-repo.jpg\" alt=\"Appium Inspector Github page with releases option highlighted\"><\/p>\n\n\n\n<p>Go to release and find the latest .dmg (on Mac) or .exe (on Windows) to download and install.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/appium-inspector-releases-page.jpg\" alt=\"Appium Inspector Github releases page with mac .dmg file highlighted\"><\/p>\n\n\n\n<p>On Mac, you may get a warning stating: <strong>\u201cAppium Inspector\u201d<\/strong> can\u2019t be opened because Apple cannot check it for malicious software.&nbsp;<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/apple-malicious-software-warning.jpg\" alt=\" Apple warning for malicious software\"><\/p>\n\n\n\n<p>To mitigate this, just go to System preferences &gt; Security &amp; Privacy &gt; General and say Open Anyway for Appium Inspector. For more details see <a href=\"https:\/\/github.com\/appium\/appium-desktop\/issues\/1217\">Issue 1217<\/a>.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/open-appium-inspector-in-security-and-privacy.jpg\" alt=\"Give open anyway permission to Appium in System preferences\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-setting-up-desired-capabilities\">Setting up Desired Capabilities<\/h3>\n\n\n\n<p>Once you launch Appium inspector, you\u2019ll be greeted with the below home screen. If you see there is a <strong>JSON representation<\/strong> sector under <strong>Desired Capabilities <\/strong>section.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/inspector-1-adding-caps.jpg\" alt=\" Steps highlighting how we can add our desired caps and save this config\"><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-what-are-the-desired-capabilities\">What are the Desired Capabilities?<\/h4>\n\n\n\n<p>Think of them as properties that you want your driver&#8217;s session to have. For example, you may want to reset your app after your test or launch the app in a particular orientation. These are all achievable by specifying a Key-Value pair in a JSON that we provide to the Appium server session.&nbsp;<\/p>\n\n\n\n<p>Please see <a href=\"https:\/\/appium.io\/docs\/en\/latest\/guides\/caps\/\" target=\"_blank\" rel=\"noreferrer noopener\">Appium docs<\/a> for more ideas on these capabilities.<\/p>\n\n\n\n<p>Below are some sample capabilities we can give for Android:<\/p>\n\n\n\n<pre class=\"wp-block-code lang-json\"><code class=\"\">{\n    \"platformName\": \"android\",\n    \"automationName\": \"uiautomator2\",\n    \"platformVersion\": \"10\",\n    \"deviceName\": \"Automation\",\n    \"app\": \"\/&lt;absolute_path_to_app&gt;\/ApiDemos-debug.apk\",\n    \"appPackage\": \"io.appium.android.apis\",\n    \"appActivity\": \"io.appium.android.apis.ApiDemos\"\n}<\/code><\/pre>\n\n\n\n<p>For this post, we\u2019ll use the sample apps provided by Appium. You can see them <a href=\"https:\/\/github.com\/appium\/appium\/tree\/master\/sample-code\/apps\">here<\/a>, once you\u2019ve downloaded them. Keep track of its absolute path and update it in-app<strong> key<\/strong> in the JSON.<\/p>\n\n\n\n<p>We\u2019ll add this JSON under JSON representation and then tap on the Save button.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/inspector-2-saved-caps.jpg\" alt=\"Saved caps in grid\"><\/p>\n\n\n\n<p>It would be a good idea to save this config for the future. You can tap on &#8216;Save as&#8217; and give it a meaningful name.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/inspector-3-saving-caps.jpg\" alt=\" Saving and giving caps a name\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-starting-the-inspector-session\">Starting the Inspector Session<\/h3>\n\n\n\n<p>To start the inspection session, You need to have an Appium server run locally, run it via typing <code>appium<\/code> on the command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\u279c  appium-fast-boilerplate git:(main) appium\n[Appium] Welcome to Appium v2.0.0-beta.25\n[Appium] Attempting to load driver uiautomator2...\n[Appium] Appium REST http interface listener started on 0.0.0.0:4723\n[Appium] Available drivers:\n[Appium]   - uiautomator2@2.0.1 (automationName 'UiAutomator2')\n[Appium] No plugins have been installed. Use the \"appium plugin\" command to install the one(s) you want to use.<\/code><\/pre>\n\n\n\n<p>Let\u2019s make sure our emulator is also up and running. We can start the emulator via AVD Manager in Android studio, or in case you are more command-line savvy, I have written <a href=\"https:\/\/automationhacks.io\/2020\/06\/11\/using-adb-and-cmdline-to-ease-android-app-testing\/\">an earlier post<\/a> on how to do this via CMDline as well.<\/p>\n\n\n\n<p>Once done, tap on the <strong>Start Session <\/strong>button, this should launch the API Demos app and show the inspector home screen.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/inspector-4-launched-inspector.jpg\" alt=\"Appium inspector home screen with controls highlighted\"><\/p>\n\n\n\n<p>Using this you can tap on any element in the app and see its Element hierarchy and elements properties. This is very useful to author Appium scripts and I\u2019ll encourage you to explore each section of this tool and get familiar since you\u2019ll be using this a lot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-writing-our-first-android-test-using-appium\">Writing Our First Android Test Using Appium<\/h2>\n\n\n\n<p>Phew, that seemed like a lot of setup steps but don\u2019t worry, you only have to do this once, and now we can get down to the real business of writing our first Automated test on Android.<\/p>\n\n\n\n<p>You can download the project using Github from <a href=\"https:\/\/github.com\/automationhacks\/appium-fast-boilerplate\" target=\"_blank\" rel=\"noreferrer noopener\">appium-fast-boilerplate<\/a>.<\/p>\n\n\n\n<p>We\u2019ll also understand what the fundamental concepts of writing page objects and tests are based on these. Let\u2019s take a look at the high-level architecture.<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/appium-test-flow.png\" alt=\"High-level architecture of an Android test written using Appium\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-what-would-this-test-do\">What Would This Test Do?<\/h3>\n\n\n\n<p>Before automating any test, we need to be clear on what is the purpose of that test. I\u2019ve found the <strong>Arrange Act Assert <\/strong>pattern quite useful to reason about it. <a href=\"https:\/\/automationpanda.com\/2020\/07\/07\/arrange-act-assert-a-pattern-for-writing-good-tests\/\" target=\"_blank\" rel=\"noreferrer noopener\">Read this post<\/a> by Andrew Knight in case you are interested to know more about it.<\/p>\n\n\n\n<p>Our test would perform the below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Opens API Demos app<\/li>\n\n\n\n<li>Taps around and navigates to <strong>Log Text box<\/strong> and taps on Add once<\/li>\n\n\n\n<li>Verify the log text is displayed<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-our-test-class\">Our Test Class<\/h3>\n\n\n\n<p>Let\u2019s start by seeing our test.<\/p>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">import constants.TestGroups;\nimport org.testng.Assert;\nimport org.testng.annotations.Test;\nimport pages.apidemos.home.APIDemosHomePage;\n\npublic class AndroidTest extends BaseTest {\n\n    @Test(groups = {TestGroups.ANDROID})\n    public void testLogText() {\n        String logText = new APIDemosHomePage(this.driver)\n                .openText()\n                .tapOnLogTextBox()\n                .tapOnAddButton()\n                .getLogText();\n\n        Assert.assertEquals(logText, \"This is a test\");\n    }\n}<\/code><\/pre>\n\n\n\n<p>There are a few things to notice above:<\/p>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">public class AndroidTest extends BaseTest<\/code><\/pre>\n\n\n\n<p>Our class extends a <strong>BaseTest<\/strong>, this is useful since we can perform common setup and tear-down functions, including setting up driver sessions and closing them once our script is done.&nbsp;<\/p>\n\n\n\n<p>This ensures that the tests are as simple as possible and does not overload the reader with any more details than they need to see.<\/p>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">String logText = new APIDemosHomePage(this.driver)\n                .openText()\n                .tapOnLogTextBox()\n                .tapOnAddButton()\n                .getLogText();<\/code><\/pre>\n\n\n\n<p>We see our tests read like plain English with a series of actions following each other. This is called a <a href=\"https:\/\/martinfowler.com\/bliki\/FluentInterface.html\" target=\"_blank\" rel=\"noreferrer noopener\">Fluent pattern<\/a> and we\u2019ll see how this is set up in just a moment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-base-test-and-driver-setup\">Base Test and Driver Setup<\/h3>\n\n\n\n<p>Let\u2019s see our <strong>BaseTest <\/strong>class:<\/p>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">import constants.Target;\nimport core.driver.DriverManager;\nimport core.utils.PropertiesReader;\nimport exceptions.PlatformNotSupportException;\nimport io.appium.java_client.AppiumDriver;\nimport org.testng.ITestContext;\nimport org.testng.annotations.AfterMethod;\nimport org.testng.annotations.BeforeMethod;\n\nimport java.io.IOException;\n\npublic class BaseTest {\n    protected AppiumDriver driver;\n    protected PropertiesReader reader = new PropertiesReader();\n\n    @BeforeMethod(alwaysRun = true)\n    public void setup(ITestContext context) {\n        context.setAttribute(\"target\", reader.getTarget());\n\n        try {\n            Target target = (Target) context.getAttribute(\"target\");\n            this.driver = new DriverManager().getInstance(target);\n        } catch (IOException | PlatformNotSupportException e) {\n            e.printStackTrace();\n        }\n    }\n\n    @AfterMethod(alwaysRun = true)\n    public void teardown() {\n        driver.quit();\n    }\n}<\/code><\/pre>\n\n\n\n<p>Let\u2019s unpack this class.<\/p>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">protected AppiumDriver driver;<\/code><\/pre>\n\n\n\n<p>We set our driver instance as <strong>protected <\/strong>so that all test classes will have access to it.<\/p>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">protected PropertiesReader reader = new PropertiesReader();<\/code><\/pre>\n\n\n\n<p>We create an instance of <strong>PropertiesReader <\/strong>class to read relevant properties. This is useful since we want to be able to switch our driver instances based on different test environments and conditions. If curious, please <a href=\"https:\/\/github.com\/automationhacks\/appium-fast-boilerplate\/blob\/main\/src\/main\/java\/core\/utils\/PropertiesReader.java\" target=\"_blank\" rel=\"noreferrer noopener\">see its implementation here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">Target target = (Target) context.getAttribute(\"target\");\nthis.driver = new DriverManager().getInstance(target);<\/code><\/pre>\n\n\n\n<p>We get the relevant <code>Target<\/code> and then using that gets an instance of <strong>AppiumDriver<\/strong> from a class called <strong>DriverManager<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-driver-manager-to-setup-appium-driver\">Driver Manager to Setup Appium Driver<\/h3>\n\n\n\n<p>We\u2019ll use this reusable class to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Read capabilities JSON file based on platform (Android\/iOS)<\/li>\n\n\n\n<li>Setup a local driver instance with these capabilities<\/li>\n\n\n\n<li>This class could independently evolve to setup desired driver instances, either local, the house or remote cloud lab<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">package core.driver;\n\nimport constants.Target;\nimport exceptions.PlatformNotSupportException;\nimport io.appium.java_client.AppiumDriver;\nimport org.openqa.selenium.remote.DesiredCapabilities;\n\nimport java.io.IOException;\nimport java.net.MalformedURLException;\nimport java.net.URL;\nimport java.util.HashMap;\n\nimport static core.utils.CapabilitiesHelper.readAndMakeCapabilities;\n\npublic class DriverManager {\n    private static AppiumDriver driver;\n    \/\/ For Appium &lt; 2.0, append \/wd\/hub to the APPIUM_SERVER_URL\n    String APPIUM_SERVER_URL = \"http:\/\/127.0.0.1:4723\";\n\n    public AppiumDriver getInstance(Target target) throws IOException, PlatformNotSupportException {\n        System.out.println(\"Getting instance of: \" + target.name());\n        switch (target) {\n            case ANDROID:\n                return getAndroidDriver();\n            case IOS:\n                return getIOSDriver();\n            default:\n                throw new PlatformNotSupportException(\"Please provide supported target\");\n        }\n    }\n\n    private AppiumDriver getAndroidDriver() throws IOException {\n        HashMap map = readAndMakeCapabilities(\"android-caps.json\");\n        return getDriver(map);\n    }\n\n    private AppiumDriver getIOSDriver() throws IOException {\n        HashMap map = readAndMakeCapabilities(\"ios-caps.json\");\n        return getDriver(map);\n    }\n\n    private AppiumDriver getDriver(HashMap map) {\n        DesiredCapabilities desiredCapabilities = new DesiredCapabilities(map);\n\n        try {\n            driver = new AppiumDriver(\n                    new URL(APPIUM_SERVER_URL), desiredCapabilities);\n        } catch (MalformedURLException e) {\n            e.printStackTrace();\n        }\n\n        return driver;\n    }\n}<\/code><\/pre>\n\n\n\n<p>You can observe:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>getInstance <\/strong>method takes a target and based on that tries to get either an Android or an IOS Driver. In the future, if we want to run our tests against a cloud provider like Headspin, SauceLabs, BrowserStack, Applitools, then this class could handle creating the relevant session.<\/li>\n\n\n\n<li>Both <strong>getAndroidDriver <\/strong>and <strong>getIOSDriver <\/strong>read a JSON file with similar capabilities as we saw in the Inspector section and then convert it into a Java Hashmap which could be passed into <strong>getDriver <\/strong>method that returns an Appium Instance. With this, we could later pass say an environmental context and based on that choose a different capabilities file.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-a-simple-page-object-with-the-fluent-pattern\">A Simple Page Object with the Fluent Pattern<\/h3>\n\n\n\n<p>Let\u2019s take a look at the example of a page object that enables a Fluent pattern.<\/p>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">package pages.apidemos.home;\n\nimport core.page.BasePage;\nimport io.appium.java_client.AppiumDriver;\nimport org.openqa.selenium.By;\nimport org.openqa.selenium.WebElement;\nimport pages.apidemos.logtextbox.LogTextBoxPage;\n\npublic class APIDemosHomePage extends BasePage {\n    private final By textButton = By.xpath(\"\/\/android.widget.TextView[@content-desc=\\\"Text\\\"]\");\n    private final By logTextBoxButton = By.xpath(\"\/\/android.widget.TextView[@content-desc=\\\"LogTextBox\\\"]\");\n\n    public APIDemosHomePage(AppiumDriver driver) {\n        super(driver);\n    }\n\n    public APIDemosHomePage openText() {\n        WebElement text = getElement(textButton);\n        click(text);\n\n        return this;\n    }\n\n    public LogTextBoxPage tapOnLogTextBox() {\n        WebElement logTextBoxButtonElement = getElement(logTextBoxButton);\n        waitForElementToBeVisible(logTextBoxButtonElement);\n\n        click(logTextBoxButtonElement);\n\n        return new LogTextBoxPage(driver);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Notice the following:<\/p>\n\n\n\n<p>Above is an example page object class:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>With 2 XPath locators defined with By clause<\/li>\n\n\n\n<li>We init the driver in <strong>BasePage<\/strong> class<\/li>\n\n\n\n<li>The test actions return either <strong>this (i.e. current page)<\/strong> or <strong>next page object<\/strong> to enable a Fluent pattern. Following this, we can create a sort of action graph where any action that a test takes connects to the next set of actions this page can take and makes writing test scripts a breeze.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-base-page-class\">Base Page Class<\/h3>\n\n\n\n<pre class=\"wp-block-code lang-java\"><code class=\"\">package core.page;\n\nimport io.appium.java_client.AppiumDriver;\nimport org.openqa.selenium.By;\nimport org.openqa.selenium.WebElement;\nimport org.openqa.selenium.support.ui.ExpectedConditions;\nimport org.openqa.selenium.support.ui.WebDriverWait;\n\nimport java.util.List;\n\npublic class BasePage {\n    protected AppiumDriver driver;\n\n    public BasePage(AppiumDriver driver) {\n        this.driver = driver;\n    }\n\n    public void click(WebElement elem) {\n        elem.click();\n    }\n\n    public WebElement getElement(By by) {\n        return driver.findElement(by);\n    }\n\n    public List&lt;WebElement&gt; getElements(By by) {\n        return driver.findElements(by);\n    }\n\n    public String getText(WebElement elem) {\n        return elem.getText();\n    }\n\n    public void waitForElementToBeVisible(WebElement elem) {\n        WebDriverWait wait = new WebDriverWait(driver, 10);\n        wait.until(ExpectedConditions.visibilityOf(elem));\n    }\n\n    public void waitForElementToBePresent(By by) {\n        WebDriverWait wait = new WebDriverWait(driver, 10);\n        wait.until(ExpectedConditions.presenceOfElementLocated(by));\n    }\n\n    public void type(WebElement elem, String text) {\n        elem.sendKeys(text);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Every page object inherits from a BasePage that wraps Appium methods.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This provides us with an abstraction and allows us to create our own project-specific reusable actions and methods. This is a very good pattern to follow for a few reasons\n<ul class=\"wp-block-list\">\n<li>Say we want to provide some custom functionality like adding a logger line in our own logging infrastructure whenever an Appium action is performed, we can wrap those methods and perform this.<\/li>\n\n\n\n<li>Also if in the future Appium breaks an API, this change is not cascaded to all our page objects, but rather only to this class where we can handle it in an appropriate manner to provide backward compatibility.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>A word of caution<\/strong> \u26a0\ufe0f: Do not dump every method in this class, try to compose only relevant actions.<\/li>\n<\/ul>\n\n\n\n<p>Congratulations, you\u2019ve written your first Appium Android test. You can run this either via the IDE or via a Gradle command<\/p>\n\n\n\n<pre class=\"wp-block-code lang-bash\"><code class=\"\">.\/gradlew clean build runTests -Dtag=\"ANDROID\" -Ddevice=\"ANDROID\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>You can see the entire project on the Github <a href=\"https:\/\/github.com\/automationhacks\/appium-fast-boilerplate\" target=\"_blank\" rel=\"noreferrer noopener\">appium-fast-boilerplate<\/a>, clone it, and play around with it. Hopefully, this post helps you a little bit in starting on Android automation using Appium.&nbsp;<\/p>\n\n\n\n<p>In the next post, we\u2019ll dive into the world of iOS Automation with Appium and write our first Hello World test.<\/p>\n\n\n\n<p>You could also check out <a href=\"https:\/\/automationhacks.io\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/automationhacks.io<\/a> for other posts that I\u2019ve written about software engineering and testing.&nbsp;<\/p>\n\n\n\n<p>As always, do share this with your friends or colleagues and if you have thoughts or feedback, I\u2019d be more than happy to chat over at Twitter or elsewhere. Until next time. Happy testing and coding.<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1730829134937\"><strong class=\"schema-faq-question\"><strong>What is Appium, and why is it popular for Android testing?<\/strong><\/strong> <p class=\"schema-faq-answer\">Appium is an open-source tool for automating mobile apps on Android and iOS, known for its flexibility and support across different platforms. It enables testers to write tests in multiple programming languages, making it ideal for cross-platform testing.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1730829091958\"><strong class=\"schema-faq-question\"><strong>How does Appium help automate Android app testing?<\/strong><\/strong> <p class=\"schema-faq-answer\">Appium allows testers to interact with Android apps just as users would, automating various actions and verifying that the app works correctly. This streamlines testing, improves efficiency, and ensures consistent functionality across devices.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1730829097562\"><strong class=\"schema-faq-question\"><strong>What are the prerequisites for using Appium to test Android apps?<\/strong><\/strong> <p class=\"schema-faq-answer\">To use Appium for Android testing, you\u2019ll need Java (or another language compatible with Appium), an IDE like IntelliJ, the Appium server, and Android Studio or SDK. Setting up these tools enables you to automate and execute tests on Android applications.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1730829110325\"><strong class=\"schema-faq-question\"><strong>What types of tests can be run on Android apps using Appium?<\/strong><\/strong> <p class=\"schema-faq-answer\">Appium supports various types of tests, including functional, UI, and end-to-end tests, to validate the app&#8217;s performance and user experience. This comprehensive testing helps ensure the app works smoothly for end users.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1730829122503\"><strong class=\"schema-faq-question\"><strong>What are the benefits of using Appium Inspector in Android testing?<\/strong><\/strong> <p class=\"schema-faq-answer\">Appium Inspector allows testers to view the app&#8217;s element hierarchy, identify UI elements, and generate code for locating elements, simplifying test creation. This tool enhances test accuracy and speeds up test development.<\/p> <\/div> <\/div>\n\n\n\n<div class=\"wp-block-group pb-none pt-none\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<style>\n.schema-faq-section { \n  background: white;\n  margin: 1rem 0;\n  border: 2px solid rgba(0, 0, 0, 0.13);\n  border-radius: 10px;\n  box-shadow: 2px 2px 6px 2px rgba(0, 0, 0, 0.03);\n}\n.schema-faq-question{\n  cursor: pointer;\n  display: flex;\n  align-items: center;\n  transition: opacity ease 0.25s;\n  padding: 1rem;\n  color: var(--wp--preset--color--primary);\n  font-size: var(--wp--preset--font-size-large);\n}\n.schema-faq-question:hover {\n  color: var(--wp--preset--color--secondary);\n}\n.schema-faq-question:after{\n  width: 16px;\n  height: 20px;\n  display: inline-block;\n  margin-left: auto;\n  margin-right: 5px;\n  vertical-align: top;\n  color: inherit;\n  content: \"+\";\n}\n.schema-faq-question.expanded:after{\n  content: \"-\";\n}\n.schema-faq-question:hover{\n  opacity: 0.75;\n}\n.schema-faq-answer{\n  padding: 0 1rem 1rem 1rem;\n  display: none;\n}\n.schema-faq-answer.default{\n  display: block;\n}\n.editor-styles-wrapper .schema-faq-question {\n  cursor: text;\n}\n.editor-styles-wrapper .schema-faq-answer {\n  display: block; \n}\n<\/style>\n\n\n\n<script>\njQuery(function($){var yoast={accordion:function(){var isAnimating=!1;$(\".schema-faq-section\").find(\".schema-faq-question\").click(function(event){event.stopPropagation();if(isAnimating)return;isAnimating=!0;var answer=$(this).nextAll(\".schema-faq-answer\").eq(0);answer.slideToggle(250,function(){$(this).toggleClass(\"expanded\");$(this).prev(\".schema-faq-question\").toggleClass(\"expanded\");isAnimating=!1});$(\".schema-faq-answer\").not(answer).slideUp(\"fast\",function(){$(this).removeClass(\"expanded\");$(this).prev(\".schema-faq-question\").removeClass(\"expanded\")})})}};yoast.accordion()});\n<\/script>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to create your first Appium test for Android in this comprehensive, step-by-step walkthrough.<\/p>\n","protected":false},"author":87,"featured_media":35372,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[12271],"tags":[10015,10021,12783,10103,10152,12690],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v24.5 (Yoast SEO v24.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Guide to Writing Your First Android Test with Appium<\/title>\n<meta name=\"description\" content=\"Learn how to write Android tests with Appium in this detailed guide. Explore step-by-step instructions for setting up and automating Android app testing.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Writing Your First Appium Test For Android Mobile Devices\" \/>\n<meta property=\"og:description\" content=\"Learn how to create your first Appium test for Android in this comprehensive, step-by-step walkthrough.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/\" \/>\n<meta property=\"og:site_name\" content=\"AI-Powered End-to-End Testing | Applitools\" \/>\n<meta property=\"article:published_time\" content=\"2024-08-21T16:51:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-24T19:49:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"831\" \/>\n\t<meta property=\"og:image:height\" content=\"542\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Gaurav Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@automationhacks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gaurav Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"29 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/\"},\"author\":{\"name\":\"Gaurav Singh\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#\/schema\/person\/38e1665a1de2aa02deb7cba27db62868\"},\"headline\":\"Writing Your First Appium Test For Android Mobile Devices\",\"datePublished\":\"2024-08-21T16:51:00+00:00\",\"dateModified\":\"2025-01-24T19:49:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/\"},\"wordCount\":2445,\"publisher\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg\",\"keywords\":[\"Android\",\"Appium\",\"Mobile\",\"Mobile App Testing\",\"Test Automation\",\"Test Engineers\"],\"articleSection\":[\"Getting Started\"],\"inLanguage\":\"en-US\"},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/\",\"url\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/\",\"name\":\"Guide to Writing Your First Android Test with Appium\",\"isPartOf\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg\",\"datePublished\":\"2024-08-21T16:51:00+00:00\",\"dateModified\":\"2025-01-24T19:49:35+00:00\",\"description\":\"Learn how to write Android tests with Appium in this detailed guide. Explore step-by-step instructions for setting up and automating Android app testing.\",\"breadcrumb\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829134937\"},{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829091958\"},{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829097562\"},{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829110325\"},{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829122503\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#primaryimage\",\"url\":\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg\",\"contentUrl\":\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg\",\"width\":831,\"height\":542},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/app14743.cloudwayssites.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting Started\",\"item\":\"https:\/\/app14743.cloudwayssites.com\/blog\/category\/getting-started\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Writing Your First Appium Test For Android Mobile Devices\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#website\",\"url\":\"https:\/\/app14743.cloudwayssites.com\/\",\"name\":\"Applitools Visual AI\",\"description\":\"Applitools delivers full end-to-end test automation with AI infused at every step.\",\"publisher\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/app14743.cloudwayssites.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#organization\",\"name\":\"Applitools\",\"url\":\"https:\/\/app14743.cloudwayssites.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2020\/03\/applitools.png\",\"contentUrl\":\"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2020\/03\/applitools.png\",\"width\":156,\"height\":28,\"caption\":\"Applitools\"},\"image\":{\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#\/schema\/person\/38e1665a1de2aa02deb7cba27db62868\",\"name\":\"Gaurav Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5d3da0654d3e285896edad526418842c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5d3da0654d3e285896edad526418842c?s=96&d=mm&r=g\",\"caption\":\"Gaurav Singh\"},\"description\":\"Gaurav Singh is an experienced Software engineer in Test who loves to code in Kotlin, Python, Java, and JavaScript and builds and scales Test automation frameworks and teams. He believes in understanding and testing at all the layers of the stack and has worked with Web, Mobile, and Backend systems throughout his career in different domains. He blogs at automationhacks.io and posts about his journey and adventures in Software Engineering and Testing. Gaurav is an International conference speaker and has spoken previously at conferences like Appium Conf, Selenium Conf, and Automation Guild and shares his knowledge and learns from others. He has also built a few open-source courses for Test Automation University.\",\"sameAs\":[\"https:\/\/automationhacks.io\/\",\"https:\/\/www.linkedin.com\/in\/automationhacks\/\",\"https:\/\/x.com\/automationhacks\"],\"url\":\"https:\/\/app14743.cloudwayssites.com\/blog\/author\/gauravsingh\/\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829134937\",\"position\":1,\"url\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829134937\",\"name\":\"What is Appium, and why is it popular for Android testing?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Appium is an open-source tool for automating mobile apps on Android and iOS, known for its flexibility and support across different platforms. It enables testers to write tests in multiple programming languages, making it ideal for cross-platform testing.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829091958\",\"position\":2,\"url\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829091958\",\"name\":\"How does Appium help automate Android app testing?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Appium allows testers to interact with Android apps just as users would, automating various actions and verifying that the app works correctly. This streamlines testing, improves efficiency, and ensures consistent functionality across devices.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829097562\",\"position\":3,\"url\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829097562\",\"name\":\"What are the prerequisites for using Appium to test Android apps?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"To use Appium for Android testing, you\u2019ll need Java (or another language compatible with Appium), an IDE like IntelliJ, the Appium server, and Android Studio or SDK. Setting up these tools enables you to automate and execute tests on Android applications.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829110325\",\"position\":4,\"url\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829110325\",\"name\":\"What types of tests can be run on Android apps using Appium?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Appium supports various types of tests, including functional, UI, and end-to-end tests, to validate the app's performance and user experience. This comprehensive testing helps ensure the app works smoothly for end users.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829122503\",\"position\":5,\"url\":\"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829122503\",\"name\":\"What are the benefits of using Appium Inspector in Android testing?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Appium Inspector allows testers to view the app's element hierarchy, identify UI elements, and generate code for locating elements, simplifying test creation. This tool enhances test accuracy and speeds up test development.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Guide to Writing Your First Android Test with Appium","description":"Learn how to write Android tests with Appium in this detailed guide. Explore step-by-step instructions for setting up and automating Android app testing.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/","og_locale":"en_US","og_type":"article","og_title":"Writing Your First Appium Test For Android Mobile Devices","og_description":"Learn how to create your first Appium test for Android in this comprehensive, step-by-step walkthrough.","og_url":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/","og_site_name":"AI-Powered End-to-End Testing | Applitools","article_published_time":"2024-08-21T16:51:00+00:00","article_modified_time":"2025-01-24T19:49:35+00:00","og_image":[{"width":831,"height":542,"url":"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg","type":"image\/jpeg"}],"author":"Gaurav Singh","twitter_card":"summary_large_image","twitter_creator":"@automationhacks","twitter_misc":{"Written by":"Gaurav Singh","Est. reading time":"29 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#article","isPartOf":{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/"},"author":{"name":"Gaurav Singh","@id":"https:\/\/app14743.cloudwayssites.com\/#\/schema\/person\/38e1665a1de2aa02deb7cba27db62868"},"headline":"Writing Your First Appium Test For Android Mobile Devices","datePublished":"2024-08-21T16:51:00+00:00","dateModified":"2025-01-24T19:49:35+00:00","mainEntityOfPage":{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/"},"wordCount":2445,"publisher":{"@id":"https:\/\/app14743.cloudwayssites.com\/#organization"},"image":{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#primaryimage"},"thumbnailUrl":"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg","keywords":["Android","Appium","Mobile","Mobile App Testing","Test Automation","Test Engineers"],"articleSection":["Getting Started"],"inLanguage":"en-US"},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/","url":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/","name":"Guide to Writing Your First Android Test with Appium","isPartOf":{"@id":"https:\/\/app14743.cloudwayssites.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#primaryimage"},"image":{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#primaryimage"},"thumbnailUrl":"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg","datePublished":"2024-08-21T16:51:00+00:00","dateModified":"2025-01-24T19:49:35+00:00","description":"Learn how to write Android tests with Appium in this detailed guide. Explore step-by-step instructions for setting up and automating Android app testing.","breadcrumb":{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829134937"},{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829091958"},{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829097562"},{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829110325"},{"@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829122503"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#primaryimage","url":"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg","contentUrl":"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2022\/03\/hello-appium-writing-first-android-test-1_831x542.jpg","width":831,"height":542},{"@type":"BreadcrumbList","@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/app14743.cloudwayssites.com\/"},{"@type":"ListItem","position":2,"name":"Getting Started","item":"https:\/\/app14743.cloudwayssites.com\/blog\/category\/getting-started\/"},{"@type":"ListItem","position":3,"name":"Writing Your First Appium Test For Android Mobile Devices"}]},{"@type":"WebSite","@id":"https:\/\/app14743.cloudwayssites.com\/#website","url":"https:\/\/app14743.cloudwayssites.com\/","name":"Applitools Visual AI","description":"Applitools delivers full end-to-end test automation with AI infused at every step.","publisher":{"@id":"https:\/\/app14743.cloudwayssites.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/app14743.cloudwayssites.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/app14743.cloudwayssites.com\/#organization","name":"Applitools","url":"https:\/\/app14743.cloudwayssites.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/app14743.cloudwayssites.com\/#\/schema\/logo\/image\/","url":"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2020\/03\/applitools.png","contentUrl":"https:\/\/app14743.cloudwayssites.com\/wp-content\/uploads\/2020\/03\/applitools.png","width":156,"height":28,"caption":"Applitools"},"image":{"@id":"https:\/\/app14743.cloudwayssites.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/app14743.cloudwayssites.com\/#\/schema\/person\/38e1665a1de2aa02deb7cba27db62868","name":"Gaurav Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/app14743.cloudwayssites.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5d3da0654d3e285896edad526418842c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5d3da0654d3e285896edad526418842c?s=96&d=mm&r=g","caption":"Gaurav Singh"},"description":"Gaurav Singh is an experienced Software engineer in Test who loves to code in Kotlin, Python, Java, and JavaScript and builds and scales Test automation frameworks and teams. He believes in understanding and testing at all the layers of the stack and has worked with Web, Mobile, and Backend systems throughout his career in different domains. He blogs at automationhacks.io and posts about his journey and adventures in Software Engineering and Testing. Gaurav is an International conference speaker and has spoken previously at conferences like Appium Conf, Selenium Conf, and Automation Guild and shares his knowledge and learns from others. He has also built a few open-source courses for Test Automation University.","sameAs":["https:\/\/automationhacks.io\/","https:\/\/www.linkedin.com\/in\/automationhacks\/","https:\/\/x.com\/automationhacks"],"url":"https:\/\/app14743.cloudwayssites.com\/blog\/author\/gauravsingh\/"},{"@type":"Question","@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829134937","position":1,"url":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829134937","name":"What is Appium, and why is it popular for Android testing?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Appium is an open-source tool for automating mobile apps on Android and iOS, known for its flexibility and support across different platforms. It enables testers to write tests in multiple programming languages, making it ideal for cross-platform testing.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829091958","position":2,"url":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829091958","name":"How does Appium help automate Android app testing?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Appium allows testers to interact with Android apps just as users would, automating various actions and verifying that the app works correctly. This streamlines testing, improves efficiency, and ensures consistent functionality across devices.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829097562","position":3,"url":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829097562","name":"What are the prerequisites for using Appium to test Android apps?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"To use Appium for Android testing, you\u2019ll need Java (or another language compatible with Appium), an IDE like IntelliJ, the Appium server, and Android Studio or SDK. Setting up these tools enables you to automate and execute tests on Android applications.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829110325","position":4,"url":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829110325","name":"What types of tests can be run on Android apps using Appium?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Appium supports various types of tests, including functional, UI, and end-to-end tests, to validate the app's performance and user experience. This comprehensive testing helps ensure the app works smoothly for end users.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829122503","position":5,"url":"https:\/\/app14743.cloudwayssites.com\/blog\/how-to-write-android-test-appium\/#faq-question-1730829122503","name":"What are the benefits of using Appium Inspector in Android testing?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Appium Inspector allows testers to view the app's element hierarchy, identify UI elements, and generate code for locating elements, simplifying test creation. This tool enhances test accuracy and speeds up test development.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/posts\/35292"}],"collection":[{"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/comments?post=35292"}],"version-history":[{"count":0,"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/posts\/35292\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/media\/35372"}],"wp:attachment":[{"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/media?parent=35292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/categories?post=35292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app14743.cloudwayssites.com\/wp-json\/wp\/v2\/tags?post=35292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}