Selenium 3.0

Refer youtube video – First Program in Selenium 3.0

  1. Explain Selenium 1.0 and RC and how it works
  2. Explain Selenium 2.0
  3. Explain changes in Selenium 3.0
  4. Setup 3.0 environment and Demo

Selenium 1.0

I would like to start with Selenium 1.0 it will help to understand what are the changes are in 3.0.

Selenium 1.0 introduced in 2004. JavaScript approach followed interactive with browsers using java script send box

Selenium 1.0 came with IDE with firefox plugin. This IDE itself is a framework. It has playback recording tool option to execute the test cases and test suite.

Apart from IDE there is also RC it support execution on local or remote machine with different language binding because selenium IDE scripts are written in plan html table format it just plain text file wharves RC support different programming language Java, C#, Python, Ruby

The way selenium RC works is from it has client library from different languages as mention here and from client library send command to RC , RC received the commands and send commends to browser so basically perform proxy injection of JavaScript interact with browser. RC support different OS. Logic is interactive with Dom of the browser of it support any browser similar approach.

RC receives commands from the test program, interprets them, report back the results of those tests to the test program.  RC consist of Selenium core,  that is inject into the browser using client library API when the test program opens the browser. Selenium core interprets the commands coming from the test program and execute selenese commands using browsers built-in JavaScript engine.

selenium-rc

Selenium 2.0 WebDriver

There was W3c standard taking about same-origin policy

What is Same-Origin policy ?

A web browser permits scripts contained in a first web page to access data in a second web page, but only if both web pages have the same origin. This policy prevents a malicious script on one page from obtaining access to sensitive data on another web page through that page’s DOM.

Example – Accessing one page http://www.example.com/dir/page2.html and another page http://www.example.com/dir2/other.html allow because both Same protocol, host and port.

But if u accessing http://www.example.com:81/dir/other.html does not allow because same protocol and host but different port

So in case of Selenium RC server run locally and when local server inject proxy into the application domin so application domin is different from where RC interactive so its violating same-origin policy.

Introduce web driver 2007 for web testing tool. Unlike RC, Web driver is not relaying on java script but actually using the browser driver to interact directly with application. So it interacting natively to application injecting or communicating with DOM. Initially web drive only support JAVA.

Every browser impose very strict security rules on the JavaScript being executed to protect the users from malicious scripts. This make testing harder for some scenarios. For example IE JavaScript security model don’t allow to change the value of the INPUT file element for uploading the file and navigating between different domains

So here browser driver implantation provided top to web driver so this way it is fully supporting same-origin policy.

Webdriver and Selenium is merged in 2009. So webdriver is also supporting different browsers

At that time many scripts is written in RC so solution provided Webdriver backed selenium.  So using this interface migrate instillation of browser so that selenium core logic change the webdriver.

Selenium 3.0

Major Changes

  • From selenium webdriver API the legacy-rc library is separated. The original RC APIs are only available via the leg-rc package. So RC approach is totally dropped in 3.0
  • Selenium-Java library contains clear version of WebDriver
  • Selenium 3.0 works only with Java 1.8 or Higher
  • Support for Firefox is via Mozilla’s geckodriver.
  • Official support for IE requires version 9 or above.
  • Unused command line arguments are now no longer parsed.

Impact of Existing Scripts of Selenium 2.0 – There was no major impact of selenium 2.0 scripts just need to change the JDK version and few references.

You will get below exeption if launch firefox browser with Selenium 3 without gecko driver

Exception “java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;”

What is Geckodriver ?

A Proxy for using W3C WebDriver-compatible clients to interact with Gecko-based browsers. Geckodriver provides HTTP API described by the WebDriver protocol to communicate with Gecko browsers, such as Firefox (Version after 47)

Selenium 3 expects you to set path to the driver executable by the ‘webdriver.gecko.driver’.

 When using Selenium 3 beta releases, you have to download geckodriver. Just like the other drivers available to Selenium,

Geckodriver download link – https://github.com/mozilla/geckodriver/releases

Now let us see the example to launch firefox browser with Selenium 3 with gecko driver

public class Test1 {

public static void main(String[] args) {

System.setProperty(“webdriver.gecko.driver”, driverPath+”geckodriver.exe”);      driver = new FirefoxDriver();        driver.quit();      }}

With Chrome driver

public class Test2 {

public static void main(String[] args) {

System.setProperty(“webdriver.chrome.driver”, driverPath+”chromedriver.exe”);      driver = new ChromeDriver();        driver.quit();      }}

Limitation of gecko driver in Firefox

If used driver.quite() and try to close the firefox driver getting exception

Solution – use driver.close()

Gecho_Driver_FF_Error.png

 

Advertisements

About samp79

Professional Automation Tester
This entry was posted in Selenium, Test Automation. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s