0
0
Selenium Pythontesting~20 mins

Parameterize with test data in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parameterization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of parameterized test with multiple data sets
Given the following pytest test function using parameterization, what will be the output when running the test?
Selenium Python
import pytest

@pytest.mark.parametrize('input,expected', [(2, 4), (3, 9), (4, 16)])
def test_square(input, expected):
    assert input * input == expected

# What is the test result summary?
A3 tests passed
B2 tests passed, 1 failed
CAll tests failed
D1 test passed, 2 failed
Attempts:
2 left
💡 Hint
Check if the assertion matches the expected square values.
assertion
intermediate
2:00remaining
Correct assertion for parameterized Selenium test
You have a Selenium test that checks page titles for multiple URLs using parameterization. Which assertion correctly verifies the page title matches the expected title?
Selenium Python
from selenium import webdriver
import pytest

@pytest.mark.parametrize('url,expected_title', [
    ('https://example.com', 'Example Domain'),
    ('https://www.python.org', 'Welcome to Python.org')
])
def test_page_title(url, expected_title):
    driver = webdriver.Chrome()
    driver.get(url)
    # Which assertion is correct here?
    # assert ???
    driver.quit()
Aassert expected_title in driver.page_source
Bassert driver.title != expected_title
Cassert driver.title == expected_title
Dassert driver.current_url == expected_title
Attempts:
2 left
💡 Hint
Page title is accessed by driver.title property.
🔧 Debug
advanced
2:00remaining
Identify the error in parameterized Selenium test code
What error will occur when running this parameterized Selenium test code?
Selenium Python
import pytest
from selenium import webdriver

@pytest.mark.parametrize('url', ['https://example.com', 'https://python.org'])
def test_open_page(url):
    driver = webdriver.Chrome
    driver.get(url)
    assert 'Example' in driver.title
    driver.quit()
AAttributeError: 'function' object has no attribute 'get'
BNo error, test passes
CNameError: name 'driver' is not defined
DTypeError: 'WebDriver' object is not callable
Attempts:
2 left
💡 Hint
Check how the webdriver.Chrome is used.
framework
advanced
2:00remaining
Best practice for parameterizing Selenium tests with pytest fixtures
Which option shows the best way to combine pytest fixtures and parameterization for Selenium tests to reuse the browser instance efficiently?
AUse @pytest.mark.parametrize on test function and create a new driver inside each test
BUse @pytest.fixture with parameters and create driver inside fixture for each test
CCreate driver globally outside tests and parametrize tests without fixtures
DUse a session-scoped fixture to create driver once and parametrize test with @pytest.mark.parametrize
Attempts:
2 left
💡 Hint
Think about reusing browser instance to speed up tests.
🧠 Conceptual
expert
2:00remaining
Why parameterize tests in Selenium automation?
What is the main advantage of parameterizing Selenium tests with multiple data sets?
AIt makes tests run faster by parallelizing browser instances automatically
BIt reduces code duplication and allows running the same test logic with different inputs automatically
CIt ensures tests only run once with fixed data to avoid flaky results
DIt removes the need for assertions by validating all inputs implicitly
Attempts:
2 left
💡 Hint
Think about how parameterization affects test coverage and code reuse.