{"id":636,"date":"2014-06-26T09:56:58","date_gmt":"2014-06-26T13:56:58","guid":{"rendered":"http:\/\/qxf2.com\/blog\/?p=636"},"modified":"2024-10-16T16:28:36","modified_gmt":"2024-10-16T20:28:36","slug":"appium-mobile-automation","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/appium-mobile-automation\/","title":{"rendered":"Get started with mobile automation: Appium &#038; Python"},"content":{"rendered":"<p><span style=\"font-weight: bold; font-style: inherit;\"><strong>Problem:<\/strong><\/span> There is a perception among testers that getting started with mobile automation is hard.<\/p>\n<h2> Why this post? <\/h2>\n<p>I strongly believe that a tester must have a wide range of skills. You do not need to be an expert in all of them, but it is extremely important to have contemplated a spectrum of concepts and explored a variety of tools. The context under which you test will inform you of the specific choice of testing methodology and test tools to choose. The more options you are aware of, the better your context-specific choice is going to be. In this regard, I began noticing that mobile testing has become somewhat of a niche among testers. Testers are reluctant to get started with mobile testing &#8211; probably because they think getting started involves a lot of time and effort. At <a href=\"http:\/\/www.qxf2.com\/?utm_source=appium&#038;utm_medium=click&#038;utm_campaign=From%20blog\">Qxf2 Services<\/a>, we have decided to tackle the problem head-on. This post is the second in a series of quick, easily consumable tutorials geared towards hands-on testers looking to start exploring the mobile testing landscape. <\/p>\n<p><strong>NOTE:<\/strong> In this post we are concentrating only on the &#8220;getting started&#8221; phase. The tools your test team uses to solve the specific and unique problems can greatly vary. There is no one silver bullet.<\/p>\n<hr>\n<h2> A little bit of history <\/h2>\n<p>On the eve of Christmas 2013, Selenium <a href=\"http:\/\/seleniumhq.wordpress.com\/2013\/12\/24\/android-and-ios-support\/\">officially retired<\/a> their own AndroidDriver and iPhoneDriver in favour of <a href=\"http:\/\/selendroid.io\/\">Selendroid<\/a>, <a href=\"http:\/\/ios-driver.github.io\/ios-driver\/\">iosdriver<\/a> and <a href=\"http:\/\/appium.io\/\">Appium<\/a>. In an <a href=\"https:\/\/qxf2.com\/blog\/selendroid-mobile-automation\/\">earlier post<\/a> we explored using Selendroid and Python. In this post, we will help you get started with Appium.<\/p>\n<p><a href=\"http:\/\/appium.io\/\" target=\"_blank\" rel=\"noopener\"> Appium <\/a> is an open-source tool you can use to automate mobile native, mobile web, and mobile hybrid applications on iOS and Android platforms. Appium is &#8220;cross-platform&#8221;: it allows you to write tests on multiple platforms (iOS, Android), using the same API. This enables a large or total amount of code reuse between iOS and Android test suites.<\/p>\n<hr>\n<h2> Appium setup<\/h2>\n<p>Here are the steps to setup Appium on Windows 7 and use it with Android emulator.<br \/>\n1. <strong>Download the latest <a href=\"https:\/\/github.com\/appium\/appium-desktop\/releases\/latest\" target=\"_blank\" rel=\"noopener\">Appium <\/a><\/strong><br \/>\nI have used appium-desktop-Setup-1.5.0-ia32.exe. You can run the exe to install the appium desktop app<br \/>\n2. <strong>Download and Install <a href=\"https:\/\/developer.android.com\/studio\/index.html\" target=\"_blank\" rel=\"noopener\">Android Studio<\/a><\/strong><br \/>\nOnce you install Android Studio make sure the AVD Manager is also installed as we are going to run our tests on an emulator. Set ANDROID_HOME to be your Android SDK path and add the tools and platform-tools folders to your PATH variable. I could find the Android SDK installed on the below-mentioned path<br \/>\n<strong>$\\AppData\\Local\\Android\\Sdk<\/strong><\/p>\n<p>3. <strong>Install the <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html\">Java JDK<\/a><\/strong><br \/>\nSet JAVA_HOME to your JDK folder<br \/>\n4. <strong>Install the Python client library<\/strong><br \/>\nThere are client libraries (in Java, Ruby, Python, PHP, JavaScript, and C#) which support Appium\u2019s extensions to the WebDriver protocol. When using Appium, you want to use these client libraries instead of your regular WebDriver client. I have used the Appium Python client available <a href=\"https:\/\/github.com\/appium\/python-client\" target=\"_blank\" rel=\"noopener\">here<\/a>. Assuming you have pip installed on your machine, you can use the following command to install it<\/p>\n<pre lang=\"html\">pip install Appium-Python-Client <\/pre>\n<p>Woot! You are now set up. Next stop: launch the emulator and start the Appium server.<\/p>\n<p>5. <strong>Start the Android Virtual Device (AVD) Manager<\/strong><br \/>\nStart the Android Studio and launch the Android Virtual Device (AVD) Manager from by clicking on the link as shown in the screenshot below.<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/AVD_Manager.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/AVD_Manager.png\" alt=\"AVD_Manager\" width=\"1261\" height=\"465\" class=\"aligncenter size-full wp-image-9158\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/AVD_Manager.png 1261w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/AVD_Manager-300x111.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/AVD_Manager-768x283.png 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/AVD_Manager-1024x378.png 1024w\" sizes=\"auto, (max-width: 1261px) 100vw, 1261px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/developer.android.com\/tools\/devices\/managing-avds.html\" target=\"_blank\" rel=\"noopener\">Create <\/a>an emulator with the preferences you need and launch it using the start button<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Emulator.png\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Emulator-300x296.png\" alt=\"android_emulator\" width=\"300\" height=\"296\" class=\"aligncenter size-medium wp-image-9159\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Emulator-300x296.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Emulator.png 614w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n6. <strong>Start the Appium server console<\/strong><br \/>\nStart the Appium server console by double clicking on the Appium file. <\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Appium.png\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Appium.png\" alt=\"start_appium\" width=\"802\" height=\"150\" class=\"aligncenter size-full wp-image-9173\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Appium.png 802w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Appium-300x56.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Start_Appium-768x144.png 768w\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" \/><\/a><br \/>\n7. <strong>Launch the Appium node server<\/strong><br \/>\nClick on the &#8216;rocket&#8217; icon to launch the Appium node server<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Launch_Appium.png\" data-rel=\"lightbox-image-3\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Launch_Appium-300x238.png\" alt=\"Launch_Appium\" width=\"300\" height=\"238\" class=\"aligncenter size-medium wp-image-9163\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Launch_Appium-300x238.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Launch_Appium.png 635w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Appium_Console.png\" data-rel=\"lightbox-image-4\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Appium_Console-300x212.png\" alt=\"appium_node_server_console\" width=\"300\" height=\"212\" class=\"aligncenter size-medium wp-image-9164\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Appium_Console-300x212.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Appium_Console.png 634w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<hr>\n<h2> Your first test using Appium<\/h2>\n<p>For this test we will use one of my favorite Android apps &#8211; the highly recommended <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=uk.co.aifactory.chessfree&#038;hl=en\">Chess Free<\/a> application created by the UK based <a href=\"http:\/\/www.aifactory.co.uk\/\">AI Factory<\/a>. For this blog post, we will pretend that our test is to launch the application and click on &#8220;PLAY&#8221; button.<\/p>\n<p>1. <strong>Obtain the .apk for the application under test<\/strong><br \/>\nWe obtained the .apk for Chess Free over <a href=\"http:\/\/www.appsapk.com\/chess-free\/\" target=\"_blank\" rel=\"noopener\">here<\/a>. Copy the chess application to a directory of your choice. I used ($Directory_Of_My_Choice\\apps\\Chess Free.apk )<br \/>\n2. <strong>Peek into the AndroidManifest.xml<\/strong><br \/>\nTo write the test, you need two pieces of information specific to your application:<br \/>\n   a) Java package of the Android app you want to run<br \/>\n   b) Activity name for the Android activity you want to launch your package<\/p>\n<p>You can get this information by running the following command<\/p>\n<pre lang=\"html\">ANDROID_HOME\\sdk\\build-tools\\android-4.4.2>aapt dump badging path_to_apk_file<\/pre>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/chess_pkg_activity.gif\" data-rel=\"lightbox-image-5\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/chess_pkg_activity-300x241.gif\" alt=\"aapt_pkg_activity\" width=\"300\" height=\"241\" class=\"aligncenter size-medium wp-image-660\" \/><\/a><\/p>\n<p>Another approach is using the <a href=\"http:\/\/developer.android.com\/guide\/topics\/manifest\/manifest-intro.html\">AndroidManifest.xml<\/a> which is present in the root directory of all Android applications and has the information we need. You can use Android Studio to view the AndroidManifest.xml file. Go to Build\/Analyze APK and select your apk. Then you can see the content of the AndroidManifset file.<\/p>\n<pre lang=\"html\"> \r\npackage=\"uk.co.aifactory.chessfree\" and \r\nandroid:name=\".ChessFreeActivity\" \r\n<\/pre>\n<p>3. <strong>Write the test<\/strong><br \/>\nCreate a test script (android_chess.py) in $Directory_Of_My_Choice based on the snippet below. Pay particular attention to the setup() method.<\/p>\n<pre lang=\"python\">\r\n\"\"\"\r\nQxf2: Example script to run one test against the Chess Free app using Appium\r\nThe test will:\r\n- launch the app\r\n- click the 'PLAY!' button\r\n\"\"\"\r\n \r\nimport os\r\nimport unittest\r\nfrom appium import webdriver\r\nfrom time import sleep\r\n \r\nclass ChessAndroidTests(unittest.TestCase):\r\n    \"Class to run tests against the Chess Free app\"\r\n    def setUp(self):\r\n        \"Setup for the test\"\r\n        desired_caps = {}\r\n        desired_caps['platformName'] = 'Android'\r\n        desired_caps['platformVersion'] = '8.0'\r\n        desired_caps['deviceName'] = 'Pixel'\r\n        # Returns abs path relative to this file and not cwd\r\n        desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'apps\/Chess Free.apk'))\r\n        desired_caps['appPackage'] = 'uk.co.aifactory.chessfree'\r\n        desired_caps['appActivity'] = '.ChessFreeActivity'\r\n        self.driver = webdriver.Remote('http:\/\/localhost:4723\/wd\/hub', desired_caps)\r\n \r\n    def tearDown(self):\r\n        \"Tear down the test\"\r\n        self.driver.quit()\r\n \r\n    def test_single_player_mode(self):\r\n        \"Test the Chess app launches correctly and click on Play button\"\r\n        element = self.driver.find_element_by_id(\"uk.co.aifactory.chessfree:id\/ButtonPlay\")\r\n        element.click()\r\n        sleep(5)\r\n \r\n#---START OF SCRIPT\r\nif __name__ == '__main__':\r\n    suite = unittest.TestLoader().loadTestsFromTestCase(ChessAndroidTests)\r\n    unittest.TextTestRunner(verbosity=2).run(suite)\r\n<\/pre>\n<p>4. <strong>Run the test <\/strong><br \/>\nRun the script android_chess.py. The chess application is launched in the test emulator<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Chess_App-1.png\" data-rel=\"lightbox-image-6\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Chess_App-1-146x300.png\" alt=\"Run_Chess_App\" width=\"146\" height=\"300\" class=\"aligncenter size-medium wp-image-9194\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Chess_App-1-146x300.png 146w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Chess_App-1.png 280w\" sizes=\"auto, (max-width: 146px) 100vw, 146px\" \/><\/a><br \/>\n5. <strong>Check the result<\/strong><br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Check_Result.png\" data-rel=\"lightbox-image-7\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Check_Result-300x72.png\" alt=\"appium_test_run\" width=\"300\" height=\"72\" class=\"aligncenter size-medium wp-image-9192\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Check_Result-300x72.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Check_Result-768x184.png 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2014\/06\/Check_Result.png 807w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Celebrate a little &#8211; you just upgraded your skills by a little bit in a very short span of time! <\/p>\n<p>There you have it! You have just run your first mobile automated test with Appium and Python. If you are looking for Python based mobile automation framework, check out our open-sourced <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\">GUI and API automation framework based on the page object model<\/a>. Happy exploring from <a href=\"http:\/\/www.qxf2.com\/?utm_source=appium&#038;utm_medium=click&#038;utm_campaign=From%20blog\">Qxf2 Services<\/a>!<\/p>\n<p><strong>P.S.:<\/strong> As a chess fan<del datetime=\"2014-06-25T19:25:14+00:00\">atic<\/del>, I think it is a crime to test chess applications in an automated fashion. I sincerely believe infinite manual testing is the only correct way to test chess applications \ud83d\ude09<\/p>\n<p><strong>P.P.S:<\/strong> We were pleasantly surprised by positive reaction we got to our last tutorial on mobile application testing with Selendroid. Please chime in on the direction you want our future blog posts to go. We will try our best to keep churning out useful posts for testers.<\/p>\n<hr>\n<h2>Hire QA consultants from Qxf2<\/h2>\n<p>This is an extremely old article but as you can see, Qxf2 was an early adopter of Appium. Not only did we work with Appium, we shared our learnings with the QA community as well. This has been our culture and over the years we have improved and stayed in touch with the rapid changes in the software space. In fact, we have innovated in the QA services domain too. Qxf2 offer several <a href=\"https:\/\/qxf2.com\/?utm_source=appium-get-started&#038;utm_medium=click&#038;utm_campaign=From%20blog\">top-notch, unique testing services aimed towards startups<\/a> that most folks are not aware of. So, if you are working at a startup or on an early-stage product, browse our services and get in touch. After all, every team benefits from having one good technical tester!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: There is a perception among testers that getting started with mobile automation is hard. Why this post? I strongly believe that a tester must have a wide range of skills. You do not need to be an expert in all of them, but it is extremely important to have contemplated a spectrum of concepts and explored a variety of [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,50,38,47,71,18],"tags":[],"class_list":["post-636","post","type-post","status-publish","format-standard","hentry","category-android","category-appium","category-automation","category-mobile","category-mobile-automation","category-python"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/636","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=636"}],"version-history":[{"count":38,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/636\/revisions"}],"predecessor-version":[{"id":22915,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/636\/revisions\/22915"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}