0
0
Testing Fundamentalstesting~15 mins

Why mobile testing addresses unique challenges in Testing Fundamentals - Automation Benefits in Action

Choose your learning style9 modes available
Verify mobile app login functionality on different devices
Preconditions (3)
Step 1: Open the mobile app on the device
Step 2: Enter valid username 'testuser' in the username field
Step 3: Enter valid password 'Test@1234' in the password field
Step 4: Tap the login button
Step 5: Wait for the home screen to load
✅ Expected Result: User is successfully logged in and home screen is displayed without UI glitches or crashes
Automation Requirements - Appium with Python
Assertions Needed:
Verify login button is clickable
Verify home screen is displayed after login
Verify no error messages are shown
Verify UI elements are properly visible and not overlapping
Best Practices:
Use explicit waits to handle app loading times
Use accessibility IDs or resource IDs for element locators
Run tests on multiple device emulators or real devices
Handle different screen sizes and orientations
Automated Solution
Testing Fundamentals
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
import unittest

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

    def test_login(self):
        # Wait for username field and enter username
        username_field = self.wait.until(EC.element_to_be_clickable((By.ACCESSIBILITY_ID, 'username_input')))
        username_field.send_keys('testuser')

        # Wait for password field and enter password
        password_field = self.wait.until(EC.element_to_be_clickable((By.ACCESSIBILITY_ID, 'password_input')))
        password_field.send_keys('Test@1234')

        # Wait for login button and tap
        login_button = self.wait.until(EC.element_to_be_clickable((By.ACCESSIBILITY_ID, 'login_button')))
        login_button.click()

        # Wait for home screen element to verify login success
        home_screen_element = self.wait.until(EC.presence_of_element_located((By.ACCESSIBILITY_ID, 'home_screen')))
        self.assertTrue(home_screen_element.is_displayed(), 'Home screen is not displayed')

        # Verify no error message is shown
        error_elements = self.driver.find_elements(By.ACCESSIBILITY_ID, 'error_message')
        self.assertEqual(len(error_elements), 0, 'Error message displayed after login')

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

if __name__ == '__main__':
    unittest.main()

This test script uses Appium with Python to automate the mobile app login test.

setUp() initializes the Appium driver with desired capabilities for an Android emulator.

In test_login(), explicit waits ensure elements are ready before interacting, which handles app loading delays.

We locate elements by accessibility IDs, which are stable and recommended for mobile testing.

Assertions check that the home screen appears and no error messages are shown, confirming successful login.

tearDown() closes the app session after the test.

This approach addresses mobile testing challenges like varying load times, different screen sizes, and UI stability.

Common Mistakes - 3 Pitfalls
Using Thread.sleep() instead of explicit waits
Using XPath locators with long absolute paths
Not handling different screen sizes or orientations
Bonus Challenge

Now add data-driven testing with 3 different sets of login credentials (valid and invalid).

Show Hint