Appium is a powerful open-source tool for automating mobile application testing across various platforms like Android and iOS. It allows developers to run tests on native and hybrid mobile applications using the same codebase, making it a highly versatile framework.
This article will guide you through running Appium tests on real Android devices, including setup, writing test scripts, and understanding the importance of real device testing for accurate results.
What is Appium?
Appium is an open-source framework that allows us to conduct automation testing of mobile applications on different platforms like Android, iOS, and Windows.
It automates the testing for:
- Native Mobile Applications that are written using iOS, Android, or Windows SDKs
- Mobile Web Applications that can be accessed using mobile phone browsers such as Safari, Chrome, or the in-built native browser applications for android devices
- Hybrid Mobile Applications that have a native wrapper around the web view
Appium is a cross-platform testing framework that is flexible, enabling you to write the testing code against multiple platforms such as iOS, Windows, and Android using the same API. This means you can use the same code for iOS that you have written for Android, saving lots of time and effort.
Benefits of Appium
Below are the reasons why Appium is important:
- Cross-Platform Testing: Appium allows testing on Android, iOS, and Windows using a single API, saving time and effort by reusing code across platforms.
- Language Flexibility: It supports multiple languages, such as Java, Python, Ruby, JavaScript, and C#, enabling developers to work in their preferred language.
- No App Modification Needed: Appium allows testing of native, hybrid, and mobile web apps without altering the app code, making it convenient for production testing.
- Real and Virtual Device Support: It supports real devices and emulators, providing the flexibility to test apps under different conditions.
- Open-Source with Active Community: Free and open-source, Appium is continuously updated by a large community, ensuring it remains reliable and cutting-edge.
- CI/CD Integration: Easily integrates with CI/CD tools like Jenkins, enabling automated mobile testing as part of the development pipeline.
- Feature-Rich: Supports gestures, element interactions, and multiple orientations, covering various mobile testing needs.
How to Run Appium Tests on Android Devices
To run Appium tests on Android, you need to set up the necessary tools and components, including the Appium server, Java, TestNG, and the Appium client library. Once set up, write your test scripts using Java and the Appium WebDriver.
Here’s the basic process for setting up and writing Appium tests:
- Install the required tools (Appium, Java, TestNG, Appium Client Library, etc.)
- Enable developer mode on your Android device.
- Define Desired Capabilities for the test device.
- Write and execute test scripts using the Appium Java Client API.
The code below demonstrates how to write Appium test scripts. The example here uses Eclipse IDE to run Appium tests on Android devices.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; public class AppiumExample{ WebDriver driver; WebDriverWait wait; String AppURL = "https://www.browserstack.com/"; @BeforeTest public void setup() throws MalformedURLException { // Create an object for Desired Capabilities DesiredCapabilities capabilities = new DesiredCapabilities(); // Name of mobile web browser to automate. capabilities.setCapability("browsername", "chrome"); //device name capabilities.setCapability("GalaxyS4", "WKZLMJLB7L8TR8SW");
// Which mobile OS platform to use - iOS, Android, or FirefoxOS capabilities.setCapability("platformName", "Android"); // Java package of the Android app you want to run capabilities.setCapability("appPackage", "com.android.chrome"); // Activity name for the Android activity you want to launch from package capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main"); // Initialize the driver object with the URL to Appium Server passing the capabilities. Server Url may vary driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); wait = new WebDriverWait(driver, 5); }@Test public void testSearchAppium() { driver.get(AppURL); String homePageTitle = titleElement.getText(); Assert.assertEquals(homePageTitle, Most Reliable App & Cross Browser Testing Platform | Browserstack "); WebElement LinkElement = driver.findElement(By.xpath("//body[@class='page-template-default page page-id-593 page-parent live persistent-header wpb-js-composer js-comp-ver-6.0.5 vc_responsive']")).click(); wait.until(ExpectedConditions.presenceOfElementLocated(byPageTitle)); String searchPageTitle = driver.findElement(byPageTitle).getText(); Assert.assertEquals(searchPageTitle, "Search"); }@AfterTest public void tearDown() { driver.quit(); } }
Run Appium Tests on Real Android Devices for Free
Why use Real Android Devices for Appium Tests?
Although emulators are useful in the early stages of development, real Android devices provide the most accurate representation of how your app will perform in real-world conditions. Emulators often fail to replicate critical factors such as network throttling, battery performance, or actual hardware configurations, which can impact the end-user experience.
Testing on real Android devices offers several advantages:
- Accurate user experience simulation: Ensures the app functions as expected under real conditions.
- Variety of devices: Test on various devices, including multiple Android OS versions, screen sizes, and hardware configurations.
- Better performance: Real devices offer faster and more reliable testing than emulators, leading to more precise results.
Use BrowserStack App Live and App Automate for Appium Tests
BrowserStack’s Real Device Cloud allows you to run manual and automated mobile app tests on real Android devices, ensuring that your tests reflect true user experiences.
With seamless integration of Appium, you can automate your tests on various Android devices without needing an in-house device lab.
Benefits of using BrowserStack for Appium Testing:
- Real Devices: Test on thousands of real, physical Android devices, ensuring accurate, real-world results.
- Cross-Device Compatibility: Easily test on multiple devices, OS versions, and screen sizes to ensure consistent app performance.
- Geolocation Testing: Simulate various geographic locations for location-based app functionality testing.
- Network Simulation: Test your app under different network conditions, such as 2G, 3G, or 4G.
- Push Notifications: Test how your app handles push notifications in real user conditions.
- Advanced Debugging Tools: Access a range of logs and video recordings for effective debugging.
- Instant Access: Sign up for free and get instant access to the devices you need for testing, with no setup required.
Useful Resources for Appium
Tutorials
- How to perform Parallel Test Execution in Appium?
- Appium Visual Testing: The Essential Guide
- How to run Appium iOS Tests on Real Devices?
- How to perform Debugging in Appium
- How to Run Your First Appium Test Script
- How to report bugs in Appium UI Testing?
- How to run Appium Tests on macOS?
- XPath in Appium: Tutorial
- How to Analyze Appium Logs
- How to perform Drag and Drop using Appium
- How to test mobile app in Landscape or Portrait mode using Appium
- How to Run Same Script in Multiple Devices using Appium
- How to change Time Zones for Mobile App Testing using Appium
- How to Perform Localization of Mobile Apps using Appium
- What is Appium Inspector? (Benefits & How to Use it?)
- How to run Appium tests on Android devices
- How to scroll down to an element in Appium
- How to Download and Install Appium
- How to set up your Appium Grid
- How to test Biometric authentication using Appium?
- How to use touch actions in Appium?
- How to Automate a Real E2E User Flow involving App and Browser with Appium
- How to Inspect Element using UIAutomatorViewer in Appium
- How to Test Flutter Apps Using Appium Automation
- Understanding Appium Desktop: Tutorial
- Appium Tutorial for Mobile Application Testing
- React Native and Appium Tutorial
- Understanding FindElements in Appium
Best Practices, Tips, and Tricks
- Appium Best Practices Every Developer Must Know
- Effective Locator Strategies in Appium
- Top Appium Commands every Developer must know
- Desired Capabilities in Appium
- Overcoming Top Challenges faced in Appium Automation
Getting Started with
- Getting Started with Appium and NUnit framework
- WebdriverIO Tutorial: Getting started with Test Automation using Selenium and Appium
- Appium with Python: Getting Started with App Automation Testing
- Appium with Java: Getting Started to Run Automated Tests
- Test Windows Desktop App using Appium-Compatible WinAppDriver
Differences and Comparisons
- Running Appium Tests on iOS Simulator vs Real Devices
- Appium vs XCUITest : Key Differences
- Appium vs Espresso: Key Differences
Conclusion
You can also leverage a plethora of debugging options for Appium testing on BrowserStack such as Text logs, Network Logs, Device Logs, Appium Logs, Visual logs, and Video Recordings of tests. Explore Debugging Options on BrowserStack App Automate
Since users demand high-functioning and engaging apps, Appium testing is an absolute requirement before releasing any apps. By running Appium tests on real Android devices, testers can ensure that apps are working as expected in real user conditions. Run as many tests as possible on as many real Android devices as possible to offer a consistently optimal user experience.