Test Overview
This test simulates checking a mobile app on different devices to verify it works well despite device fragmentation. It verifies the app loads and a key button is clickable on various screen sizes and OS versions.
This test simulates checking a mobile app on different devices to verify it works well despite device fragmentation. It verifies the app loads and a key button is clickable on various screen sizes and OS versions.
from selenium 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 TestAppOnDevices(unittest.TestCase): def setUp(self): # Simulate device by setting window size and user agent options = webdriver.ChromeOptions() # Example: simulate a small screen device options.add_argument('--window-size=375,667') # iPhone 8 size options.add_argument('--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Mobile/15E148 Safari/604.1') self.driver = webdriver.Chrome(options=options) def test_button_clickable_on_device(self): driver = self.driver driver.get('https://example.com/mobile-app') # Wait for the main button to be present wait = WebDriverWait(driver, 10) button = wait.until(EC.presence_of_element_located((By.ID, 'start-button'))) # Check if button is displayed and enabled self.assertTrue(button.is_displayed(), 'Button should be visible') self.assertTrue(button.is_enabled(), 'Button should be clickable') # Click the button button.click() # Verify next page or modal appears success_message = wait.until(EC.presence_of_element_located((By.ID, 'welcome-message'))) self.assertTrue(success_message.is_displayed(), 'Welcome message should appear after click') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens with simulated device window size and user agent | Browser window size set to 375x667 pixels, user agent mimics iPhone OS 13.6 | - | PASS |
| 2 | Browser navigates to https://example.com/mobile-app | Mobile version of the app page loads | - | PASS |
| 3 | Waits for element with ID 'start-button' to be present | Start button is found on the page | Element 'start-button' is present | PASS |
| 4 | Checks if 'start-button' is visible and enabled | Button is visible and clickable | button.is_displayed() == True and button.is_enabled() == True | PASS |
| 5 | Clicks the 'start-button' | Button click triggers navigation or modal | - | PASS |
| 6 | Waits for element with ID 'welcome-message' to appear | Welcome message is displayed after button click | Element 'welcome-message' is present and visible | PASS |
| 7 | Test ends and browser closes | Browser window closed | - | PASS |