Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a test function using pytest.
Selenium Python
def [1](): assert 2 + 2 == 4
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the function without 'test_' prefix so pytest ignores it.
Using spaces or special characters in the function name.
✗ Incorrect
The test function must start with test_ so pytest can recognize it.
2fill in blank
mediumComplete the code to import the Selenium WebDriver for Chrome.
Selenium Python
from selenium.webdriver import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Firefox or other browsers when Chrome is needed.
Misspelling the browser name.
✗ Incorrect
To automate Chrome browser, import Chrome from selenium.webdriver.
3fill in blank
hardFix the error in the test class definition for pytest.
Selenium Python
class [1]: def test_example(self): assert True
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or names not starting with 'Test' for test classes.
Forgetting to capitalize the class name properly.
✗ Incorrect
Pytest recognizes test classes only if their names start with Test.
4fill in blank
hardFill both blanks to create a Selenium test that opens a page and checks the title.
Selenium Python
from selenium import webdriver class TestPageTitle: def test_title(self): driver = webdriver.[1]() driver.get('https://example.com') assert driver.title [2] 'Example Domain' driver.quit()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Firefox WebDriver when Chrome is intended.
Using '!=' instead of '==' in the assertion.
✗ Incorrect
Use webdriver.Chrome() to open Chrome and == to assert the title matches exactly.
5fill in blank
hardFill all three blanks to create a pytest test function that finds an element by ID and asserts its text.
Selenium Python
from selenium import webdriver from selenium.webdriver.common.by import [1] def test_element_text(): driver = webdriver.Chrome() driver.get('https://example.com') element = driver.find_element([2], 'example-id') assert element.text [3] 'Example Domain' driver.quit()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not importing 'By' and trying to use it directly.
Using wrong locator like 'By.NAME' instead of 'By.ID'.
Using '!=' instead of '==' in assertion.
✗ Incorrect
Import By to specify locator type, use By.ID to find by ID, and == to assert text equality.