Skip to main content

Selenium - Architecture

Selenium Architecture:

Here, we will learn about the overall selenium architecture. How communication happens from client library to browser and which are all the components involved between them.


Architecture compromises of major four components namely
  1. Selenium Language Binding
  2. JSON Wire Protocol
  3. Browser Drivers
  4. Real Browsers

1. Selenium Language Binding:

Various programming languages provide their own Rest API support for communicating to their respective browser drivers via JSON Wire protocol.
python provides 'selenium' as a client library which has all the rest API implementation for communicating with browser drivers.
Selenium is a third party library which does not come in python basic installation. 
You need to install it via PIP command :
pip install selenium

driver = selenium.webdriver.Chrome('location of the chrome driver executable') 

Above line returns one chrome browser session , where rest all browser related automation can be performed using on that instance using selenium library API calls.


2. JSON Wire Protocol:

JSON Wire Protocol is common protocol using across all the client libraries to bring uniformity among all the libraries. 
This Protocol converts everything to JSON format for each GET and POST request from the client libraries Rest API calls.

It sends client library data to browser drivers in the form of JSON and receives result from browsers via driver and converts JSON to user readable format.

eg : 

Python Code:
driver.get('http://facebook.com')   // Client Library 


JSON format:
{
"url" : 'sessionid/http://facebook.com'    //JSON Wire protocol interpretation.
}


Browser Driver :
Will explain in the below section , how Selenium is platform agnostic!?


Refer following link for JSON Wire protocol Documentation : 

3. Browser Drivers:

Rest API calls from client will not hit directly to real browsers instead it hits their respective browser drivers and in turn those drivers call their respective browsers.


How Selenium is platform agnostic?
JSON Wire protocol converts every single line of code from the client library to a meaningful JSON format where driver can able to understand and can perform same operation on the real browser.

Browser Driver doesn't bother/depend about which language client library user is using  because JSON-wire protocol made his job much easier by converting every single line of code to JSON format.



My Recommendation: Go through these steps , which will help you while debugging.

If you're curious to know , why JSON-Wire and driver works together. follow following steps:

Step 1 : Download selenium server standalone  Note : Selenium RC is deprecated in upcoming releases.
Step 2 : Download chrome Driver and geckodriver and place it in the same location where selenium standalone server jar is placed.
Step 3 : Run the server using : java -jar selenium-standalone-server.jar

Console output:
13:47:03.442 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-01-28 13:47:03.592:INFO::main: Logging initialized @848ms to org.seleniumhq.jetty9.util.log.StdErrLog
13:47:04.060 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
13:47:04.654 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444


Step 4 : Open the browser and enter http://localhost:4444 
It redirects a selenium page

Step 5 : Click on Console output
It opens up the console which will lists all the active sessions of the browsers.

Step 6 : Click on the new session -> select the browser of your choice ( I recommend you to choose google chrome because firefox will fail if you haven't install geckoDriver)

Step 7 : Use post man to GET or POST something on that created session.

 http://localhost:4444/wd/hub/sessions - > retrieves all the active sessions



 Thank You!
Happy Learning

Comments

Popular posts from this blog

Kubernetes ETCDCTL

ETCD is a key-value data store for storing kubernetes state and objects. ETCDCTL is the tool used to back up with snapshot. ETCDCTL a command line tool for interacting with the etcd server  Key Features:  Keep the event history until compaction. access to old version of keys. user controlled key compaction. Support range query. pagination support with limit argument. support consistency guarantee across multiple queries. Replace TTL key with lease. Support watch feature. ETCDTOOL Installation: Build binary from source code  Download tool directly  Build binary from source code: Checkout the code repository git clone -b v3.4.16 https://github.com/etcd-io/etcd.git Change directory to etcd cd etcd Run build script ./build The binaries are under the bin directory. exportPATH="$PATH:`pwd`/bin" Check etcd version etcd --version Download ETCD tool directly: kubectl exec -it etcd-docker-desktop -n kube-system -- /bin/bash -c 'ETCDCTL_API=3 /usr/local/bin/etcd --version' | h

Selenium Basic Commands.

Selenium Commands, Packages and Exceptions. Here I have selected few most frequently asked commands in the interview. Recommended way of Importing webdriver from selenium package. from selenium import webdriver. Once webdriver is imported then you are able to access the classes like this webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy To launch the application URL: driver = webdriver.Chrome driver.get('http://youtube.com') To get URL of the currently loaded page: driver.current_url To close the current window: driver.close() Exceptions in Selenium: Base Exception class: Selenium.common.exceptions selenium.common.exceptions.WebDriverException selenium.common.exceptions.InvalidElementStateException selenium.common.exceptions