Python Selenium Architecture

madhuri_thete

Madhuri Rajaram Thete

Posted on April 5, 2024

Python Selenium Architecture

What is Selenium?
Selenium is a web automated testing tool that supports cross-browser testing across various operating systems. Selenium supports Python, JavaScript, JAVA, C# and Ruby.

Image description
Fig: Selenium WebDiver Architecture

Selenium Web-Driver:
Selenium WebDriver is a collection of APIs that allows communication between your test script and the web browser.
Selenium WebDriver API provides an understandable programming interface. WebDriver interacts with the browser using the browser’s native support for automation. For each browser(e.g. Chrome, Firefox).JAVA and C# languages are mostly preferred to work with Selenium.

Selenium Client Library:
Selenium supports various programming languages, including Python. The Selenium client library for Python provides bindings to interact with the WebDriver. The selenium client library can be divided into two groups:

1. Web Driver protocol clients:
They are thin wrappers around WebDriver protocol HTTP calls.

2. WebDriver-based tools :
These are higher-level libraries that allow us to work with
WebDriver automation.

In Python, you can install the Selenium library using a package manager like 'pip’.

Image description

Browser Drivers:
Browser drivers act as a bridge between the Selenium libraries and the browsers. They help to run Selenium commands on the browser. For e.g., the Chrome Driver executable is used to communicate with the Chrome browser.

JSON Wire Protocol:
The communication between the Selenium WebDriver and the browser driver is facilitated by the JSON Wire Protocol. This protocol defines a RESTful web service using HTTP requests and responses in JSON format.

Web Browser:
The web browser is the application being automated. Selenium supports various browsers, including Chrome, Firefox and Safari, Internet Explorer and operating systems like Windows, Mac OS, Linux.

Selenium WebDriver Feature:
1.Selenium WebDriver architecture is designed to support cross-
browser testing and parallel testing.
2.It is open-source, supports many languages, and is compatible
with many operating systems.
3.It also supports integration with testing frameworks like TestNG
to improve automation testing and reporting.
4.Selenium has strong community support which makes
troubleshooting pretty easy.
5.Selenium Architecture enables us to implement user gestures like
the mouse cursor and keyboard actions like click, double click,
drag, and drop, click and hold, etc.
6.The architecture of Selenium enables us to simulate advanced
browser interactions like clicking the browser’s back and front
buttons.

Image description

Fig: Selenium WebDriver Feature

What is significance of the Python Virtual Environment?
Python virtual environments allow developers to control software dependencies in Python code. They’re useful ways of ensuring that the correct package/library versions are consistently used every time the software runs. Virtual environments also help ensure that the results from running code are reproducible.

Image description

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated Python virtual environments for them. This is one of the most important tools that most Python developers use.
A scenario where you are working on two web-based Python projects one of them uses Django 4.0 and the other uses Django 4.1 (check for the latest Django versions and so on). In such situations, we need to create a virtual environment in Python that can be really useful to maintain the dependencies of both projects.

Create Virtual Environment in Python
We use a module named virtualenv which is a tool to create virtual environments in Python, isolated from system environment Python.

  • Steps for creating Virtual Environment in Python

Image description

1. Step 1 - Install virtualenv:
pip install virtualenv

Image description

2. Step 2 - Creating a Virtual Environment:
1. Using venv:
python.exe -m venv new-env

2. Using virtualenv:
virtualenv new_env

Image description

3. Step 3 - Activate the virtual environment:
On Windows, Press Enter after typing
.\new-env\Scripts\activate

Image description

How to fix it:
Step 1 - Run Powershell as administrator
Step 2 - Execute the following command:
"Set-ExecutionPolicy -ExecutionPolicy RemoteSigned"

Step 3 - Enter 'Y'

Image description

Step 4 - Managing Packages Using pip
pip install requests

Image description

💖 💪 🙅 🚩
madhuri_thete
Madhuri Rajaram Thete

Posted on April 5, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related