APPIUM For Android & iOS Mobile Apps Testing In Flutter
Hi everyone! today we learn about Appium for Android & iOS Mobile Apps Testing In Flutter. Appium is an open-source test automation tool used for testing mobile applications. It allows users to test various types of mobile applications (such as Native, Hybrid, and Mobile Web) using the standard WebDriver library.
If you’re looking for the best Flutter app development company for your mobile application then feel free to contact us at — support@flutterdevs.com.
Table Of Contents::
Attach Android Emulator to Appium
APPIUM Test Case for Native Android App(Calculator)
Common Encountered Errors and Troubleshooting Steps in Appium
What is Appium?:
APPIUM is a freely distributed open-source mobile application UI Testing framework. Appium allows native, hybrid, and web application testing and supports automation tests on physical devices as well as an emulator or simulator both. It offers cross-platform application testing, i.e. single API works for both Android and iOS platform test scripts.
It has NO dependency on Mobile device OS. Because APPIUM has a framework or wrapper that translates Selenium Webdriver commands into UIAutomation (iOS) or UIAutomator (Android) commands depending on the device type, not any OS type.
Appium supports all languages that have Selenium client libraries like- Java, Objective-C, JavaScript with node.js, PHP, Ruby, Python, C#, etc.
How APPIUM Works?:
- Appium is an ‘HTTP Server’ written using a Node.js platform and drives iOS and an Android sessions using Webdriver JSON wire protocol. Hence, before initializing the Appium Server, Node.js must be pre-installed on the system.
- When Appium is downloaded and installed, then a server is set up on our machine that exposes a REST API.
- It receives connection and command requests from the client and executes that command on mobile devices (Android / iOS).
- It responds with HTTP responses. Again, to execute this request, it uses the mobile test automation frameworks to drive the user interface of the apps. A framework like:-
- Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with OS X v10.5 and later)
- Google UIAutomator for Android API level 16 or higher
- Selendroid for Android API level 15 or less
Prerequisite To Use APPIUM:
- Install ANDROID SDK (Studio)
- Install JDK (Java Development Kit)
- Install Eclipse
- Install TestNG for Eclipse
- Install Selenium Server JAR
- Appium Client Library
- APK App Info on Google Play
- js (Not Required — Whenever the Appium server is installed, it by default comes with “Node.exe” & NPM. It’s included in the Current version of Appium.)
- Install Appium Desktop
Install Appium Desktop:
Appium Studio is an Open source GUI app to install Appium Server. It comes bundled with all the prerequisites to install and use Appium Server. It also has an Inspector to get basic information on your Apps. It comes with a Recorder to create boilerplate code to automate your mobile apps.
Step 1) Go to http://appium.io/ and click on Download Appium.
Step 2) For Windows, select the exe file and download. The file is around 162MB and will take time to download based on your internet speed.
Step 3) Click on the downloaded exe.
Step 4) On a Windows machine, there is no need to install Appium. It runs directly from the exe. Once you click the exe you will see the following image for a few minutes.
For Mac, you need to install the dmg
Step 5) Next you will see the Server Start Window. It populates the default host and port option which you can change. It also mentions the version of Appium being used.
Step 6) On clicking the Start Server Button, a new server is launched on the specified host and port. Server log output is shown.
Step 7) Click New Session Window.
Step 8) You can enter the Desired Capabilities and start a session.
APPIUM Inspector:
Similar to the Selenium IDE record and playback tool, Appium has an ‘Inspector’ to record and Playback. It records and plays native application behavior by inspecting DOM and generates the test scripts in any desired language. However, currently, there is no support for Appium Inspector for Microsoft Windows. In Windows, it launches the Appium Server but fails to inspect elements. However, the UI Automator viewer can be used as an option for Inspecting elements.
Steps to start with Appium Inspector on a Mac machine:-
Step 1) Download and start your Appium server with the default IP Address 0.0.0.0 and port 4725.
- Select the source file or .app files from local to test.
- Check the ‘App Path’ Checkbox to enable the ‘Choose’ button.
Step 2)Now, clicking on the ‘Choose’ button will give the option to browse and select the test file from the local drive.
Step 3) Start Simulator on a Mac machine.
Step 4) Click the ‘Launch’ button from the top right corner, which enables a blue color icon. Again, click on this blue color icon, it will open the Appium inspector and Simulator with a pre-selected application.
Step 5)– Launching your Appium Inspector will show the element hierarchy in a column-wise structure. Also, a user can apply actions using buttons like Tap, Swipe, etc.
Step 6) Click on the ‘Stop’ button to stop recording.
Attach Android Emulator to Appium:
Step 1) Install Android SDK in your system.
Go to Control panel >> System and Security >> System and from the left panel click on ‘Advanced System Settings. From the ‘System Properties’ pop-up, click on the ‘Advanced’ tab and then click on the “Environment Variables” button.
Step 2) Now, from the ‘Environment variables’ pop-up, ‘double-click on ‘Path’ and set the ANDROID_HOME variable that points to your SDK directory. In the path append the whole SDK folder path.
e.g. –C:\User\ABC\Desktop\adt-bundled-windows-x86_64-20140321\sdk
Step 3) Start your Android emulator or attach any Android device to your system (Make sure you have the Android Debugging option enabled in your Android device. To check Debugging Option. Go to Device Settings >> Developer Options >> Check “Debugging Option”).
Step 4) Open Command Prompt and navigate to your Android SDK’s \platform-tools\ directory (E.g. D:\adt-bundle-windows-x86_64–20130514\sdk\platform-tools).
Step 5)– Run the ADB devices’ command. You can see your connected device listed in Command Prompt window. (In CMD write ‘>adb devices’- This command will list the connected emulator instances. E.g.: ADB –s emulator-5554 install <Location of .apk file>)
Step 6)– Run the ADB start-server command. It will start the ADB server that will be used by Appium to send commands to your Android device.
Step 7) Now, navigate to the Appium directory in your system and start Appium by clicking an Appium.exe file.
Step 8) Do not alter the IP address or port number and click the ‘Launch’ button. Your Appium console starts at 127.0.0.1:4723 as shown below.
Step 9) Click on the ‘Start’ button, Appium server started running on your system.
APPIUM Test Case for Native Android App(Calculator):
Step 1) Download the ADT eclipse plugin or download ADT bundled separately here
Step 2) Open Eclipse and Create a new Project >> Package >> Class
Step 3) Import the Selenium library and Test-inside that new project.
Step 4) Now Create a small test Program for ‘Calculator. app’ to sum two numbers.
package src_Appium;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
public class Calculator {
WebDriver driver;@BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("BROWSER_NAME", "Android");
capabilities.setCapability("VERSION", "4.4.2");
capabilities.setCapability("deviceName","Emulator");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
// This package name of your app (you can get it from apk info app)
capabilities.setCapability("appActivity","com.android.calculator2.Calculator"); // This is Launcher activity of your app (you can get it from apk info app)
//Create RemoteWebDriver instance and connect to the Appium server
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new RemoteWebDriver(new URL("https://127.0.0.1:4723/wd/hub"), capabilities);
}@Test
public void testCal() throws Exception {
//locate the Text on the calculator by using By.name()
WebElement two=driver.findElement(By.name("2"));
two.click();
WebElement plus=driver.findElement(By.name("+"));
plus.click();
WebElement four=driver.findElement(By.name("4"));
four.click();
WebElement equalTo=driver.findElement(By.name("="));
equalTo.click();
//locate the edit box of the calculator by using By.tagName()
WebElement results=driver.findElement(By.tagName("EditText"));
//Check the calculated value on the edit box
assert results.getText().equals("6"):"Actual value is : "+results.getText()+" did not match with expected value: 6";}@AfterClass
public void teardown(){
//close the app
driver.quit();
}
}
Appium Server and Android Emulator from ‘AVD Manager’ and Click Run >> TestNG. The above program will run the ‘Calculator. app’ on the selected emulator and the Result is displayed under the Eclipse console using a TestNG framework.
Limitations Using APPIUM:
- Appium does not support testing of Android Version lower than 4.2
- Limited support for hybrid app testing. e.g.: not possible to test the switching action of the application from the web app to native and vice-versa.
- No support for running Appium Inspector on Microsoft Windows.
Common Encountered Errors and Troubleshooting Steps in Appium:
Conclusion:
With emerging trends and more demand for Mobile Apps, all major companies are migrating to get their business on mobile apps. Thus to release quality mobile apps, automation testing of mobile apps is the latest trend in the industry.
Appium, because of its simplicity and ease of use, is one of the leaders and most widely used tools all over the globe for the automation testing of mobile apps for iOS or Android.
❤ ❤ Thanks for reading this article ❤❤
If I got something wrong? Let me know in the comments. I would love to improve.
Clap 👏 If this article helps you.
Feel free to connect with us:
And read more articles from FlutterDevs.com.
FlutterDevs team of Flutter developers to build high-quality and functionally-rich apps. Hire a flutter developer for your cross-platform Flutter mobile app project on an hourly or full-time basis as per your requirement! For any flutter-related queries, you can connect with us on Facebook, GitHub, Twitter, and LinkedIn.
We welcome feedback and hope that you share what you’re working on using #FlutterDevs. We truly enjoy seeing how you use Flutter to build beautiful, interactive web experiences.