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.
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.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Appium driver launches the Android app on emulator | Android emulator opens with the app's main activity visible | - | PASS |
| 2 | Waits for username input field to appear | Login screen shows username field | Check username field is displayed | PASS |
| 3 | Enters 'testuser' into username field | Username field contains 'testuser' | - | PASS |
| 4 | Waits for password input field to appear | Login screen shows password field | Check password field is displayed | PASS |
| 5 | Enters 'password123' into password field | Password field contains 'password123' | - | PASS |
| 6 | Waits for login button to be clickable | Login button is visible and enabled | Check login button is clickable | PASS |
| 7 | Clicks the login button | App navigates to home screen | - | PASS |
| 8 | Waits for welcome message on home screen | Home screen shows welcome message | Verify welcome message text contains 'Welcome' | PASS |
| 9 | Test ends and Appium driver quits | App closed, emulator ready for next test | - | PASS |