Selenium Architecture
Published: 2023-12-17 08:49:24

## **_Selenium WebDriver Architecture:_**

- Selenium WebDriver is currently the most widely used component in the Selenium tool suite. Selenium WebDriver: _Selenium 2 integrated with WebDriver API_ provides an understandable programming interface. JAVA and C# languages are mostly preferred to work with Selenium.
- Through test scripts, WebDriver simulates user actions, navigates through web pages, interacts with elements (such as button, text, dropdown menu, forms, links, etc), submit forms, perform validations, assertions and many more.

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


## **_Architecture of Selenium WebDriver (Selenium 3):_**

- In **_Selenium 3_**, there is _no direct communication between the client libraries_ (Java, Python, JavaScript, etc) and the browser drivers. The server (browser drivers) _does not understand language_ but only the protocols and on the other hand, client libraries does not understand protocols used by browser drivers. 
- Therefore, JSON Wire protocol is being used as a mediator between client and server to encode and decode the requests and responses made by client and server respectively. This results in limited browser interaction, inefficient communication and lack of standardization which ultimately led to flaky test and slower test execution.


## **_Architecture of Selenium 4 WebDriver:_**

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

**_The architecture of Selenium is composed of:_**

**_1. Selenium IDE:_**
Selenium IDE (Integrated Development Environment) is primarily a record/run tool that a test case developer uses to develop Selenium Test cases. It is just a web-browser extension.
Selenium IDE is an easy-to-use tool from the Selenium Test Suite and can even be used by someone new to developing automated test cases for their web applications.

**_2. Selenium Remote Control:_**
Selenium RC is an important component in the Selenium test suite. It is a testing framework that enables a QA or a developer to write test cases in any programming language in order to automate UI tests for web applications against any HTTP website.

**_3. Selenium WebDriver:_**
Selenium WebDriver is a web framework that permits you to execute cross-browser tests. This tool is used for automating web-based application testing to verify that it performs expectedly. Selenium WebDriver allows you to choose a programming language to create test scripts.

_Selenium WebDriver Architecture is made up of four major components:_

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

- **_Selenium Client library:_** Selenium provides support to multiple libraries such as Ruby, Python, Java, etc as language bindings
- **_JSON wire protocol over HTTP:_** JSON is an acronym for JavaScript Object Notation. It is an open standard that provides a transport mechanism for transferring data between client and server on the web.
- **_Browser Drivers:_** Selenium browser drivers are native to each browser, interacting with the browser by establishing a secure connection. Selenium supports different browser drivers such as ChromeDriver, GeckoDriver, Microsoft Edge WebDriver, SafariDriver, and InternetExplorerDriver.
- **_Browsers:_** Selenium provides support for multiple browsers like Chrome, Firefox, Safari, Internet Explorer etc.

**_4. Selenium Grid_**
It is used to run parallel tests on multiple devices running different browsers at different geographical locations
We can run multiple test-cases simultaneously at one moment of time
It used the Hub-Node architecture or Master-Slave architecture

## **_Python virtual environment:_**
Python virtual environments give you the ability to isolate your Python development projects from your system installed Python and other Python environments. This gives you full control of your project and makes it easily reproducible

**_Usage of Python Virtual Environment_**

**From terminal / command-prompt**
- Check the version of Python virtual environment

    _virtualenv --version_
-  Create a Python Virtual environment

    _virtualenv <name_of_your_project>_
-  Activate your Python Virtual environment
   _ Scripts\activate_
-  Deactivate your Python Virtual environment

    _Scripts\deactivate_

_**Pycharm:**_
PyCharm makes it possible to use the virtualenv tool to create a project-specific isolated virtual environment. The main purpose of virtual environments is to manage settings and dependencies of a particular project regardless of other Python projects.