{"id":110,"date":"2016-10-25T13:14:59","date_gmt":"2016-10-25T13:14:59","guid":{"rendered":"http:\/\/loadfocus.com\/blog\/tech\/?p=110"},"modified":"2019-08-11T18:35:56","modified_gmt":"2019-08-11T18:35:56","slug":"how-to-use-the-overview-home-and-back-buttons-in-appium-for-android","status":"publish","type":"post","link":"https:\/\/loadfocus.com\/blog\/tech\/2016\/10\/how-to-use-the-overview-home-and-back-buttons-in-appium-for-android","title":{"rendered":"How to use the Overview, Home and Back buttons in Appium for Android"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> &lt; 1<\/span> <span class=\"rt-label rt-postfix\">minute read<\/span><\/span><p class=\"lead\"><!-- pn-tldr --><\/p>\n<h2>Key takeaways<\/h2>\n<ul>\n<li>Appium reaches the Android system buttons through key events rather than element clicks.<\/li>\n<li>Back and Home behave differently: one navigates, the other backgrounds the app.<\/li>\n<li>Test the resume path after Home, since that is where state bugs appear.<\/li>\n<\/ul>\n<p><!-- \/pn-tldr -->Using the Overview, Home and Back native buttons is pretty straight forward using WebDriver and Appium. Below there are the code examples for all the 3 buttons:<\/p>\n<p>&nbsp;<\/p>\n<h3>How to click the Back Button on Android with Selenium WebDriver and Appium<\/h3>\n<pre class=\"lang-java\"><code class=\"lang-java\">\npublic void clickBackButton(){\n((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.BACK);\n}\n<\/code><\/pre>\n<h3>How to click the Overview Button on Android with Selenium WebDriver and Appium<\/h3>\n<h3>See more details<\/h3>\n<p><script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- Square --><br \/>\n<ins class=\"adsbygoogle\" style=\"display:block\" data-ad-client=\"ca-pub-8151016364557535\" data-ad-slot=\"3756710829\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script><br \/>\n     (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n<\/script><br \/>\n[emaillocker]<\/p>\n<pre class=\"lang-java\"><code class=\"lang-java\">\npublic void clickOverviewButton(){\n((AndroidDriver&lt;WebElement&gt;)driver).pressKeyCode(AndroidKeyCode.KEYCODE_APP_SWITCH);\n}\n<\/code><\/pre>\n<h3>How to click the Home Button on Android with Selenium WebDriver and Appium<\/h3>\n<pre class=\"lang-java\"><code class=\"lang-java\">\npublic void clickHomeButton(){\n((AndroidDriver&lt;WebElement&gt;)driver).pressKeyCode(AndroidKeyCode.HOME);\n}\n<\/code><\/pre>\n<p>&nbsp;<br \/>\n[\/emaillocker]<br \/>\n<a href=\"https:\/\/loadfocus.com\">LoadFocus.com<\/a> is a cloud testing platform:<\/p>\n<ul>\n<li><a href=\"https:\/\/loadfocus.com\/load-testing\">Cloud Load Testing Service<\/a><\/li>\n<li><a href=\"https:\/\/loadfocus.com\/website-speed-testing\">Website Speed Testing Service<\/a><\/li>\n<li><a href=\"https:\/\/loadfocus.com\/automated-website-testing\">Automated Website Testing Service<\/a><\/li>\n<li><a href=\"https:\/\/loadfocus.com\/mobile-emulation\">Mobile Emulation Service<\/a><\/li>\n<\/ul>\n<p><!-- pn-faq --><\/p>\n<h2>Frequently Asked Questions<\/h2>\n<h3>How do I press Android system buttons in Appium?<\/h3>\n<p>Through key events rather than element clicks, by calling pressKeyCode on the AndroidDriver with the relevant code: BACK, HOME, or KEYCODE_APP_SWITCH for the Overview button.<\/p>\n<h3>What is the difference between Back and Home?<\/h3>\n<p>Back navigates within the app and eventually leaves it, Home sends the app to the background without closing it. They exercise different lifecycle paths, so they are not interchangeable in a test.<\/p>\n<h3>What should I check after pressing Home?<\/h3>\n<p>The resume path. Bringing the app back from the background is where state bugs surface: lost form input, stale sessions, a timer that kept running or a screen that reloads from scratch.<\/p>\n<p><!-- \/pn-faq --><!-- pn-related-reading --><\/p>\n<h2>Related reading<\/h2>\n<ul>\n<li><a href=\"https:\/\/loadfocus.com\/blog\/comparisons\/android-app-automation-testing-tools\/\">Best Android App Automation Testing Tools<\/a><\/li>\n<li><a href=\"https:\/\/loadfocus.com\/blog\/2016\/12\/how-to-send-an-android-application-to-background-and-reopen-it\">Send an Android App to Background and Reopen It<\/a><\/li>\n<li><a href=\"https:\/\/loadfocus.com\/blog\/tech\/2017\/12\/how-to-click-a-link-by-text-in-selenium-webdriver-java\">How to Click a Link by Text in Selenium WebDriver Java<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> &lt; 1<\/span> <span class=\"rt-label rt-postfix\">minute read<\/span><\/span>Key takeaways Appium reaches the Android system buttons through key events rather than element clicks. Back and Home behave differently: one navigates, the other backgrounds the app. Test the resume path after Home, since that is where state bugs appear. Using the Overview, Home and Back native buttons is pretty straight forward using WebDriver and&#8230;  <a href=\"https:\/\/loadfocus.com\/blog\/tech\/2016\/10\/how-to-use-the-overview-home-and-back-buttons-in-appium-for-android\" class=\"more-link\" title=\"Read How to use the Overview, Home and Back buttons in Appium for Android\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[20,19],"class_list":["post-110","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile-testing","tag-use-back-button-in-android","tag-use-native-buttons-in-appium"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":7,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":340,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/posts\/110\/revisions\/340"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/media\/505"}],"wp:attachment":[{"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}