A parameterized test runs the same test code multiple times with different input values. It helps check many cases without writing separate tests for each.
Click to reveal answer
beginner
Why use parameterized tests in Selenium with Python?
They save time by reusing test code for different inputs, making tests easier to maintain and cover more scenarios efficiently.
Click to reveal answer
beginner
Which Python library is commonly used for parameterized tests with Selenium?
The 'pytest' library with the '@pytest.mark.parametrize' decorator is commonly used to create parameterized tests in Selenium Python.
Click to reveal answer
intermediate
How do you define multiple test inputs using '@pytest.mark.parametrize'?
You list the parameter names as a string, then provide a list of tuples with values for each test run. Example: @pytest.mark.parametrize('input,expected', [(1,2), (3,4)])
Click to reveal answer
intermediate
What is a key benefit of parameterized tests for test reports?
Each input set runs as a separate test case, so reports show which inputs passed or failed clearly, helping find issues faster.
Click to reveal answer
What does a parameterized test do?
ARuns the same test with different inputs
BRuns different tests with the same input
CRuns tests only once
DRuns tests without any inputs
✗ Incorrect
A parameterized test runs the same test code multiple times with different inputs.
Which decorator is used in pytest for parameterized tests?
A@pytest.inputdata
B@pytest.mark.parametrize
C@pytest.testcase
D@pytest.run
✗ Incorrect
The '@pytest.mark.parametrize' decorator is used to define parameterized tests in pytest.
What is the format to provide multiple inputs in '@pytest.mark.parametrize'?
AA list of tuples with values
BA dictionary of inputs
CA single string with values
DA set of integers
✗ Incorrect
You provide a list of tuples, each tuple containing values for one test run.
Why are parameterized tests helpful in Selenium testing?
AThey require writing many test functions
BThey make tests run slower
CThey reduce code duplication and test many inputs easily
DThey only test one input
✗ Incorrect
Parameterized tests reduce code duplication and allow testing many inputs efficiently.
How does test reporting benefit from parameterized tests?
AHides input details
BDoes not show test results
CMerges all inputs into one result
DShows results for each input separately
✗ Incorrect
Each input runs as a separate test case, so reports show pass/fail per input clearly.
Explain how to create a parameterized test in Selenium Python using pytest.
Think about how pytest runs the same test with different inputs.
You got /4 concepts.
Describe the advantages of using parameterized tests in automated UI testing.
Consider how testing many inputs helps find bugs faster.
You got /4 concepts.
Practice
(1/5)
1. What is the main benefit of using @pytest.mark.parametrize in Selenium Python tests?
easy
A. It allows running the same test with multiple sets of data easily.
B. It speeds up the browser loading time.
C. It automatically finds locators on the page.
D. It generates test reports without extra code.
Solution
Step 1: Understand the purpose of parameterized tests
Parameterized tests run the same test logic multiple times with different input data sets.
Step 2: Identify what @pytest.mark.parametrize does
This decorator allows easy setup of multiple data inputs for one test function, reducing repeated code.
Final Answer:
It allows running the same test with multiple sets of data easily. -> Option A
Quick Check:
Parameterized tests = multiple data sets [OK]
Hint: Think: same test, many inputs, less code [OK]
Common Mistakes:
Confusing parameterization with browser speed optimization
Thinking it auto-finds locators
Assuming it auto-generates reports
2. Which of the following is the correct syntax to parameterize a test function with two parameters username and password using pytest?
easy
A. @pytest.mark.param('username', 'password', [('user1', 'pass1'), ('user2', 'pass2')])
B. @pytest.parametrize(['username', 'password'], [('user1', 'pass1'), ('user2', 'pass2')])
C. @pytest.mark.parametrize(('username', 'password'), ['user1', 'pass1', 'user2', 'pass2'])
D. @pytest.mark.parametrize('username, password', [('user1', 'pass1'), ('user2', 'pass2')])
Solution
Step 1: Recall pytest parameterize syntax
The correct syntax uses @pytest.mark.parametrize with a string of comma-separated parameter names and a list of tuples for values.
Step 2: Compare options
@pytest.mark.parametrize('username, password', [('user1', 'pass1'), ('user2', 'pass2')]) matches the correct syntax exactly. Others have wrong decorator names or wrong argument formats.
Final Answer:
@pytest.mark.parametrize('username, password', [('user1', 'pass1'), ('user2', 'pass2')]) -> Option D
Quick Check:
Correct decorator and tuple list = @pytest.mark.parametrize('username, password', [('user1', 'pass1'), ('user2', 'pass2')]) [OK]
Hint: Remember: mark.parametrize with string params and list of tuples [OK]
Common Mistakes:
Misspelling 'parametrize' as 'parametrize' or 'param'
Using list instead of tuple for parameter values
Passing parameters as list instead of string
3. What will be the output when running this parameterized test snippet?
B. Missing data list for parameterize decorator on test_double.
C. Parameters names should be a list, not a string.
D. Test function name is invalid.
Solution
Step 1: Check the decorator usage on test_double
The decorator @pytest.mark.parametrize('input, expected') is missing the second argument: the list of data tuples.
Step 2: Verify other parts
Assertion and function name are correct. Parameter names as string is valid syntax.
Final Answer:
Missing data list for parameterize decorator on test_double. -> Option B
Quick Check:
Decorator needs data list argument [OK]
Hint: Always provide data list with parametrize decorator [OK]
Common Mistakes:
Forgetting the data list argument
Using list instead of string for parameter names (which is allowed but less common)
Misreading assertion syntax
5. You want to test a login form with multiple username and password pairs using Selenium and pytest parameterization. Which approach correctly combines parameterized tests with Selenium WebDriver to test login functionality?
hard
A. Use @pytest.mark.parametrize to pass username and password, then inside the test open the browser, fill fields, submit, and assert login success.
B. Write separate test functions for each username and password pair without parameterization.
C. Use parameterization only for URLs, not for form inputs like username and password.
D. Use @pytest.mark.parametrize but do not open the browser inside the test function.
Solution
Step 1: Understand parameterized test purpose in Selenium context
Parameterized tests allow running the same test logic with different input data, such as username and password pairs.
Step 2: Combine parameterization with Selenium actions
Inside the test function, open the browser, fill the login form with parameters, submit, and check results. This is the correct approach.
Final Answer:
Use @pytest.mark.parametrize to pass username and password, then inside the test open the browser, fill fields, submit, and assert login success. -> Option A
Quick Check:
Parameterize inputs + Selenium actions inside test [OK]
Hint: Parameterize inputs, then automate browser steps inside test [OK]
Common Mistakes:
Writing separate tests instead of parameterizing
Not opening browser inside test function
Limiting parameterization to URLs only
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.