Use @pytest.mark.parametrize for ordinary test inputs such as URLs and expected titles. Put browser creation and cleanup in a pytest fixture; parameterize that fixture when each case needs a different browser. Give cases readable IDs so you can identify and rerun a specific failure.
Parameterize ordinary Selenium test inputs
When the browser setup stays the same and only the test data changes, put the values directly on the test with @pytest.mark.parametrize. Keep the WebDriver in a fixture so the test receives a browser without owning its setup and teardown.
import pytest
from selenium import webdriver
@pytest.fixture
def driver():
browser = webdriver.Chrome()
yield browser
browser.quit()
@pytest.mark.parametrize(
"url, expected_title",
[
pytest.param("https://example.com/", "Example Domain", id="example"),
pytest.param("https://www.selenium.dev/", "Selenium", id="selenium-home"),
],
)
def test_page_title(driver, url, expected_title):
driver.get(url)
assert expected_title in driver.title
pytest invokes the test once for each parameter set. The example URLs and expected titles illustrate the pattern; they are not claims that these cases were tested. See the pytest parametrization guide for decorator, fixture, and dynamic approaches.
Keep parameter data safe
pytest passes parameter values as-is; it does not copy them for each test invocation. If a parameter is a list or dictionary and a test mutates it, later invocations may see that changed object. Avoid mutating shared parameters, or create fresh mutable data during fixture setup.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Multiple parametrization decorators combine into a Cartesian product. For example, two browser choices and four viewport choices produce eight combinations. Use stacked decorators only when every combination is meaningful; otherwise provide explicit case records that represent the combinations you actually need.
Parameterize the browser fixture for browser coverage
If tests should run in multiple browsers, make the fixture responsible for choosing and creating the WebDriver. Every test that requests this fixture will then run for each configured browser value.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import pytest
from selenium import webdriver
@pytest.fixture(params=["chrome", "firefox"], ids=["chrome", "firefox"])
def driver(request):
if request.param == "chrome":
browser = webdriver.Chrome()
elif request.param == "firefox":
browser = webdriver.Firefox()
else:
raise AssertionError(f"Unsupported browser: {request.param}")
yield browser
browser.quit()
def test_homepage_has_title(driver):
driver.get("https://example.com/")
assert "Example Domain" in driver.title
This is a pattern illustration, not an executed test. Adjust browser construction to the browsers and runtime your project supports. A production fixture may need browser options, environment-based configuration, or a remote WebDriver. Avoid sharing a browser session across cases unless you have deliberately designed how state is isolated.
Choose a matrix that matches the behavior
- Coverage: include the input and browser combinations needed to exercise the behavior, not every theoretical combination.
- Isolation: decide whether each case should receive a fresh browser session; reused state can make failures depend on execution order.
- Execution cost: each fixture parameter can multiply the number of browser runs, especially when combined with test parameters.
- Maintenance: use a short explicit list for fixed cases, fixture parameters for resource variants, and dynamic generation only when collection rules genuinely depend on configuration.
Use indirect parametrization when input configures a fixture
Use indirect=True when a test parameter is configuration for a fixture rather than a value the test should receive directly. pytest passes that parameter to the fixture as request.param, allowing setup to happen when the test runs instead of while pytest collects cases.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
import pytest
from selenium import webdriver
@pytest.fixture
def driver(request):
browser_name = request.param
if browser_name == "chrome":
browser = webdriver.Chrome()
elif browser_name == "firefox":
browser = webdriver.Firefox()
else:
raise ValueError(f"Unsupported browser: {browser_name}")
yield browser
browser.quit()
@pytest.mark.parametrize("driver", ["chrome", "firefox"], indirect=True, ids=["chrome", "firefox"])
def test_homepage_title(driver):
driver.get("https://example.com/")
assert "Example Domain" in driver.title
For mixed cases, selectively mark only the fixture-configuring argument as indirect: @pytest.mark.parametrize("driver, url", [("chrome", "https://example.com/")], indirect=["driver"]). In that form, the URL is passed directly to the test while the browser name arrives in the fixture through request.param.
Assign useful IDs and rerun one case
Use ids= on a parametrized fixture or decorator, or assign an ID to an individual case with pytest.param(..., id="..."). IDs make collected tests and failure reports easier to scan. pytest.param can also attach marks, such as pytest.mark.xfail, to a specific case.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
To run one parametrized test instance, use its node ID in the command line. For the first example above, the command is:
pytest tests/test_pages.py::test_page_title[selenium-home]
The path, function name, and bracketed ID must match your test’s actual node ID. If you are unsure of the exact spelling, inspect pytest’s collected test IDs before rerunning.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Handle browser setup and cleanup reliably
A fixture that yields a WebDriver gives pytest a teardown point after the test finishes. Call quit() to end the WebDriver session. Selenium’s Python API documents this fixture pattern. For cleanup that should remain explicit even if test execution raises an exception, put teardown in a try/finally block:
@pytest.fixture
def driver():
browser = webdriver.Chrome()
try:
yield browser
finally:
browser.quit()
Modern Selenium uses Selenium Manager to handle browser and driver installation on most supported platforms. Explicit installation or driver specification may still be needed if that does not fit your environment. Check the documentation for your installed Selenium release and browser. Local scripts do not need the Java server; remote WebDriver requires Selenium Grid.
Troubleshoot common parametrization problems
- A test receives a string instead of a WebDriver: the value may be passed directly to the test. Mark the fixture argument indirect so pytest supplies it as
request.param. - The fixture raises an unsupported-browser error: the parameter value does not match a branch in the fixture. Add supported construction logic or correct the case value.
- A browser session remains open after a failure: ensure teardown follows
yieldand callquit(); usetry/finallywhen you want teardown expressed explicitly. - Cases unexpectedly share changed test data: parameter objects are passed as-is, not copied. Avoid in-place mutation or create fresh objects for each invocation.
- The run count is unexpectedly large: stacked parametrization creates every combination. Reduce the axes or use explicit cases when only selected combinations matter.
- A focused rerun says no tests were found: check the test path, function name, and case ID against the collected node ID.
- Browser startup fails before the assertion: verify the browser is installed and supported by the Selenium version in use, then check Selenium Manager or your explicit driver configuration for that environment.
Or skip the browser setup
If your goal is to capture a page rather than exercise browser behavior, ScreenshotNeo provides a one-call screenshot API. It returns an image or PDF and can also be used through its MCP server.
Quick Recap
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/ -o shot.webp
See the ScreenshotNeo documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for free.
Recommended Free Tools
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

