Free tools Windows power users keep installed
One-click scans. No signup required.
Use Python’s built-in unittest module—often called PyUnit—with Selenium by putting browser tests in a unittest.TestCase class, opening the WebDriver in setUp, and registering driver.quit as cleanup. You do not install a separate “PyUnit” package. The example below runs locally and can be extended with unittest discovery or a test suite.
What PyUnit means in a Selenium project
Python’s standard library names its testing framework unittest. “PyUnit” is a familiar label for that framework, not a separate package or a Selenium add-on. The framework provides test cases, fixtures, suites, runners, and assertions; Selenium supplies the browser automation.
The example uses Selenium’s Python bindings. The Selenium 4.49.0 documentation accessed October 3, 2026 lists Python 3.10+ support and supported browser targets including Chrome, Edge, Firefox, Safari, WebKitGTK, and WPEWebKit. Check the current Selenium WebDriver documentation for support and installation details that may change.
Install Selenium and prepare a local browser
-
Create and activate a virtual environment for the project, then install the Selenium package:
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter- 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.
python -m venv .venv # macOS or Linux source .venv/bin/activate # Windows PowerShell .venvScriptsActivate.ps1 python -m pip install selenium -
Install a browser supported by your environment, such as Chrome, if one is not already available.
-
In modern Selenium, Selenium Manager handles driver setup for most supported browser and platform combinations when the driver is instantiated. A separate manual driver download and PATH configuration is not a universal prerequisite. Manual browser or driver setup remains an option if your environment requires it.
A local test does not need a Selenium server. Remote WebDriver or Grid is a later option when you need browser sessions on another machine or centrally managed infrastructure.
Create a Selenium unittest case with reliable cleanup
Save the following as test_selenium.py. It opens Chrome for the test, navigates to Selenium’s public site, checks a title condition, and registers cleanup immediately after the driver is created.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →import unittest
from selenium import webdriver
class SeleniumTestCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.addCleanup(self.driver.quit)
def test_page_title(self):
self.driver.get("https://selenium.dev")
self.assertIn("Selenium", self.driver.title)
if __name__ == "__main__":
unittest.main()
Why use setUp and addCleanup?
setUp runs before each test method, so each test gets a fresh browser session. Calling addCleanup(self.driver.quit) right after driver creation ensures the session is quit after the test, including when an assertion fails. quit() ends the WebDriver session; close() closes only the current window and may leave a session running when more than one window exists.
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.
Write test methods and assertions
Each method the runner should execute starts with test. Assertions communicate expected behavior to the test runner: use methods such as assertEqual, assertTrue, assertFalse, and assertRaises rather than printing a result or raising an unrelated error. The sample’s assertIn checks that the title contains the expected word, without requiring an exact full-title match.
Run one test, a class, or the project suite
Run a test file
From the project directory, run:
python -m unittest test_selenium.py
The module form works too:
python -m unittest test_selenium
To run a specific class or method, use a dotted name:
python -m unittest test_selenium.SeleniumTestCase
python -m unittest test_selenium.SeleniumTestCase.test_page_title
Discover tests as the project grows
Organize related tests in files such as test_search.py and test_checkout.py. By default, unittest discovery looks for test files matching test*.py. From a project directory, run discovery with:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorspython -m unittest discover
You can specify a start directory and filename pattern when your layout needs it:
python -m unittest discover -s tests -p "test_*.py"
Use unittest.TestSuite when you need explicit composition of selected test cases; discovery is simpler for a conventional growing test directory. Keep each test self-contained so it can run alone or in a different order. Put shared setup and teardown in fixtures rather than making one test depend on another.
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.
Use pytest with an existing unittest suite
You can run many existing unittest tests with pytest without rewriting their TestCase classes. With pytest installed, invoke it on the test file or project:
python -m pip install pytest
python -m pytest
By default, pytest collects files named test_*.py or *_test.py and test methods beginning with test in unittest classes. It offers selection options, output capture, tracebacks, and plugins. Compatibility is not complete: if your suite relies on unittest’s load_tests protocol or other specialized behavior, consult the pytest unittest compatibility documentation before switching runners. unittest is built into Python; pytest is an additional dependency. Neither runner changes how Selenium controls the browser.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWhen to use remote Selenium execution
Keep the first test local. Consider Remote WebDriver or Selenium Grid when browser sessions must run on separate machines, when a team needs centrally managed browsers, or when execution should be separated from the test runner. Remote setup requires a reachable Selenium endpoint and compatible browser capacity; the local webdriver.Chrome() constructor must then be replaced with the project’s remote-driver configuration. Remote execution is not required for unittest, Selenium installation, or a basic browser test.
For screenshot capture rather than interactive browser testing, ScreenshotNeo is a website screenshot API and MCP server. It is a different tool from WebDriver: use it when you need an image or PDF of a page, not to replace assertions or browser interaction in a Selenium test.
Troubleshoot common failures
-
ModuleNotFoundError: No module named 'selenium': Selenium is missing from the Python environment running the test. Activate the project’s virtual environment and install withpython -m pip install seleniumusing that same interpreter.Rank #4
SaleUGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray- 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
-
Browser or driver cannot be started: Confirm a supported browser is installed and that the environment can allow Selenium Manager to resolve the driver. If automatic setup is unsuitable for your network or machine policy, configure browser and driver installation manually according to Selenium’s documentation.
Recommended: Update Every Outdated Driver on Your PC in One Scan - Free →Recommended: Fix Windows Errors and Clear Junk Files in Minutes - Free Scan →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
The test fails before reaching the assertion: Look at the WebDriver startup or navigation exception in the runner output. Verify the target is reachable from the test machine and that the browser can launch in the current environment.
-
The browser remains open after a failure: Register
self.addCleanup(self.driver.quit)immediately after successful driver creation. Avoid relying on code placed after assertions, since a failed assertion stops normal execution of the test body. -
No tests are found: Check the filename pattern, class inheritance, and method prefix. A discoverable test file generally starts with
test, the class subclassesunittest.TestCase, and runnable methods start withtest. -
A test passes alone but fails in a suite: Remove ordering assumptions and shared mutable browser state. Each test should establish the page and state it needs, then clean up its own browser session.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display- 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.
Or skip the browser setup
If your goal is a clean screenshot or PDF rather than a WebDriver test, ScreenshotNeo can return the capture from one GET request. See the ScreenshotNeo API documentation for the available parameters.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://selenium.dev -o shot.webp
- Cookie banners are accepted and more than 60 known consent platforms, newsletter popups, and chat widgets are removed before the shot; each step can be turned off.
- Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. Responses include
X-Page-VerdictandX-Billedheaders. - An MCP server provides
take_screenshot,get_page_info, andcapture_pdftools for Claude, Cursor, and other MCP clients. - The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to try it with 1,000 screenshots a month and no card.
Frequently Asked Questions
Can unittest run Selenium tests in parallel by itself?
The unittest command described here runs the selected tests without adding a parallel-execution tool. If parallel browser sessions are needed, choose and configure an execution approach that supports them, and ensure each session has isolated resources.
Should I use unittest or pytest for a new Selenium project?
Use unittest if you want a runner included with Python and a class-and-fixture style. Consider pytest if its selection, reporting, or plugin capabilities better fit your project; it can also collect many existing unittest tests.
Recommended Free Tools
Quick Recap
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.

