0
0
Testing Fundamentalstesting~15 mins

Mobile testing types in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Verify mobile app launches and displays home screen
Preconditions (3)
Step 1: Launch the mobile app on the device
Step 2: Wait for the home screen to load
Step 3: Verify the home screen title is visible
Step 4: Verify the main menu button is present
Step 5: Close the app
✅ Expected Result: The app launches successfully, home screen title and main menu button are visible, and app closes without errors
Automation Requirements - Appium with Python unittest
Assertions Needed:
Home screen title is displayed
Main menu button is present
Best Practices:
Use explicit waits to wait for elements
Use accessibility IDs or resource IDs for locating elements
Close the app session properly after test
Automated Solution
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 MobileAppLaunchTest(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)
        self.wait = WebDriverWait(self.driver, 10)

    def test_home_screen_display(self):
        # Wait for home screen title to be visible
        home_title = self.wait.until(
            EC.visibility_of_element_located((By.ACCESSIBILITY_ID, "home_screen_title"))
        )
        self.assertTrue(home_title.is_displayed(), "Home screen title should be visible")

        # Verify main menu button is present
        main_menu_btn = self.wait.until(
            EC.presence_of_element_located((By.ACCESSIBILITY_ID, "main_menu_button"))
        )
        self.assertIsNotNone(main_menu_btn, "Main menu button should be present")

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

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

This test script uses Appium with Python's unittest framework to automate a mobile app launch test.

setUp(): Sets desired capabilities for Android emulator and app details, then starts the Appium driver and a wait helper.

test_home_screen_display(): Waits explicitly for the home screen title to appear using accessibility ID, asserts it is visible, then waits for the main menu button and asserts it is present.

tearDown(): Closes the app session properly after the test.

This approach uses explicit waits to avoid timing issues and uses accessibility IDs for reliable element location, following best practices for mobile test automation.

Common Mistakes - 3 Pitfalls
Using hardcoded sleep delays instead of explicit waits
Locating elements by fragile XPath expressions
Not closing the app session after test
Bonus Challenge

Now add data-driven testing with 3 different app activities to verify their launch

Show Hint