Verify Selenium installation via pip
Preconditions (2)
✅ Expected Result: The 'pip install selenium' command completes without errors, and 'import selenium' in Python interpreter does not raise any error.
import unittest class TestSeleniumInstallation(unittest.TestCase): def test_selenium_import(self): try: import selenium except ImportError: self.fail("selenium module is not installed or cannot be imported") if __name__ == '__main__': unittest.main()
This test uses Python's built-in unittest framework to check if the selenium module is installed correctly.
The test_selenium_import method tries to import selenium. If it fails, the test fails with a clear message.
This approach directly verifies the installation by confirming the module can be imported without errors.
Now add tests to verify that selenium version is at least 4.0.0
import selenium print(type(selenium))
pip install selenium but get ModuleNotFoundError when importing Selenium in Python. What is the most likely cause?pip install selenium, which additional step is necessary to start writing tests?Pass the test and this pattern moves unknown