DEV Community

Cover image for Python Selenium Architecture and significance of python virtual environment.
Vidhya
Vidhya

Posted on • Edited on

Python Selenium Architecture and significance of python virtual environment.

Working module of python selenium Architecture

Selenium Python uses the Selenium Client Library to convert Python commands into W3C WebDriver HTTP requests. These requests are sent to the browser-specific driver (e.g., chromedriver,edgedriver,etc), which acts as an HTTP server. The browser driver converts these commands into native browser instructions and performs them on the real browser like chrome. The driver then returns JSON responses back to Selenium, which Python interprets and gives to the script.

Workflow representation

What is virtual Environment:
A virtual environment is an isolated workspace where you can install python packages separately for each project.

This avoids version conflicts with interfering in common project structure

How to create Virtual environment

python -m venv myenv

A new folder myenv will be created

In myenv we have Activate scipts which runs and switch to new environment

Activate virtual environment

myenv\Scripts\activate


On Activating new virtual environment is created.

Virtual environment will be created. Then run the requirements.txt file, which contains project's required plugins or packages

My test execution requires pytest and selenium so I specified the following in requirement.txt

In order to execute the requirement.txt run the below comments

Why Virtual Environments Are Significant

Example 1: Different Selenium Versions for Two Test Frameworks
Scenario

We maintain:
Old Framework – uses Selenium 4.8
New Framework – uses Selenium 4.25
In global Python:

You can’t install both versions → conflict.

Solution:
Old framework


Activate:
pip install selenium==4.8

Top comments (0)