Real Device
When testing mobile apps, it's important to test them on real devices to ensure that they work as expected in real-world conditions. Real device testing allows you to see how the app behaves on actual hardware, providing more accurate results than emulators or simulators. This tutorial explains how to set up and use real devices for testing with Appium in simple terms.
Testing on real devices provides several benefits:
- Real-world Performance: Emulators may not mimic real-world performance, network conditions, or battery consumption.
- Device-Specific Bugs: Some bugs only appear on specific hardware or OS versions.
- Compatibility: Ensures the app works across different devices and OS versions.
- Real Gestures and Interactions: Testing on a real device allows you to interact with actual gestures, notifications, and hardware buttons.
To test on a real device, you’ll need to configure both Appium and the device (Android or iOS). Here’s how to set it up.
Setting Up Android Real Device for Appium
- Enable Developer Mode on Android:
- Go to Settings > About Phone.
- Tap on Build Number several times (usually 7) until you see a message saying "You are now a developer!"
- Go back to Settings and find Developer Options.
- Enable USB Debugging:
- In Developer Options, enable USB Debugging.
- Install Android SDK and ADB:
- Make sure you have the Android SDK installed. ADB (Android Debug Bridge) is a part of the SDK, which allows Appium to communicate with your device.
- You can download the SDK from the Android developer website.
- Connect the Device to Your Computer:
- Connect your Android device to your computer using a USB cable.
- Run the command adb devices in a terminal to check if the device is detected. You should see your device listed.
- Set Desired Capabilities in Appium:
- Configure Appium to target your specific device and app. Here’s an example configuration:
Java
C#
Python
Javascript
Kotlin
Copy
UiAutomator2Options options = new UiAutomator2Options(); options.setPlatformName("Android"); options.setPlatformVersion("12"); options.setAppPackage("com.example.demoapp"); options.setDeviceName("Pixel_4_Emulator"); options.setAutomationName("UiAutomator2"); options.setApp("/path/to/your/app.apk");
C# code coming soon
Python code coming soon
Javascript code coming soon
Kotlin code coming soon
Setting Up iOS Real Device for Appium
- Enable Developer Mode on iOS:
- Connect your iOS device to a Mac.
- Go to Settings > Privacy & Security and enable Developer Mode.
- Install Xcode:
- Download and install Xcode from the Mac App Store. Xcode includes the tools required to communicate with iOS devices.
- Sign App with a Development Profile:
- iOS apps need to be signed with a provisioning profile and certificate. This allows the app to be installed on the real device.
- You can create a provisioning profile through the Apple Developer portal if you have an Apple Developer account.
- Trust the Developer Certificate on the Device:
- On your iOS device, go to Settings > General > Device Management.
- Find your developer profile and tap Trust.
- Set Desired Capabilities in Appium:
- Configure Appium to target your specific iOS device. Here’s an example configuration:
Java
C#
Python
Javascript
Kotlin
Copy
XCUITestOptions options = new XCUITestOptions(); options.setPlatformName("iOS"); options.setUdid("your_device_udid"); options.setDeviceName("YourDeviceName"); options.setBundleId("com.example.app"); URL url = new URL("http://192.168.43.3:4723"); IOSDriver driver = new IOSDriver(url,options);
C# code coming soon
Python code coming soon
Javascript code coming soon
Kotlin code coming soon