0
0
Selenium Pythontesting~20 mins

Data providers pattern in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Data Provider Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of test execution with data provider
Given the following Selenium test code using a data provider pattern, what will be the output when running the test?
Selenium Python
import unittest
from parameterized import parameterized

class TestLogin(unittest.TestCase):

    @parameterized.expand([
        ("user1", "pass1"),
        ("user2", "pass2"),
        ("user3", "pass3")
    ])
    def test_login(self, username, password):
        print(f"Testing login with {username} and {password}")
        self.assertTrue(len(username) > 0)
        self.assertTrue(len(password) > 0)

if __name__ == '__main__':
    unittest.main()
AThree tests run, but all fail due to assertion error
BOne test runs, printing 'Testing login with user1 and pass1', passes
CThree tests run, each printing 'Testing login with userX and passX', all pass
DTest fails to run due to missing data provider decorator
Attempts:
2 left
💡 Hint
Look at how many parameter sets are provided to the @parameterized.expand decorator.
assertion
intermediate
1:30remaining
Correct assertion for data-driven test
In a data-driven Selenium test, which assertion correctly verifies that the page title contains the expected keyword for each data set?
Selenium Python
def test_page_title(self, keyword):
    title = self.driver.title
    # Which assertion is correct here?
Aself.assertFalse(keyword in title)
Bself.assertIn(keyword, title)
Cself.assertEqual(keyword, title)
Dself.assertTrue(title.startswith(keyword))
Attempts:
2 left
💡 Hint
We want to check if the keyword appears anywhere in the title.
locator
advanced
1:30remaining
Best locator strategy for data-driven tests
In a data-driven Selenium test, you need to locate a button whose text changes based on test data. Which locator strategy is best to use?
ALocate by XPath using contains(text(), variable_text)
BLocate by fixed ID attribute
CLocate by CSS class name
DLocate by tag name only
Attempts:
2 left
💡 Hint
The button text changes per test data, so the locator must adapt dynamically.
🔧 Debug
advanced
2:00remaining
Debugging failing data-driven test
A data-driven Selenium test fails intermittently with a NoSuchElementException on a locator that worked before. What is the most likely cause?
AThe page content changes based on test data, so the element is missing for some inputs
BThe locator syntax is invalid and causes a runtime error
CThe test data provider is empty, so no tests run
DThe browser driver is not installed
Attempts:
2 left
💡 Hint
Think about how test data can affect page elements.
framework
expert
2:00remaining
Implementing data providers in pytest for Selenium
Which pytest feature allows you to implement data providers for Selenium tests to run the same test with multiple data sets?
Aunittest.TestCase subclass with setUp method
BUsing Selenium WebDriverWait explicitly
Cpytest.fixture with scope='module'
D@pytest.mark.parametrize decorator
Attempts:
2 left
💡 Hint
Look for a pytest decorator that runs tests multiple times with different inputs.