DEV Community

Priyadharsini RK
Priyadharsini RK

Posted on

Python Selenium Architecture and Virtual environment with example commands

Selenium Architecture:
Selenium is a powerful tool for controlling web browser through program. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. Selenium has four major components – Selenium IDE, Selenium RC, Selenium Web driver, Selenium GRID.
The architecture of Selenium is composed of:
Selenium IDE
1.IDE - Integrated Development Environment
It is just a web-browser extension that you need to download and install the extension for that particular web browser and start working with it.
One of the major advantages of using Selenium IDE is that it can automate and record the entire automation process as well
People generally do not use IDE, they rather prefer selenium scripts in order to do the same job.

2.Selenium Remote Control
It is an outdated and deprecated technology. We do not use it these days.
It has been replaced with WebDriver which is far more better and easy to use.

3.Selenium WebDriver:
• It is the most important and major component of selenium architecture.
• It provides a programming interface between the language and the web-browser.
• It is composed of:
a.Selenium Client Library:
• It consists of language bindings or commands which you will be using to write in your automation scripts.
• They are compatible with W3C protocols like HTTP, HTTPS, TCP, UDP etc
• They are the wrappers which send the script commands to the network, for the execution into the web-browser.

b.Selenium API
• It contains a set of rules and regulation which your Programming language (Python) used to communicate with the Selenium
• It helps in automation without the need for the user to understand what is happening in the background.

c.JSON wire protocol:
• The commands that you write are converted into JSON which is then transmitted across the network or to your web-browser so that it can be executed.
• The JSON data are sent to the client using the HTTP protocol
• It is used by the browsers also,

d.Browser Drivers:
• It acts as a bridge between the Selenium Script, Libraries and the browser.
• It helps us to run the selenium commands on the web browser.
https://github.com/mozilla/geckodriver/releases/tag/v0.34.0

Browser:
• All the web browser.

4.Selenium Grid:
• It is used to run parallel test on multiple devices running same or different browsers and we could also simulate at different geographical locations.
• We can run multiple test-cases simultaneously at the same time.
• It uses the master-slave architecture.

Virtual Environment:
• It is a tool which helps python Developers and testers to keep project dependencies and modules which are required for different projects separate and independent from each other.
• With this we can manage our projects and their dependencies far more easily and efficiently.
• This allows us to have multiple independent python environments on the same system without them interfering with each other.

Uses of Virtual Environments:

  1. Isolation
  2. Dependency Management

How to create virtual environments in Python,

  1. virtualenv:

Install the virtualenv package:

pip install virtualenv

Create the python virtual environment:

virtualenv

b. Select the virtual environment:

Click ctrl + shift + p and select Python: Select Interpreter

c. Select your environment which you have created now

Other way of using pipenv using terminal:

  1. Create the Virtual Environment by:

pipenv - -python 3.12

  1. Install the packages

pipenv install selenium

pipenv install webdriver_manager

  1. Run the python file

pipenv run python main.py

Top comments (0)