0
0
Testing Fundamentalstesting~10 mins

Emulators vs real devices in Testing Fundamentals - Test Execution Compared

Choose your learning style9 modes available
Test Overview

This test compares running a mobile app test on an emulator versus a real device. It verifies that the app launches and a key button is clickable on both platforms.

Test Code - Appium with unittest
Testing Fundamentals
from appium import webdriver
import unittest

class TestAppOnDevices(unittest.TestCase):
    def setUp(self):
        # Setup for emulator
        self.emulator_caps = {
            'platformName': 'Android',
            'deviceName': 'Android Emulator',
            'app': '/path/to/app.apk'
        }
        # Setup for real device
        self.real_device_caps = {
            'platformName': 'Android',
            'deviceName': 'RealDevice123',
            'app': '/path/to/app.apk'
        }

    def test_on_emulator(self):
        driver = webdriver.Remote('http://localhost:4723/wd/hub', self.emulator_caps)
        button = driver.find_element('id', 'com.example.app:id/startButton')
        button.click()
        self.assertTrue(button.is_enabled())
        driver.quit()

    def test_on_real_device(self):
        driver = webdriver.Remote('http://localhost:4723/wd/hub', self.real_device_caps)
        button = driver.find_element('id', 'com.example.app:id/startButton')
        button.click()
        self.assertTrue(button.is_enabled())
        driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 10 Steps
StepActionSystem StateAssertionResult
1Test starts for emulator setupAppium server running, emulator device ready-PASS
2Driver connects to emulator and launches appApp is launched on emulator screen-PASS
3Finds start button by id on emulatorStart button visible on emulator app screenElement with id 'com.example.app:id/startButton' is foundPASS
4Clicks start button on emulatorButton click triggers expected UI responseButton is enabled after clickPASS
5Driver quits emulator sessionEmulator app closed-PASS
6Test starts for real device setupAppium server running, real device connected-PASS
7Driver connects to real device and launches appApp is launched on real device screen-PASS
8Finds start button by id on real deviceStart button visible on real device app screenElement with id 'com.example.app:id/startButton' is foundPASS
9Clicks start button on real deviceButton click triggers expected UI responseButton is enabled after clickPASS
10Driver quits real device sessionReal device app closed-PASS
Failure Scenario
Failing Condition: App fails to launch or button not found on device
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify on both emulator and real device?
AThat the start button is clickable and enabled
BThat the app crashes on launch
CThat the device battery is full
DThat the app icon is visible on home screen
Key Result
Always verify that your element locators are correct and that the app is fully launched before interacting with UI elements on both emulators and real devices.