Challenge - 5 Problems
Selenium Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple Selenium test function
What will be the test result when running this Selenium test function using pytest?
Selenium Python
from selenium import webdriver from selenium.webdriver.common.by import By def test_google_title(): driver = webdriver.Chrome() driver.get('https://www.google.com') title = driver.title driver.quit() assert 'Google' in title
Attempts:
2 left
💡 Hint
Think about what driver.title returns after loading the page.
✗ Incorrect
The test opens Google's homepage, gets the title which contains 'Google', then asserts this condition. The driver.quit() is called after getting the title, so it does not affect the assertion.
❓ assertion
intermediate1:30remaining
Correct assertion for checking element text
Which assertion correctly verifies that a web element's text is exactly 'Submit' in a Selenium test?
Selenium Python
element = driver.find_element(By.ID, 'submit-btn')
text = element.textAttempts:
2 left
💡 Hint
Use the equality operator to check exact match.
✗ Incorrect
The assertion 'assert text == 'Submit'' checks that the element's text exactly matches 'Submit'. Using 'in' checks for substring, '!=' is the opposite, and 'is' checks identity which is not reliable for strings.
🔧 Debug
advanced2:30remaining
Identify the error in this Selenium test class
What error will occur when running this Selenium test class with pytest?
Selenium Python
from selenium import webdriver from selenium.webdriver.common.by import By class TestLogin: def setup_method(self): self.driver = webdriver.Chrome() def teardown_method(self): self.driver.quit() def test_login(self): self.driver.get('https://example.com/login') username = self.driver.find_element(By.ID, 'username') password = self.driver.find_element(By.ID, 'password') username.send_keys('user') password.send_keys('pass') self.driver.find_element(By.ID, 'submit').click() assert 'Dashboard' in self.driver.title
Attempts:
2 left
💡 Hint
Consider what happens if the page elements are missing or IDs are incorrect.
✗ Incorrect
If the elements with IDs 'username', 'password', or 'submit' do not exist on the page, Selenium raises NoSuchElementException. The setup and teardown methods are correctly named and used.
❓ framework
advanced2:00remaining
Best practice for Selenium test class setup and teardown
Which code snippet correctly implements setup and teardown for a Selenium test class using pytest conventions?
Attempts:
2 left
💡 Hint
Pytest uses setup_method and teardown_method for per-test setup/teardown.
✗ Incorrect
Pytest recognizes setup_method and teardown_method for setup and cleanup before and after each test method. 'setup' and 'setUp' are unittest conventions, and 'before_all'/'after_all' are not pytest standard.
🧠 Conceptual
expert3:00remaining
Understanding test isolation in Selenium test classes
Why is it important to create a new WebDriver instance in the setup method before each test instead of reusing the same driver instance across multiple tests?
Attempts:
2 left
💡 Hint
Think about how leftover data or state can affect test results.
✗ Incorrect
Creating a new WebDriver instance for each test ensures tests do not affect each other by sharing browser state like cookies, cache, or session data. This isolation improves test reliability and repeatability.