0
0
Selenium Pythontesting~5 mins

Conftest for shared fixtures in Selenium Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of a conftest.py file in pytest?
The conftest.py file is used to define shared fixtures and hooks that can be used across multiple test files without importing them explicitly.
Click to reveal answer
beginner
How do you define a fixture in conftest.py for Selenium WebDriver?
You define a function with the @pytest.fixture decorator that initializes the WebDriver, yields it for use in tests, and then quits the driver after tests finish.
Click to reveal answer
beginner
Why is it better to put Selenium WebDriver setup in conftest.py instead of each test file?
Putting WebDriver setup in conftest.py avoids repeating code, makes tests cleaner, and ensures consistent setup and teardown across all tests.
Click to reveal answer
intermediate
What does the scope parameter in a pytest fixture control?
The scope parameter controls how often the fixture is invoked. For example, scope='function' runs before each test, scope='session' runs once per test session.
Click to reveal answer
beginner
How can you use a fixture from conftest.py in your test function?
Simply add the fixture name as a parameter to your test function. Pytest will automatically find and inject the fixture from conftest.py.
Click to reveal answer
What is the main benefit of using conftest.py for fixtures?
ATo run tests in parallel automatically
BTo write test cases faster
CTo avoid using Selenium WebDriver
DTo share fixtures across multiple test files without imports
Which decorator is used to define a fixture in pytest?
A@pytest.test
B@pytest.fixture
C@pytest.setup
D@pytest.driver
If you want a Selenium WebDriver fixture to run once per test session, which scope should you use?
Afunction
Bmodule
Csession
Dclass
How do you ensure the WebDriver quits after a test using a fixture?
AUse yield in the fixture and call driver.quit() after yield
BCall driver.quit() inside the test
CDo nothing, it quits automatically
DUse a global variable
How do you use a fixture named browser in your test function?
AAdd <code>browser</code> as a parameter to the test function
BImport browser and call it
CCall <code>pytest.browser()</code>
DUse <code>self.browser</code> inside the test
Explain how to create and use a Selenium WebDriver fixture in conftest.py.
Think about setup and teardown using yield.
You got /5 concepts.
    Describe the benefits of using conftest.py for shared fixtures in Selenium testing.
    Consider how shared setup helps in many tests.
    You got /5 concepts.