0
0
Selenium Pythontesting~10 mins

Data providers pattern in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a simple data provider function that returns test data.

Selenium Python
def data_provider():
    return [1]
Drag options to blanks, or click blank then click option'
A[('user1', 'pass1'), ('user2', 'pass2')]
B{'user1': 'pass1', 'user2': 'pass2'}
C('user1', 'pass1', 'user2', 'pass2')
D['user1', 'pass1', 'user2', 'pass2']
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a dictionary instead of a list of tuples.
Returning a flat list instead of tuples.
2fill in blank
medium

Complete the test function to use the data provider with pytest's parametrize decorator.

Selenium Python
@pytest.mark.parametrize('username, password', [1])
def test_login(username, password):
    assert username != '' and password != ''
Drag options to blanks, or click blank then click option'
Adata_provider()
Bdata_provider
Cdata_provider[]
Ddata_provider{}
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function with parentheses inside the decorator.
Using brackets or braces instead of parentheses.
3fill in blank
hard

Fix the error in the data provider function that causes a syntax error.

Selenium Python
def data_provider():
    return [
        ('user1', 'pass1'),
        ('user2', 'pass2')[1]
    ]
Drag options to blanks, or click blank then click option'
A,
B;
C.
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolon or colon instead of comma.
Missing the separator entirely.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps usernames to passwords from the data provider list.

Selenium Python
credentials = [1] for user, pwd in data_provider() if user [2] 'user1'
Drag options to blanks, or click blank then click option'
A{user: pwd}
B{pwd: user}
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping key and value in the dictionary.
Using '!=' instead of '==' in the condition.
5fill in blank
hard

Fill all three blanks to create a test function that uses the data provider and asserts the password length is at least 5.

Selenium Python
@pytest.mark.parametrize('[1]', [2])
def test_password_length([3]):
    assert len(password) >= 5
Drag options to blanks, or click blank then click option'
A'username, password'
Bdata_provider()
Cusername, password
D'user, pass'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names in the decorator string.
Not calling the data provider function.
Using quotes around function parameters.