PYTHON SELENIUM ARCHITECTURE
Published: 2024-07-07 11:42:47



Selenium with Python architecture has multiple components works together to automate browser interactions with web browsers.  Selenium is an open-source framework designed for the automation testing for web applications. It is a flexible testing tool that allows the automation tester to write testing scripts in Selenium tool and in various programming languages such as Python, Java, etc., 



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

Selenium WebDriver 4 Architecture
Components:

Test Script:

It is the code we write to automate tasks in a web browser. we can write this code in different programming languages like Python, Java, or C#.

WebDriver Client Library:

This is a set of tools that help our test script talk to the web browser.  Like a translator that helps our code give instructions to the browser.

WebDriver Protocol (W3C Standard):

This is the new standard way for our test script to communicate with the web browser. It ensures that no matter which browser we use, the instructions are understood in the same way. It's like a universal language that all browsers can understand.

Browser Drivers:

These are special programs that act as middlemen between our test script and the web browser. Each browser (like Chrome, Firefox, or Edge) has its own driver (like ChromeDriver, GeckoDriver, or EdgeDriver). These drivers translate the universal language (W3C WebDriver Protocol) into specific actions that the browser can perform.

Web Browser:

This is where the actual automation happens. The browser (like Chrome, Firefox, etc.) receives instructions from its driver and performs actions like clicking buttons, entering text, and navigating pages.

How It Works with python:
Python Test Script:

we write a test script using a python and the WebDriver client library. For example, we might write a script to open a browser, go to a website, and click a button.

Send Instructions:

When we run your script, the WebDriver client library takes your instructions and converts them into the universal language (W3C WebDriver Protocol).

Talk to the Browser Driver:

The WebDriver client library sends these instructions to the appropriate browser driver (like Chrome Driver for Chrome).

Driver Translates Instructions:

The browser driver receives the instructions and translates them into specific actions that the browser can understand. It's like a coach giving directions to a player.

Browser Executes Actions:

The browser performs the actions as instructed by the driver. For example, it might open a new page, fill out a form, or click a link.

Send Back Responses:

After performing the actions, the browser sends back information (like the page title or the result of an action) to the driver.

Driver Sends Responses Back to Script:

The browser driver then sends this information back to the WebDriver client library, which in turn passes it to your test script.

Test Script Continues or Finishes:

Your test script processes the information, performs any necessary checks or assertions (to verify that everything worked as expected), and then continues or finishes the test.


_Selenium 4:_
 Reason we choose Selenium 4:

Full W3C Compliance:

 Selenium 4 fully adopted the W3C WebDriver standard, which means it works more consistently across different browsers.

Better Tools Integration:

 It introduced support for Chrome DevTools Protocol (CDP), allowing advanced debugging, performance analysis, and better control over browser features.

Relative Locators:

 New feature to locate elements relative to other elements, making test scripts easier to write and understand.

Full Page Screenshots: 

Capability to capture screenshots of the entire web page, not just the visible part.

Improved Grid: 

Selenium Grid in Selenium 4 is easier to set up and manage, with better scalability and a more user-friendly interface.

_Limitations Addressed in Selenium 4: _

Debugging and Profiling: 

Selenium 4's integration with Chrome DevTools provides advanced debugging and performance profiling tools.

Modern Web Support:
Better handling of modern web technologies and features.

Simpler and Scalable Grid:
Enhanced Selenium Grid with easier configuration and management.