Lab 5
Lab 5
Features of Appium:
• Like Selenium, Appium allows QAs to create test scripts in multiple programming languages – Java,
JavaScript, PHP, Ruby, Python, and C#.
• Appium is especially favored for being a flexible, cross-platform framework that testers can use to create
test scripts applicable to multiple platforms (Windows, iOS, and Android) – using the same API.
• Essentially, Appium users can reuse their source code for Android and iOS, thus reducing the time and
effort of building tests. Unlike other automation tools, Appium doesn’t require you to modify the app’s
source code to enable automation.
• Supports the automation of native, hybrid, and mobile web applications, accommodating a wide range
of app types.Integrates with cross-platform mobile app development frameworks like React Native,
Xamarin, and Flutter.
• Provides built-in tools like Appium Desktop and Appium Inspector to inspect app elements and generate
test scripts
Objective:
To set up android studio and appium for mobile app testing.
Prerequisites:
1. Install Java Development Kit (JDK)
2. Install Node.js (https://nodejs.org/en/download/prebuilt-installer )
3. Android Setup:
• Install Android Studio: Download and install Android Studio.
4. Install Appium: Download and install Appium using npm (Node Package Manager).
sh
npm install -g appium@latest
for uninstall : npm un -g apppium
5. Verify appium is available on the system : appium -v which appium where appium
6. Run command appium to get information on our installed appium (CTRL + C to quit)
7. Install appium doctor (optional) npm install @appium/doctor --location=global
appium-doctor –help
appium driver list
appium driver install uiautomator2
appium driver list –updates
8. run appium server appium
appium –allow-cors
1|Page
--allow-cors: This is a flag that tells the Appium server to enable CORS - Cross-Origin Resource Sharing (CORS)
enabled
You might need to use this command if you're using a testing framework that runs on a different domain than the
Appium server.
For example, if you're using the Appium Inspector to record and edit test scripts, you'll need to start the Appium server
with CORS enabled if the Inspector is running on a different domain
This works on Appium 2.x versions
Step 8 - Can run command appium-doctor --android to check all requirements for Android Testing are completed
How to create and start Android Virtual Device (emulator) with Android Studio GUI App
Step 1 - Open Android Studio
Step 2 - Go to "Tools" -> "AVD Manager" (or click the AVD Manager icon in the toolbar)
Step 3 - Click "Create Virtual Device" and choose a desired device configuration (phone or tablet) with the required
Android API level
Step 4 - Click "Next" and follow the steps to define the AVD configuration (name, RAM, storage etc.)
Step 5 - Click "Finish" to create the emulator
Step 6 - Launch the emulator from the AVD Manager
Step 7 - Check the emulator is available in Device Manager
(Device manager will show all connected devices, virtual and physical)
2|Page
Here are some sample APK files that we can use for learning test automation
Can get some sample APK files from appium
https://github.com/appium/appium/tree/master/packages/appium/sample-code/apps
This contains both Android (.apk files) and iOS (.app files)
__________________________________________________________
Can search for APK files for apps like Calculator
3|Page
https://en.uptodown.com/android/search
__________________________________________________________
Browserstack https://github.com/browserstack/app-testing-examples/blob/master/app-debug.apk
__________________________________________________________
SauceLabs demo Apps
https://github.com/saucelabs/sample-app-mobile/releases
4|Page
Includes both android and ios apps
__________________________________________________________
TestProject demo app
https://github.com/testproject-io/android-demo-app
__________________________________________________________
Katalon Studio Sample apk files
https://github.com/katalon-studio-samples/katalon-mobile-automation/tree/master/Data%20Files
Note:
Appium Desktop has been deprecated and unsupported since Appium 2.0. It is no longer recommended for use due to known
security vulnerabilities and incompatibility with later versions of Appium.
We can use Appium Inspector
OR
5|Page
Step 2 : Start Appium Inspector
If you are using the web version of Appium Inspector start appium using command appium --allow-cors
Step 5 : Note the host and port of appium server and provide the same in Appium Inspector
6|Page
Step 7 : Add the Desired Capabilities as per the mobile device or emulator connected to the system
If you have multiple devices connected first get the device id using adb devices then run command
This command will provide the API level (e.g., “30” for Android 11, “29” for Android 10, etc.)
emulator -list-avds
Step 3 - Run command adb devices to see the device id. Can use this for deviceName
If you have multiple devices connected first get the device id using adb devices then run command
7|Page
{
"appium:automationName": "UiAutomator2",
"appium:platformName": "Android",
"appium:platformVersion": "14",
"appium:deviceName": "AVRK023C30029824",
If you don’t have APK file and want to use an existing app on the device can use appPackage and appActivity
8|Page
Step 3: Create TestNG Test Class
▪ Setup Your Test Class:
package mobileApp;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.android.AndroidDriver;
//import io.appium.java_client.MobileElement;
//import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
@BeforeClass
public void setUp() throws Exception {
// caps= new DesiredCapabilities();
BaseOptions options = new BaseOptions()
.amend("appium:automationName", "UiAutomator2")
.amend("appium:platformName", "Android")
.amend("appium:platformVersion", "14")
.amend("appium:deviceName", "emulator-5554")
.amend("appium:app", "J:/backup download/ApiDemos-debug.apk")
.amend("appium:newCommandTimeout", 3600)
.amend("appium:connectHardwareKeyboard", true);
@Test
public void sampleTest() {
driver.findElement(AppiumBy.accessibilityId("Graphics")).click();
driver.findElement(AppiumBy.accessibilityId("CameraPreview")).click();
driver.findElement(AppiumBy.accessibilityId("Accessibility")).click();
driver.executeScript("mobile: pressKey", Map.of("keycode", 4));
driver.findElement(AppiumBy.accessibilityId("OS")).click();
@AfterClass
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
9|Page
Step 4: Configure Appium in POM File
Inside pom.xml:
<dependencies>
</dependencies>
</project>
10 | P a g e