5 Ways To Automate App Testing With Appium

0
11

If mobile applications need to keep up with growing customer expectations, they must perform well and be compatible with a wide range of devices on the market. As a result, businesses are attempting to ensure maximum cross-platform compatibility. Automation testing improves testing speed and accuracy. It is an efficient method of detecting flaws in new mobile applications.

This testing covers a wide range of topics, including usability, security, performance, quality, and functionality. It also evaluates a new application’s ability to interact with other applications.

Appium is an open-source automation framework that makes mobile app testing much more efficient by providing scalability and flexibility. Appium automation has become a leading testing method for mobile applications because of its extensive features and rapid adoption in the mobile application industry.

What Is Appium?

The Appium software is an open-source and cross-platform test automation tool for native, hybrid, web, and desktop apps. A mobile application automation tool designed for iOS and Android. Using WebDriver-based technology, Appium allows you to automate a wide range of mobile and desktop platforms. 

The following tests are automated:

  • SDK-based native mobile applications for Android, iOS, and Windows
  • Mobile web applications can be accessed using mobile browsers such as Safari, Chrome, or the native Android browser application.
  • The web view is encased in a native wrapper in hybrid mobile applications.

Appium, a cross-platform testing framework, allows testers to write test scripts for iOS, Windows, and Android using the same API. Because the same code can be used for iOS and Android, QAs can save time and effort.

QAs can write test scripts in a variety of programming languages, including Java, JavaScript, PHP, Ruby, Python, and C#, using the Appium testing framework. Appium scripts, like Selenium scripts, can be written in a variety of programming languages, including Java, JavaScript, PHP, Ruby, Python, and C#.

Appium-Supported Platforms

Before delving deeper into Appium Mobile Testing, it’s important to understand the platforms that Appium supports. In my personal experience, if we are unaware of the Appium support, we may waste our time trying out some implementation that is not supported by Appium.

Appium supports the following platforms and testing methods:

  • Hybrid Apps vs. Native Apps
  • Testing Web Apps on Actual Devices
  • Simulators and emulators used for testing.

Appium is compatible with iOS, Android, macOS, and Windows. The following are the drivers that are required for each platform:

  • Support for the XCUITest Driver and SafariDriver for Apple’s Safaridriver on iOS.
  • For Firefox and GeckoView, Android supports the UiAutomator2 Driver, Espresso Driver, and Geckodriver. However, UIAutomation Driver support for both iOS and Android has been deprecated.
  • The Mac2 Driver is supported by macOS 10.15. (or later). WinAppDriver Geckodriver for Firefox and GeckoView is supported by Windows Desktop.
  • Aside from these, the Appium official website lists some vendors/community-based drivers.

How Does Appium Function?

Appium automatically interacts with an application by leveraging the behaviour of various UI components such as buttons, text boxes, and links. It can be reused to write and run tests against the given application multiple times during different sessions.

Appium Works As Follows On Android And IOS Mobile Devices:

  • Appium running on an Android device

To automate application testing on Android devices, Appium employs the UIAutomator framework (or Selendroid), designed to test the Android user interface. The bootstrap.jar file acts as a TCP server, sending test commands to the Android device via the UIAutomator or Selendroid framework.

  • Appium running on an iOS device

Appium uses the JSON wire protocol for iOS devices the same way it does for Android devices. It interacts with the user interface elements for automated iOS device testing using Apple’s UIAutomation API. The bootstrap.js file acts as a TCP server, sending the test command to the iOS device via Apple’s UIAutomation API framework.

What Is The Appeal Of Appium?

