Recall & Review
beginner
What is the purpose of a test function in Selenium Python?
A test function is a small piece of code that checks if a specific part of the web application works correctly. It uses Selenium commands to interact with the browser and assertions to verify expected results.
Click to reveal answer
beginner
Why do we use test classes in Selenium Python?
Test classes group related test functions together. They help organize tests, share setup and cleanup code, and make tests easier to maintain and read.
Click to reveal answer
beginner
What is the role of the setup method in a test class?
The setup method runs before each test function in the class. It prepares the environment, like opening a browser, so each test starts fresh and independent.
Click to reveal answer
beginner
How do assertions work in test functions?
Assertions check if the actual result matches the expected result. If the assertion fails, the test stops and reports a failure, helping find bugs early.
Click to reveal answer
beginner
Give an example of a simple test function using Selenium Python.
Example:
from selenium import webdriver
def test_title():
driver = webdriver.Chrome()
driver.get('https://example.com')
assert 'Example Domain' in driver.title
driver.quit()
This test opens a browser, goes to example.com, checks the page title, and closes the browser.Click to reveal answer
What does a test class help you do in Selenium Python?
✗ Incorrect
Test classes group related tests and allow sharing setup and cleanup code to keep tests organized.
Which method usually runs before each test function in a test class?
✗ Incorrect
The setup() method prepares the environment before each test runs.
What happens if an assertion fails in a test function?
✗ Incorrect
An assertion failure stops the test and reports the failure to help identify issues.
Which Selenium command opens a web page in a browser?
✗ Incorrect
driver.get(url) opens the specified web page in the browser.
Why is it important to close the browser after a test?
✗ Incorrect
Closing the browser frees resources and ensures tests do not affect each other.
Explain how you would organize multiple Selenium tests using test functions and classes.
Think about keeping tests clean and easy to manage.
You got /4 concepts.
Describe the role of assertions in test functions and what happens when they fail.
Assertions are like checkpoints in your test.
You got /4 concepts.