DEV Community

Cover image for Selenium Architechture and Virtual Environment

Posted on

Selenium Architechture and Virtual Environment

Selenium architecture:

In Selenium Framework Selenium WebDriver supports overall browser-based automation tests majorly. WebDriver is the remote-control interface component that allows test programs to instruct and interact with browsers, manipulate DOM elements in a web page, and control the user agent’s behaviour. 
Selenium WebDriver and Selenium RC were merged to form Selenium 2.0 and later upgraded to Selenium 3.0 now Selenium 4.0 is further developed.
Now, all companies widely use a 3X version of Selenium. Now 4x version has been introduced these two have completely two different architectures.
Enter fullscreen mode Exit fullscreen mode

Selenium WebDriver 3.0 Architecture.

Client libraries communicates to Browser driver through JSON Wire Protocol Over HTTP and then browser driver and browser communicates by means of HTTP over HTTP Server

Selenium Client Libraries

Selenium client libraries or language bindings permit Selenium to support multiple languages to write test scripts like Ruby, C#, Python, and Java. It contains classes and methods required to write test automation scripts. It provides an application programming interface (API), i.e., a set of functions that performs the Selenium commands from the test script.
Web Driver protocol clients (They are thin wrappers around WebDriver protocol HTTP calls) and WebDriver-based tools are two major groups (These are higher-level libraries that allow us to work with WebDriver automation).
Enter fullscreen mode Exit fullscreen mode

Json wire protocol

Selenium WebDriver 3.0 uses JSON to communicate between Selenium client libraries and browser drivers. The request sent by the client is converted into an HTTP request for the understanding of the server and it again returns information in the JSON format to the client. It uses Layer 5 of the OSI reference model.
Enter fullscreen mode Exit fullscreen mode

Browser Driver

Browsers that support selenium have unique browser drivers like ChromeDriver for Google Chrome and GeckoDriver for Mozilla Firefox. It takes commands from the test scripts and passes them to the browser and is responsible for user actions like mouse clicks, keyboard inputs, etc.

  1. This HTTP request is routed through the HTTP Server which in turn directly drives the command execution on the browser.
  2. The browser then sends back the test status to the HTTP Server, which in turn forwards it to the test automation script.


Google Chrome, Mozilla Firefox, Microsoft Edge, and Apple’s Safari are some of the browsers Selenium supports it is also one of the components of Selenium Architecture. When these browsers receive a command it calls for respective commands and executes the test.
Enter fullscreen mode Exit fullscreen mode

Selenium WebDriver 4.0 Architecture.

Client libraries communicates to Browser driver through W3C Protocols and then the browser driver and browser communicates by means of HTTP over HTTP Server
Here Json wire protocol is replaced by the W3C protocol. The problem with JSON protocol is that the commands need to be converted into HTTP requests because the server only understands protocols but with the introduction of the W3C protocol there is no such need so the test can happen faster.

Virtual Environment

It is the way we can separate different Python environments for different projects.
Enter fullscreen mode Exit fullscreen mode

Virtual environment 1 has python version 2.7 and third party libraries like Numpy 1.14.4 and Matplotlib 2.2.5 and Virtual environment 2 have Python 3.6 version and libraries like pandas1.01.1 and pyspark2.4.8 and virtual environment 3 have python 3.1 and libraries like Pandas1.3.5 and Matplotlib3.5.1

Significance of virtual environment

  • Isolation
    If one is working on multiple projects and each project relies on packages like Flask, Django but in different versions, then installing these packages globally on his device may create conflicts and may even break the working projects. To avoid conflict virtual environment is created individually for every single project. And on these virtual environments, we can install all the necessary dependencies like libraries.

  • Dependency management
     Easy to manage dependencies like libraries, online services, and programming scripts.

  • Version Compatibility
     Simultaneously working on different versions of Python in different projects.

  • Clean and Reproducible Environments
     Easy to share projects and deploy we can give requirement files so the client can reproduce the environment.

  • Security
     By sandboxing Python projects it provides security to the project.
     Also, it prevents unauthorized access to the global libraries installed in the system.

  • Portability
     Packaging the entire project including its virtual environments project has higher portability.

  • Enabling Continuous Integration (CI) and Deployment
     Virtual environments play an important role in CI/CD (Continuous Integration and Continuous Deployment) pipelines. These pipelines use virtual environments to set up reproducible build and test environments.

  • Work on multiple Python projects
     Usually, all IT workers including Developers and Testers work on multiple projects and it is highly useful in that case.

Top comments (0)