Friday, 1 July 2016

WebDriver Wire Protocal

How webdriver is working?

How selenium integrates with diff languages? Ex: Perl, python, Java, php,dot net and other languages?

Answer:

WebDriver Wire Protocal.

Explanation:

Before we start, let’s quickly start selenium server.

Command: Java –jar E:\Selenium-Jars\selenium-server-standalone-2.53.0.jar





Copy the Remote webdriver instance url highlighted above and past it in the Firefox browser.





Step 1: Create a Session:

Click on Create on create session button and select firefox from the drop down and say OK.



Now a fresh Firefox browser opens and a Session ID appears as shown below.


‘POST’ details for the same request.





Please install RestClient Add-on over Firefox browser. This is how it looks. ( This software is used to understand the selenium wire protocol )




NOTE: Now, close the created firefox browser and we will recreate a new session using RestClient add-on.


Step 2: Create a fresh driver session using RestClient.

Now, Select the Method type as POST, URL is  http://127.0.0.1:4444/wd/hub/session and Body as {"desiredCapabilities":{"browserName":"firefox"}} then hit the send button.



A fresh Firefox browser opens ( Obviously a new session will be created).


NOTE: This is how Wedriver API looks like.
https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol




Step 3: Navigate to www.google.com.





Lets go back to Restclient and put below info ( main part is session-id which we created earlier)



Click on send button, then browser will be navigates to www.google.com

Step 4: Find the Text ( google search text box)



Once you submit your request, look at the response we got Element ID as 0.

I.e the index of the element which we are trying to access.

Step 5: Key in Text in google search box

API reference: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidelementidvalue


On Submit, your browser keys in said text.


This is how we can integrate selenium with each and every language which supports.


You can use any programming language that can send HTTP requests to automate Selenium tests on the browser.