Bird
0
0

You want to test a login form with multiple username and password pairs using parameterized tests. Which approach correctly applies this?

hard📝 Application Q8 of 15
Selenium Python - Test Framework Integration (pytest)
You want to test a login form with multiple username and password pairs using parameterized tests. Which approach correctly applies this?
A@pytest.mark.parametrize('username,password', [('user1','pass1'), ('user2','pass2')])
B@pytest.mark.parametrize(['username', 'password'], ['user1', 'pass1', 'user2', 'pass2'])
C@pytest.mark.parametrize('username,password', ['user1:pass1', 'user2:pass2'])
D@pytest.mark.parametrize('username', ['user1', 'user2']) @pytest.mark.parametrize('password', ['pass1', 'pass2'])
Step-by-Step Solution
Solution:
  1. Step 1: Understand parameter pairing

    To test username and password pairs, use a list of tuples with both values together.
  2. Step 2: Evaluate each option

    @pytest.mark.parametrize('username,password', [('user1','pass1'), ('user2','pass2')]) correctly pairs usernames and passwords. @pytest.mark.parametrize(['username', 'password'], ['user1', 'pass1', 'user2', 'pass2']) uses wrong parameter format. @pytest.mark.parametrize('username,password', ['user1:pass1', 'user2:pass2']) uses strings with colon, not tuples. @pytest.mark.parametrize('username', ['user1', 'user2']) @pytest.mark.parametrize('password', ['pass1', 'pass2']) creates Cartesian product, not pairs.
  3. Final Answer:

    @pytest.mark.parametrize('username,password', [('user1','pass1'), ('user2','pass2')]) -> Option A
  4. Quick Check:

    Use list of tuples for paired parameters [OK]
Quick Trick: Pair parameters as tuples in list for related inputs [OK]
Common Mistakes:
  • Passing separate lists for paired parameters
  • Using strings instead of tuples for pairs
  • Creating Cartesian product unintentionally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes