Selenium Architecture

Selenium Architecture

Selenium Architecture consists of mainly four stages to function.

  • Selenium Client Library
  • JSON wire protocol
  • Browser Drivers
  • Browser

Selenium Client Library

Selenium client libraries such as python,Java, Java script , C# and Ruby etc. Whenever we start executing the test scripts in respective languages our test code will be converted to JSON format in the form of keys and values pairs.



JSON Wire Protocol

JSON stands for JavaScript Object Notation.JSON helps to transfer data between client to server and vice versa by HTTP protocol.

Now the converted JSON code by client libraries will then be transferred to brower drivers over HTTP protocol.

Browser Driver and Bowser.

Each browser has its own browser driver.This driver helps us to interact with the browser and execute the commands.

When JSON sends the instructions which they receive from client libraries to the browser driver. Now the browser driver will interact with the browser, then they execute those commands and send the HTTP response back.

Finally , Status of the response will show on the monitor by using JSON wire protocol.

Here , JSON wire protocol sends two types of requests to browser driver.

  • POST request
  • GET request

POST Request : When POST request is sent to the browser driver then action will trigger on the browser.

GET Request : When GET request is sent to the browser driver then action will trigger on the browser and status will be sent to the browser driver over HTTP.Now the browser driver will send the response to monitor by using JSON wire protocol.



Now let's take an example for the below block of code.

In this example, We launch the webpage and get the text which we entered in the edit box and print on the monitor.


SeleniumExample.py

rom selenium import webdriver
import time

from selenium.webdriver.common.by import By

driver = webdriver.Chrome("/Users/admin/Documents/Skill2Lead/Others/drivers/chromedriver.exe")

driver.get("http://www.dummypoint.com/seleniumtemplate.html")

time.sleep(2)
element = driver.find_element(By.ID,"user_input")
element.send_keys("Skill2Lead")

time.sleep(2)

print("text :",element.get_attribute('value'))

time.sleep(5)
driver.quit()

  • Above code was written using python,So that here we use the python client library.
  • When we execute the code those values are converted to JSON. Now using JSON wire protocol those data will transfer to browser driver
  • Browser driver sent the data which received by JSON wire protocol to browser over HTTP protocol and execute the commands
  • First it will send the launch url POST command and it will try to launch the webpage. When it launches, the browser sends the response to the driver as status success over HTTP.
  • It will send the command to enter text in the edit box.
  • Now it will send the command to getText from a webpage using GET request.When browser executes the command it will send the data to browser driver over HTTP and browser driver sends the data to display on monitor using JSON wire protocol.
  • Finally, It will send the POST command to quite the browser driver.