This project is designed to perform cross-browser testing using Selenium WebDriver and Pytest. The tests involve automated Google searches with random search queries, and results are logged for further analysis. The browsers tested include Google Chrome and Microsoft Edge.
Ensure you have the following installed:
- Python 3.x
- Google Chrome and/or Microsoft Edge browser
- ChromeDriver and EdgeDriver for Selenium (corresponding to your browser versions)
You can download the appropriate drivers from:
-
Clone the repository:
git clone https://github.com/Only1JohnN/simple-compatibility-testing_using-selenium.git
-
Set up a virtual environment (recommended):
python3 -m venv myenv source myenv/bin/activate # For Linux/Mac # or myenv\Scripts\activate # For Windows
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up the WebDriver binaries:
- Place
chromedriverandmsedgedriverin your system's PATH or specify their location in your test script.
- Place
/tests |-- test_compatibility_testing.py # Main test script .gitignore # Git ignore file README.md # Project documentation requirements.txt # List of Python dependencies test_compatibility_testing.py: The test script that runs the Google search tests on Chrome and Edge.requirements.txt: Contains the necessary Python packages, such asseleniumandpytest.
To run the tests, simply use Pytest:
pytest tests/test_compatibility_testing.py -vThis will run the search tests on both Chrome and Edge browsers, logging the search results for each run.
The search queries can be modified or extended in the script under the SEACRH_QUERIES list. For example:
SEACRH_QUERIES = [ "Selenium Automation", "Web testing best practices", "Cross-browser compatibility testing", "Adeniyi John", "Automated testing using cypress" ]Feel free to add any search queries that are relevant to your project.
You can add or remove browsers by modifying the @pytest.fixture in the script:
@pytest.fixture(params=["Chrome", "Edge"]) def driver(request): ...To include Firefox, for instance, you would add it to the params list and ensure geckodriver is installed:
@pytest.fixture(params=["Chrome", "Edge", "Firefox"])If you need more time for page loading or results fetching, you can adjust the sleep() duration in the test function:
sleep(2) # Increase to 3 or 5 seconds if necessaryThe script uses Python’s logging module to output information about the test's progress and the results returned by Google searches. The logs will be displayed on the console, providing insights into which queries were run and what results were obtained.
logger.info(f"Searching for: {search_query}") logger.info(f"Results from {driver.capabilities['browserName']} for '{search_query}':")Logs can be customized further by modifying the logging configuration at the top of the script:
logging.basicConfig(level=logging.INFO)