Challenge - 5 Problems
Data Provider Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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()
Attempts:
2 left
💡 Hint
Look at how many parameter sets are provided to the @parameterized.expand decorator.
✗ Incorrect
The @parameterized.expand decorator runs the test method once for each tuple in the list. Each test prints the username and password and asserts their length is greater than zero, so all pass.
❓ assertion
intermediate1: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?
Attempts:
2 left
💡 Hint
We want to check if the keyword appears anywhere in the title.
✗ Incorrect
assertIn checks if the keyword is part of the title string, which is the intended verification. assertEqual would require exact match, which is too strict.
❓ locator
advanced1: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?
Attempts:
2 left
💡 Hint
The button text changes per test data, so the locator must adapt dynamically.
✗ Incorrect
Using XPath with contains(text(), variable_text) allows locating elements based on dynamic text content, which fits data-driven tests where text varies.
🔧 Debug
advanced2: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?
Attempts:
2 left
💡 Hint
Think about how test data can affect page elements.
✗ Incorrect
If the page changes depending on input data, some elements may not appear, causing NoSuchElementException only for certain data sets.
❓ framework
expert2: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?
Attempts:
2 left
💡 Hint
Look for a pytest decorator that runs tests multiple times with different inputs.
✗ Incorrect
The @pytest.mark.parametrize decorator runs a test function multiple times with different argument values, acting as a data provider.