Selenium Architecture
Published: 2024-03-27 08:26:23

The main purpose of automation testing is to minimize the time and effort of testers and generate accurate test results of end user. A tool combined with practical knowledge about the system is used to automate test execution. In an automation testing the automation test engineer, would know about the Selenium, is one tool that you would have used as main tool.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzmc6u4toph4u9ssnz1f.png)

**Selenium Client Libraries**
     These developers have made it possible to support different programming languages of our choice – Java, Python, C#, Ruby, JavaScript, etc. 
It allows us to write the Selenium automation scripts to support multiple languages.
It provides an application programming interface (API), that is, a set of functions that performs the Selenium commands from the test script and is not a testing framework.

**JSON Wire Protocol**
     JavaScript Object Notation is a data interchange format based on a subset of the JavaScript Programming Language. It is for storing and transferring data. The JSON wire protocol provides the capability of transferring data between Selenium scripts and browser drivers.
    This Json ire Protocol provides support for data structures like arrays and objects, making data reading and writing more comfortable.
     The JSON sent requests by the client are altered into HTTP requests format for the server to understand and converted back to JSON format while sending it back to the client Server again. These kind of process of data transfer is called serialization.
    In this method, the internal logic of the browser is not disclosed, and the server can communicate with the client libraries, even that is with unfamiliar programming language too.

**Browser Drivers**
     These drivers act as a bridge between the Selenium client libraries and the real browsers. They help us in running commands of selenium on the browser. 
    It is the main responsible for this driver is to executing user actions, like clicking the mouse, navigating the pages, clicking the button, etc., on the browser. 
   For every supported browser in the Selenium, have a unique browser driver. These browser drivers take commands from the Selenium test scripts and pass them to the respective browsers.
    ChromeDriver, FirefoxDriver, SafariDriver, OperaBrowser, EdgeDriver, and HtmlUnitDriver are Some popular browser drivers in Selenium.

**Selenium WebDriver Feature**

1.Multi-Browser Compatibility
2.Multiple Language Support
3.Speed & Performance
4.Community Support
5.Open Source & Portable
6.Work On Different OS
7.Add-ons & Reusability
8.Simple Commands
9.Reduced test Execution time
10.No Server installation

**Conclusion**
      The JSON Wire protocol over HTTP was the primarily used mode of communication between the Selenium client libraries and the browser driver in Selenium 3.0. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cxo147gujbgsuem6guc.jpg)
    
This protocol was replaced with the new WebDriver W3C (World Wide Web Consortium) protocol with the introduction of Selenium 4.0
     This will be less unreliable and more stable With WebDriver W3C Protocol. Stability in this is a major reason to shift to Selenium 4.0

**SIGNIFICANCE OF PHYTHON VIRTUAL ENVIRONMENT**
**Python Virtual Environment**
       A Python Virtual Environment is a powerful tool for managing dependencies and creating isolated spaces for your Python projects. **Let’s delve into its significance:**

**1.Isolation and Independence:**
A virtual environment provides an isolated space where you can work on your Python projects separately from your system-installed Python.
You can set up your own libraries and dependencies without affecting the system-wide Python installation.
Each virtual environment acts as a sandbox, allowing you to keep project-specific packages separate.

**2.Scenario-Based Use Cases:**
    Imagine you’re simultaneously working on two web-based Python projects:
Project A uses Django 4.0.
Project B uses Django 4.1.
Without virtual environments, both projects would share the same directories for storing and retrieving third-party libraries.
This creates a problem because Python can’t differentiate between different versions of the same package in the system-wide “site-packages” directory.

**Virtual environments come to the rescue:**
     Each environment contains its own set of dependencies, ensuring that Project A and Project B remain independent.

**3.Creating a Virtual Environment:**
     To create a virtual environment, you can use the virtualenv tool.

**Install it using:**
$ pip install virtualenv

**Test your installation:**
$ virtualenv --version

**Create a new virtual environment:**
$ virtualenv my_env

**Deactivate Python Virtual Environment**
  (virtualenv_name)$ deactivate

This command creates a directory named my_env containing all the necessary executables for your Python project.
You can also specify a specific Python interpreter (e.g., Python 3) when creating the environment:
$ virtualenv -p /usr/bin/python3 virtualenv_name

**4.Benefits**
     **Dependency Isolation:** Each project has its own isolated environment, preventing conflicts.

**Precise Dependency Management:** Install specific versions of packages for each project.

**Collaboration:** Share your project with others, ensuring consistent environments.

**Safe Experimentation:** Test new packages without affecting other projects.