Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import pytest for fixture usage.
Selenium Python
import [1] @pytest.fixture def browser(): pass
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unittest instead of pytest.
Importing selenium instead of pytest.
✗ Incorrect
We use pytest to create fixtures for tests.
2fill in blank
mediumComplete the fixture to initialize a Chrome WebDriver.
Selenium Python
from selenium import webdriver @pytest.fixture def browser(): driver = webdriver.[1]() yield driver driver.quit()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using webdriver.Firefox() when Chrome is required.
Forgetting to quit the driver after tests.
✗ Incorrect
webdriver.Chrome() initializes a Chrome browser instance.
3fill in blank
hardFix the error in the fixture to properly yield the driver.
Selenium Python
@pytest.fixture def browser(): driver = webdriver.Chrome() [1] driver driver.quit()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using return instead of yield causes driver.quit() to never run.
Using pass or print does not provide the driver to tests.
✗ Incorrect
Yield pauses the fixture to allow test use, then continues to quit driver.
4fill in blank
hardFill both blanks to create a fixture that sets an implicit wait and maximizes the window.
Selenium Python
@pytest.fixture def browser(): driver = webdriver.Chrome() driver.[1](10) driver.[2]() yield driver driver.quit()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using get() instead of maximize_window() to resize window.
Using close() instead of quit() to end session.
✗ Incorrect
implicitly_wait(10) sets wait time; maximize_window() enlarges the browser window.
5fill in blank
hardFill all three blanks to create a fixture that opens a URL, waits implicitly, and maximizes the window.
Selenium Python
@pytest.fixture def browser(): driver = webdriver.Chrome() driver.[1]('https://example.com') driver.[2](5) driver.[3]() yield driver driver.quit()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using refresh() instead of get() to open URL.
Forgetting to yield the driver before quitting.
✗ Incorrect
get() opens URL; implicitly_wait(5) sets wait; maximize_window() enlarges window.