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.