0
0
Testing Fundamentalstesting~15 mins

Mobile-specific test cases in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Verify login functionality on mobile app
Preconditions (2)
Step 1: Launch the mobile app
Step 2: Enter 'testuser' in the username field
Step 3: Enter '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
Automation Requirements - Appium with Python
Assertions Needed:
Verify the home screen element is visible after login
Verify no error message is displayed
Best Practices:
Use explicit waits to wait for elements
Use accessibility ids or resource ids for locating elements
Handle mobile-specific gestures if needed
Keep test steps clear and simple
Automated Solution
Testing Fundamentals
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

caps = {
    "platformName": "Android",
    "deviceName": "Android Emulator",
    "appPackage": "com.example.mobileapp",
    "appActivity": ".MainActivity",
    "automationName": "UiAutomator2"
}

# Connect to Appium server
driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)

try:
    wait = WebDriverWait(driver, 10)

    # Wait for username field and enter username
    username_field = wait.until(EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, "username_input")))
    username_field.send_keys("testuser")

    # Enter password
    password_field = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "password_input")
    password_field.send_keys("Test@1234")

    # Tap login button
    login_button = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "login_button")
    login_button.click()

    # Wait for home screen element
    home_screen_element = wait.until(EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, "home_screen")))

    # Assert home screen is displayed
    assert home_screen_element.is_displayed(), "Home screen is not displayed after login"

    # Assert no error message
    error_elements = driver.find_elements(AppiumBy.ACCESSIBILITY_ID, "login_error")
    assert len(error_elements) == 0, "Error message displayed after login"

finally:
    driver.quit()

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

We set capabilities to connect to an Android emulator and specify the app package and activity.

We use explicit waits to wait for the username field to appear before interacting.

We locate elements by accessibility id, which is a best practice for mobile apps.

After entering credentials and tapping login, we wait for the home screen element to confirm successful login.

Assertions check that the home screen is visible and no error message is shown.

Finally, the driver quits to close the session.

Common Mistakes - 3 Pitfalls
Using Thread.sleep instead of explicit waits
Using XPath locators that are too long or brittle
Not quitting the driver session after test
Bonus Challenge

Now add data-driven testing with 3 different username and password combinations

Show Hint