This Tutorial Explains how to Connect a Mobile Device with PC and Configure it for Automation Testing Using Appium. It covers the Verification of Mobile by ADB:
We have to connect a real-time Android device with the PC in order to automate Android application tests in the Android device using Appium.
For test cases to run on devices, we need to ensure that :
- USB Debugging mode is enabled on the mobile device.
- ADB recognizes the device connected to the system.
- Changing the Desired capability as per the device/application.
=> Check ALL Appium Tutorials Here.
What You Will Learn:
Configure Mobile Device With System In Appium
Here is a Video Tutorial:
Enable USB Debugging Mode In Mobile Device
This can be done in 2 ways.
- Enable USB debugging mode in settings of Mobile devices.
- Activate USB mode through PDANET+ software.
#1) Developer Options
- Navigate to the Settings app on the phone.
- Scroll down and click on the Developer Options.
- Turn on the Developer Options and click the USB Debugging.
Some devices do not have “Developer Options” under Settings. In such cases, follow the below steps:
- Navigate to Settings > About Phone > Build Number.
- Dab on Build number 7 times, then a pop up will appear saying ‘You are now a developer’.
- Then Go back to settings. You will find ‘Developer Options’ getting listed.
- Enable ‘USB Debugging’ and now the device is ready to connect to the system.
- Once done, you will now be able to enable/disable it whenever you desire by going to Settings -> Developer Options -> Debugging -> USB debugging.
#2) Using PDANET+
- Install PDANet+ from PlayStore.
- Open the application and select ‘Activate USB Mode’.
- Once the USB mode is selected, your device is ready to be connected to the system
Also, make sure to have PDANet+ installed in the system when you try to enable USB debugging mode in the mobile devices through PDANet+ app.
DOWNLOAD PDANet+ In System
- Go to PDANet+ DOWNLOAD PAGE.
- Click on the download link as shown in the above image. It will download the installation file.
Installation Of PDANet+ In System
- Connect your Android phone with PC with USB debugging mode enabled.
- Double click on PDANet+ installation .exe file.
- It will open the PDANet+ installation dialog.
- Proceed for installation with default selected options and settings on each screen of installation dialog.
You can choose either one of the options (through Settings or through PDANet+ app) mentioned to enable USB debugging mode. Once the USB mode is enabled, connect the device to the system using the USB cable.
Verify If System Recognizes A Device Using ADB
To verify if the system is able to recognize the device,
- Open command prompt
- Type >‘adb devices’
- Click on Enter.
The device name should be listed in its response as below. In this case, only one device is attached, so the device name of that mobile is listed as ‘AVY9KA90322022030’.
This command displays all devices connected to the system at that instance (might one or two or more devices also).
Note: We need to make sure that the Android SDK is installed in the system and its environment path is set, before running the ADB command.
If the device is not displayed in the response, then there might be some issue with device connection or sometimes USB debugging mode may not be enabled properly.
Desired Capabilities is a JSON object (which is a set of key-value pairs) sent by the client libraries to the Appium server.
Desired Capabilities is a class in Selenium and is used to store properties of devices and applications. These properties are read by Appium at run time and recognize the device and application for automation. We need to import “import org.openqa.Selenium.remote. DesiredCapabilities” library file and add it to the project in order to work with the Desired Capabilities.
In order to ensure automation on the mobile device connected, we mention the device name in the Desired Capabilities and Appium uses it during execution in order to find the device and automate it.
Now, let us have a look at the major capabilities used for Automation.
|platformName||It is used to set the mobile OS platform. We can pass values as iOS, Android, or FirefoxOS:
The below command can also be used : caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
|platformVersion||To set the mobile OS version,
for example, use the following command: caps.setCapability("platformVersion","5.6");
The below command can also be used: caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.6");
|deviceName||We can define the type of mobile device or emulator to use, using the following command,
for example :
caps.setCapability("deviceName", " AVY9KA90322022030’");
You can use the following command as well: caps.setCapability(MobileCapabilityType.DEVICE_NAME," AVY9KA90322022030’");
(Device name is obtained when we type ‘adb devices)
|appPackage||This capability is for the Java package of the Android app that you want to run,
for example, com.android.calculator2 for calculator, com.android.settings to Open Settings app, and so on:
Alternatively, you can use this command: caps.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculator
(we will discuss in detail in the next section on how to get appPackage name from device)
|appActivity||By using this capability, you can specify the Android activity that you want to launch from your package,
for example, MainActivity, .Settings, com.android.calculator2.Calculator, and so on:
You can also use the following command: caps.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator
(we will discuss in detail in the next section on how to get appActivity name from device)
|browserName||If you want to automate mobile web applications, then you have to use this capability to define the browser.
For Safari on iOS, you can use this: caps.setCapability("browserName", "Safari");
Also, you can use the following command: caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
For Chrome on Android, you can use this: caps.setCapability("browserName", "Chrome");
Alternatively, you can use the following command: caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
Thus we have seen the method of configuring mobile devices with systems in Appium, the ways of enabling USB debugging mode in mobile devices as well as installation of PDANet+ in the system.
Our upcoming tutorial will explain how to automate applications on a real-time mobile device using Appium.