Recall & Review
beginner
What does it mean to parameterize tests with test data?
Parameterizing tests means running the same test multiple times with different input values. This helps check how the software behaves with various data without writing separate tests for each case.
Click to reveal answer
beginner
Why is parameterizing tests useful in Selenium testing?
It saves time by reusing the same test code for many inputs. It also helps find bugs that only appear with certain data, making tests more thorough and efficient.
Click to reveal answer
intermediate
How can you parameterize tests in Python using pytest?
You can use the @pytest.mark.parametrize decorator to pass a list of input values to a test function. The test runs once for each set of inputs automatically.
Click to reveal answer
intermediate
Show a simple example of parameterizing a Selenium test with pytest.
Example:
import pytest
from selenium.webdriver.common.by import By
@pytest.mark.parametrize('username,password', [
('user1', 'pass1'),
('user2', 'pass2')
])
def test_login(driver, username, password):
driver.get('http://example.com/login')
driver.find_element(By.ID, 'user').send_keys(username)
driver.find_element(By.ID, 'pass').send_keys(password)
driver.find_element(By.ID, 'submit').click()
assert 'Welcome' in driver.page_sourceClick to reveal answer
intermediate
What are best practices when choosing test data for parameterized tests?
Choose data that covers normal cases, edge cases, and invalid inputs. This ensures the software is tested well and can handle different situations gracefully.
Click to reveal answer
What is the main benefit of parameterizing tests?
✗ Incorrect
Parameterizing tests allows running the same test multiple times with different inputs without rewriting the test.
Which Python decorator is commonly used to parameterize tests in pytest?
✗ Incorrect
The @pytest.mark.parametrize decorator is used to pass multiple sets of data to a test function.
In Selenium tests, what should you do after entering parameterized input data?
✗ Incorrect
After entering input data, you perform the action (like clicking submit) to test the behavior with that data.
Which of these is NOT a good type of test data to include when parameterizing?
✗ Incorrect
Using only one fixed input defeats the purpose of parameterization, which is to test multiple data cases.
What happens if an assertion fails in one parameterized test case?
✗ Incorrect
In parameterized tests, each input set runs as a separate test case. Failure in one does not stop others.
Explain how to use pytest to parameterize a Selenium test with multiple username and password pairs.
Think about how to repeat the same test with different inputs automatically.
You got /4 concepts.
Describe why parameterizing tests improves test coverage and efficiency.
Consider how testing many cases helps find more issues without extra work.
You got /4 concepts.