0
0
Testing Fundamentalstesting~10 mins

Mobile-specific test cases in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if a mobile app's login screen works correctly on a smartphone. It verifies that the app opens, the login fields are visible, the user can enter credentials, and the login button works to access the home screen.

Test Code - Appium with unittest
Testing Fundamentals
import unittest
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class MobileLoginTest(unittest.TestCase):
    def setUp(self):
        desired_caps = {
            "platformName": "Android",
            "deviceName": "Android Emulator",
            "appPackage": "com.example.myapp",
            "appActivity": ".MainActivity",
            "automationName": "UiAutomator2"
        }
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def test_login_functionality(self):
        wait = WebDriverWait(self.driver, 10)
        # Wait for username field
        username_field = wait.until(EC.presence_of_element_located((By.ID, "com.example.myapp:id/username")))
        self.assertTrue(username_field.is_displayed())
        username_field.send_keys("testuser")

        # Wait for password field
        password_field = wait.until(EC.presence_of_element_located((By.ID, "com.example.myapp:id/password")))
        self.assertTrue(password_field.is_displayed())
        password_field.send_keys("password123")

        # Wait for login button and click
        login_button = wait.until(EC.element_to_be_clickable((By.ID, "com.example.myapp:id/login_button")))
        login_button.click()

        # Verify home screen loaded by checking welcome message
        welcome_msg = wait.until(EC.presence_of_element_located((By.ID, "com.example.myapp:id/welcome_message")))
        self.assertIn("Welcome", welcome_msg.text)

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 9 Steps
StepActionSystem StateAssertionResult
1Test starts and Appium driver launches the Android app on emulatorAndroid emulator opens with the app's main activity visible-PASS
2Waits for username input field to appearLogin screen shows username fieldCheck username field is displayedPASS
3Enters 'testuser' into username fieldUsername field contains 'testuser'-PASS
4Waits for password input field to appearLogin screen shows password fieldCheck password field is displayedPASS
5Enters 'password123' into password fieldPassword field contains 'password123'-PASS
6Waits for login button to be clickableLogin button is visible and enabledCheck login button is clickablePASS
7Clicks the login buttonApp navigates to home screen-PASS
8Waits for welcome message on home screenHome screen shows welcome messageVerify welcome message text contains 'Welcome'PASS
9Test ends and Appium driver quitsApp closed, emulator ready for next test-PASS
Failure Scenario
Failing Condition: Login button is not found or not clickable within 10 seconds
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThe username field is cleared
BThe home screen shows a welcome message
CThe app closes automatically
DThe password field becomes hidden
Key Result
Always wait explicitly for mobile app elements to appear or become clickable before interacting to avoid flaky tests caused by slow loading or animations.