Device fragmentation challenges in Testing Fundamentals - Build an Automation Script
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 MainPage: def __init__(self, driver): self.driver = driver self.menu_locator = (By.ID, "main-menu") def is_menu_visible(self): return WebDriverWait(self.driver, 10).until( EC.visibility_of_element_located(self.menu_locator) ) class SettingsPage: def __init__(self, driver): self.driver = driver self.controls_locator = (By.CLASS_NAME, "settings-control") def are_controls_displayed(self): controls = WebDriverWait(self.driver, 10).until( EC.presence_of_all_elements_located(self.controls_locator) ) return all(control.is_displayed() for control in controls) def test_app_on_device(device_capabilities): driver = webdriver.Remote('http://localhost:4723/wd/hub', device_capabilities) try: main_page = MainPage(driver) assert main_page.is_menu_visible(), "Main menu is not visible" # Navigate to settings page settings_button = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.ID, "settings-button")) ) settings_button.click() settings_page = SettingsPage(driver) assert settings_page.are_controls_displayed(), "Settings controls are not all displayed" finally: driver.quit() if __name__ == "__main__": devices = [ {"platformName": "Android", "deviceName": "Android_Smartphone", "app": "/path/to/app.apk"}, {"platformName": "iOS", "deviceName": "iPad_Tablet", "app": "/path/to/app.app"}, {"platformName": "Windows", "deviceName": "Desktop", "app": "C:/path/to/app.exe"} ] for device in devices: test_app_on_device(device)
This test script uses Appium with Selenium WebDriver to automate testing on multiple devices.
The MainPage and SettingsPage classes follow the Page Object Model to keep locators and actions organized.
Explicit waits ensure elements are loaded before interacting or asserting visibility.
The test_app_on_device function runs the test steps on each device using its capabilities.
Assertions check that the main menu is visible and all settings controls are displayed, matching the manual test case expectations.
Finally, the driver quits to clean up after each test run.
Now add data-driven testing with 3 different device configurations including different OS versions and screen sizes
Practice
device fragmentation mean in software testing?Solution
Step 1: Understand device fragmentation concept
Device fragmentation means there are many different devices and operating system versions in use.Step 2: Match the meaning to options
There are many different devices and OS versions to test on correctly describes this as many devices and OS versions to test on, making testing harder.Final Answer:
There are many different devices and OS versions to test on -> Option BQuick Check:
Device fragmentation = many devices and OS versions [OK]
- Thinking fragmentation means testing on only one device
- Assuming all devices behave the same
- Confusing simulators with real device variety
Solution
Step 1: Identify best practice for device fragmentation
Testing on a mix of real devices and simulators covering popular OS versions helps catch issues across many device types.Step 2: Compare options to best practice
Use a mix of real devices and simulators covering popular OS versions matches this approach, while others ignore variety or real devices.Final Answer:
Use a mix of real devices and simulators covering popular OS versions -> Option CQuick Check:
Best practice = mix real devices + simulators [OK]
- Testing only on newest devices misses older versions
- Ignoring OS versions reduces test coverage
- Relying solely on simulators misses real device issues
devices = ['iPhone 12', 'Samsung S21', 'Pixel 6']
results = []
for device in devices:
if device == 'iPhone 12':
results.append('Pass')
else:
results.append('Fail')
print(results)What will be the output?
Solution
Step 1: Analyze the loop and condition
The loop checks each device; if it is 'iPhone 12', append 'Pass', else 'Fail'.Step 2: Evaluate each device
'iPhone 12' -> 'Pass', 'Samsung S21' -> 'Fail', 'Pixel 6' -> 'Fail'. So results = ['Pass', 'Fail', 'Fail'].Final Answer:
['Pass', 'Fail', 'Fail'] -> Option AQuick Check:
Only iPhone 12 passes, others fail [OK]
- Assuming all devices pass
- Mixing up Pass and Fail logic
- Ignoring the else condition
devices = ['iPhone 11', 'Galaxy S20', 'Pixel 5']
for i in range(len(devices)):
print(devices[i+1])What error will occur when running this code?
Solution
Step 1: Understand the loop and indexing
The loop runs from i=0 to i=2 (length 3). The code tries to access devices[i+1].Step 2: Identify when index goes out of range
When i=2, devices[3] is accessed, which is out of range, causing IndexError.Final Answer:
IndexError: list index out of range -> Option AQuick Check:
Accessing devices[i+1] at last index causes IndexError [OK]
- Thinking code runs without error
- Confusing IndexError with SyntaxError
- Ignoring loop range and indexing
Solution
Step 1: Understand resource constraints and coverage needs
Testing every device is impossible; testing only latest devices misses many users.Step 2: Choose balanced approach
Test on popular devices from both OS families plus simulators for older versions tests popular devices plus simulators for older OS versions, balancing coverage and resources effectively.Final Answer:
Test on popular devices from both OS families plus simulators for older versions -> Option DQuick Check:
Balanced test strategy = popular devices + simulators [OK]
- Trying to test every device wastes resources
- Testing only newest devices misses many users
- Relying solely on simulators misses real device issues
Ready to prove it?
Pass the test and this pattern moves unknown
