Challenge - 5 Problems
Parameterized Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of parameterized Selenium test with multiple inputs
Consider this parameterized Selenium test using pytest. What will be the output when running this test suite?
Selenium Python
import pytest from selenium.webdriver.common.by import By @pytest.mark.parametrize('search_term', ['apple', 'banana']) def test_search(browser, search_term): browser.get('https://example.com') search_box = browser.find_element(By.NAME, 'q') search_box.send_keys(search_term) search_box.submit() assert search_term in browser.title
Attempts:
2 left
💡 Hint
Think about what is missing for the test to run properly with Selenium.
✗ Incorrect
The test uses a 'browser' argument but does not define a fixture or setup for it. Without a browser fixture, pytest cannot provide the 'browser' object, so the tests will fail to run.
❓ assertion
intermediate2:00remaining
Correct assertion in parameterized test for form validation
You have a parameterized test that submits a form with different inputs. Which assertion correctly verifies that the error message appears when input is invalid?
Selenium Python
import pytest from selenium.webdriver.common.by import By @pytest.mark.parametrize('input_value, expect_error', [('', True), ('valid', False)]) def test_form_validation(browser, input_value, expect_error): browser.get('https://example.com/form') input_field = browser.find_element(By.ID, 'input') input_field.clear() input_field.send_keys(input_value) submit_button = browser.find_element(By.ID, 'submit') submit_button.click() error_elements = browser.find_elements(By.CLASS_NAME, 'error') # Which assertion is correct?
Attempts:
2 left
💡 Hint
Remember that find_elements returns a list, not a single element.
✗ Incorrect
find_elements returns a list of matching elements. To check if errors appear, verify if the list length is greater than zero and compare it to the expected error presence.
❓ locator
advanced2:00remaining
Best locator strategy for parameterized test with dynamic IDs
In a parameterized test, you need to locate a button whose ID changes dynamically but always starts with 'btn_'. Which locator is best to use?
Attempts:
2 left
💡 Hint
Look for a locator that matches the start of the ID attribute.
✗ Incorrect
CSS selector with ^= matches elements whose attribute starts with a given string. This is efficient and reliable for dynamic IDs starting with 'btn_'.
🔧 Debug
advanced2:00remaining
Debugging flaky parameterized Selenium test
A parameterized Selenium test intermittently fails with 'ElementNotInteractableException' on clicking a button. What is the most likely cause?
Selenium Python
import pytest from selenium.webdriver.common.by import By @pytest.mark.parametrize('page', ['home', 'about']) def test_click_button(browser, page): browser.get(f'https://example.com/{page}') button = browser.find_element(By.ID, 'start') button.click() assert 'Started' in browser.page_source
Attempts:
2 left
💡 Hint
Consider timing and element readiness in Selenium tests.
✗ Incorrect
ElementNotInteractableException usually means the element is present but not interactable yet, often due to page loading or animations. Adding waits can fix this.
❓ framework
expert3:00remaining
Implementing parameterized tests with pytest and Selenium for multiple browsers
You want to run the same parameterized test on Chrome and Firefox browsers using pytest and Selenium. Which pytest fixture setup correctly supports this?
Attempts:
2 left
💡 Hint
Think about combining pytest parameterization with fixtures for browser setup.
✗ Incorrect
Parametrizing the browser name and using a fixture to initialize the correct WebDriver allows running the same test on multiple browsers cleanly.