0
0
Testing Fundamentalstesting~10 mins

Device fragmentation challenges in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Selenium
Testing Fundamentals
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()
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opens with simulated device window size and user agentBrowser window size set to 375x667 pixels, user agent mimics iPhone OS 13.6-PASS
2Browser navigates to https://example.com/mobile-appMobile version of the app page loads-PASS
3Waits for element with ID 'start-button' to be presentStart button is found on the pageElement 'start-button' is presentPASS
4Checks if 'start-button' is visible and enabledButton is visible and clickablebutton.is_displayed() == True and button.is_enabled() == TruePASS
5Clicks the 'start-button'Button click triggers navigation or modal-PASS
6Waits for element with ID 'welcome-message' to appearWelcome message is displayed after button clickElement 'welcome-message' is present and visiblePASS
7Test ends and browser closesBrowser window closed-PASS
Failure Scenario
Failing Condition: The 'start-button' element is not found or not clickable on the simulated device
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the 'start-button' on the simulated device?
AThat the button is disabled
BThat the button is visible and clickable
CThat the button is hidden
DThat the button changes color
Key Result
Simulating different devices by adjusting window size and user agent helps catch issues caused by device fragmentation early in testing.