Appium remains the first choice for app automation testing with mobile app testing, regardless of the application type – native, hybrid, or mobile web, running on Android, iOS, or Windows smartphones and tablets. Its popularity stems from several factors, including:

  • It is a server that operates in the background.
  • It can be synchronised with the TestNG testing framework to provide more features.
  • Appium, which includes a UIAutomator, can generate detailed information logs and has a detailed reporting structure for better analysis of test results and improved debugging.
  • It allows you to write test code in a variety of languages (Java, JavaScript, PHP, Ruby, Python, and C#).
  • It allows for the reuse of the same code across multiple device platforms such as iOS, Android, and Windows. This saves a significant amount of time and effort.
  • It gives QAs complete control over the back-end APIs and databases via test code. This aids in the evaluation of defects originating from back-end APIs or databases.
  • Appium uses the standard automation APIs on all platforms, so testers do not need to change or recompile the app under test. They do not need to have access to the application’s source code.
  • It enables mobile application testing on emulators, simulators, or actual devices, giving users the freedom to select their testing device and environment. Keep in mind, however, that emulators and simulators are insufficient for final-stage testing. They cannot replicate many device features, such as low battery or an unstable network, which is required to optimise the app for inappropriate situations. Only real-world device testing can provide conclusive, accurate results and qualify an app for real-world user environments.
  • It is cross-platform compatible, allowing the same tests to run on multiple platforms, increasing coverage.
  • It provides real-time monitoring of tests, which makes their execution more robust.
  • Appium enables the execution of test automation scripts on multiple Android or iOS sessions simultaneously using UIAutomator, UIAutomation, or Xcode9. This expedites testing and ensures scalability.
  • With so many incredible features, Appium is the best automation testing framework for mobile application testing.

The Performance Impact Of Running Appium Tests

Appium is a small application that uses brief memory. Appium acts as a proxy between your test machine and each platform automation toolkit, so its architecture is actually quite simple and light. When Appium is up and running, it will listen for HTTP requests from your tests and, when a recent session is created, a component in Appium’s Node.js code called _proxy_ will forward these Selenium commands to active platform drivers.

How To Find Elements For Appium Testing?

Before beginning writing test scripts, you must first understand how to identify elements by using attributes such as ID, Name, Class, and so on to perform actions. 

You can use UIAutomatorViewer or Appium inspector to capture a snapshot of the current device screen, which shows the hierarchy of the UI components properly arranged on the screen, to identify (or locate) elements.

The UI Automator Viewer is a graphical user interface (GUI) tool included with the Android SDK that is primarily used to inspect the UI components of an Android application. It also allows you to view the properties that are associated with it. On Windows, we can find it in the Android SDK “tools” folder than ‘uiautomatorviewer.bat’.

The Prerequisite Of Appium

  • Install the ANDROID SDK.
  • Install the JDK (Java Development Kit)
  • Eclipse should be installed.
  • Install the TestNg plugin for Eclipse.
  • Install Selenium Server JAR Appium Client Library APK on Google Play js (Not required – When an Appium server is installed, it includes “Node.exe” and NPM by default. Appium’s current version includes it.)

How To Use Appium Inspector?

Appium Inspector is a default inspector available in standalone Appium (but not in the npm version) that can inspect Android and iOS elements. It simply mirrors the device’s screen, allowing us to interact with it and get element details. Let’s see how we can get it up and working.

  • Click on Start Server to launch Appium from your application/programs menu.
  • Click the Search icon in the upper right corner.
  • Add the capabilities for your device/emulator and application. Then press the Start Session button.
  • It will launch the App screen, App Source (the element hierarchy), and Selected Element Pane (The attributes and associated values of the element). This can create locators that uniquely identify the element.
  • Inside Appium Inspector, you can provide a.apk or.app file in the desired capabilities, which will install and launch the app. Refer to the screenshots below to see how we tested.apk and passed in the value for “app.”

The Appium Inspector’s best feature is the ability to validate your written locator on screen. If your locator is correct, the associated element will be highlighted.

How Can Appium Tests Be Run On IOS And Android?

I’ll walk you through the steps for running Appium tests with iOS and Android in this section of this Appium testing tutorial. First, ensure that the Appium server is operational. To get started with Appium testing, refer to the section “How to Start the Appium Server” in this blog.

Then we ensure that the Android emulator we created in the section “Android Emulators for Appium testing” is operational. We’ll need to use adb devices for this.

Appium Testing With Demo Code

Here, we’re using simple code anyone can use for their first Appium test. 

You should attempt to validate two important scenarios in any test: “open the geolocation page” and “speed test page.” Aside from the code, I’ll show a screenshot taken on the emulator while running the test script for both of the scenarios mentioned above.

We are now halfway through. To run our sample test for Appium testing on an Android APK emulator online, we simply need to execute the two commands listed below. The first command installs dependencies and the second run our suite.

Real Device Cloud Appium testing

When we talk about Appium testing or trying to identify the real use of Appium, two things come to mind from my previous experiences: The first is that Appium supports both Android and iOS automation testing, and the second is that it is a free source.

Remember that the learning curve for Appium testing is also quite simple, as you must have realised by now if you’ve made it this far.

Remember that we have been running our test scripts on an emulator until now, but you may wonder if you want to run on an actual device cloud. The best part is that running our existing scripts on actual devices is a piece of cake.

Cloud-based testing platforms like LambdaTest offers real device cloud that lets you perform mobile automation testing on 3000+ real browsers, devices and operating systems. The major benefit of using a real device cloud like LambdaTest is that it eliminates to set up an in-house device labs for Appium testing. 

LambdaTest also offers different automation testing frameworks like Selenium, Cypress, Playwright and more.

Automation Of iOS mobile web

Appium can automate the Safari browser on both real and simulated iOS devices. Setting the desired browser name capability to Safari and leaving the app capability empty allows you to access it.

  • To ensure that the correct preferences are set, you must run Safari on the device before attempting to use Appium.
  • Executing your test
  • To run your test against Safari, simply change the “browserName” to “Safari.”
  • Mobile web automation for Android
  • Appium supports both real and emulated Android devices for automating the Chrome browser.

Hybrid App Automation

One of Appium’s guiding principles is that you shouldn’t have to change your app to test it. Under that method, hybrid apps can be tested like web apps can be tested with Selenium. Appium requires some technical complexity to determine whether you want to automate the native aspects of the app or the web views. But, thankfully, we can keep everything within the Selenium WebDriver protocol.

Once the test is in a web view context, the entire Selenium WebDriver API is available. To communicate with a web view in your Appium test, follow these steps:

  • Navigate to a section of your app that has a web view active.
  • Get the contexts that are currently available.
  • This returns a list of contexts, such as ‘NATIVE APP’ or ‘WEBVIEW 1’.
  • Set the context to the id of the context to which you want to gain access.
  • This switches your Appium session into a mode in which all commands are interpreted as if they should automate the web view rather than the native app. GetElementByTagName, for example, will operate on the DOM of the web view rather than returning native elements. Of course, some WebDriver methods only make sense in either, so if you use them in the wrong context, you will get an error message.
  • To exit the web view context and return to the native portion of the app, simply set the context with the native context id (generally ‘NATIVE APP’) to leave the web context and access the native commands once more.
  • On session start, the web view context is automatically entered.
  • If your app starts in a web view, you don’t want to automate the native app before entering it; you can have Appium enter the web view context on session initialization by setting the autoWebview desired capability to true.

Android Hybrid App Automation

Appium includes built-in hybrid support via Chromedriver, allowing it to automate any Chrome-backed Android web views.

Unfortunately, there is an additional step required within your app build. As described in the Android remote debugging documentation, the setWebContentsDebuggingEnabled property on the android.webkit.WebView element must be set to true.

Follow the generalised instructions above after you’ve set your desired capabilities and started an Appium session.

iOS Hybrid App Automation

Appium connects to a web view using a unique remote debugger in order to interact with it. Since the simulator and the Appium server are on the same machine, a direct connection is made when executing against a simulator. The WkWebView and UIWebView elements can be automated with Appium. SafariViewController elements can’t currently be handled by it, unfortunately.

Follow the general instructions above after you’ve started an Appium session and set your desired capabilities.

Steps For Debugging Common Appium Errors

  • Ensure that the Android emulator is activated and running before launching the suite. Running adb kill-server and adb devices is helpful. By doing this, the Android device’s connection can be reset and the problem fixed.
  • Try performing a cold boot if the Android emulator you’re using with Fastboot isn’t being correctly detected by ADB: Cold Boot Now can be found under Android Studio > Tools > AVD Manager. Refer to Step 6 from the “Android Emulators for Appium testing” section to learn how to cold boot, and this will largely resolve all emulator issues.
  • Make sure Xcode has downloaded device symbols if the Instrument for iOS crashes when running against a physical device (“exited with code 253”). After selecting Window -> Devices, it should launch immediately. After updating iOS versions, it is required.
  • The certificate needed for creating the app and the WebDriverAgent is stored in the macOS keychain, which must be unlocked, particularly if you’re using ssh.

Conclusion

Appium is a well-known mobile automation testing tool for mobile browsers and mobile applications. It validates mobile browser and application compatibility, usability, and response time across various mobile devices.

Appium will be a piece of cake if you’re familiar with Selenium. It’s essentially a Selenium WebDriver for testing mobile devices. The Appium server’s primary function is to receive test requests in JSON format and convert them into commands that can be accepted by native testing frameworks.

This article went in-depth on the fundamentals of the Appium framework for testing Android and iOS apps in this tutorial on mobile app testing. 

LEAVE A REPLY

Please enter your comment!
Please enter your name here