Tuesday 5 July 2016

Understanding Selenium IDE & Architecture




Selenium IDE, is an extension for Firefox that allows users to record and playback tests.

A table-based syntax was placed over the raw Javascript and this allowed tests to be written by people with limited programming experience using a keyword-driven approach in HTML files.  

Command        –               Element             –            Text
type                                 name=q                       Selenium WebDriver

Selenium IDE is developed using Javascript, as all the browsers being tested supported Javascript. 

Do you want to see? How Selenium IDE code looks like?

      a. Download latest selenium IDE add-on file from here. (Ex: http://release.seleniumhq.org/selenium-ide/2.9.0/ )  selenium-ide-2.9.0.xpi  749 KB

      b.   Extract xpi file using a software, which you can download here. http://b1.org/

      c.    You would notice multiple xpi files under selenium-ide-2.9.0.xpi file, but we are mainly looking at selenium-ide.xpi file

      d.    Extract selenium-ide.xpi file

      e.     Browse below folder once you extract xpi file C:\Users\USER_ACCOUNT\Downloads\selenium-ide-     2.9.0\selenium-ide\chrome\content\selenium-core\scripts

      f.     All Java script files!! This is the selenium Core.

Selenium Core is the heart of the original Selenium implementation, and is a set of Javascript scripts that control the browser. This is sometimes referred to as "Selenium" and sometimes as "Core".

How selenium IDE works?

Test Runner will do the job.


or

C:\Users\ USER_ACCOUNT \Downloads\selenium-ide-2.9.0\selenium-ide\chrome\content\selenium-core/ TestRunner.html

Below are the the referenced javascript files to execute our scripts.

Lib/prototype.js, lib/sizzle.js, lib/snapsie.js, scripts/atoms.js, scripts/htmlutils.js, scripts/ui-element.js, lib/scriptaculous/scriptaculous.js, scripts/selenium-browserdetect.js, scripts/selenium-browserbot.js, scripts/find_matching_child.js, scripts/selenium-api.js, scripts/selenium-commandhandlers.js, scripts/selenium-executionloop.js, scripts/selenium-testrunner.js, scripts/selenium-logging.js, scripts/selenium-version.js, xpath/util.js, xpath/xmltoken.js, xpath/dom.js, xpath/xpath.js, xpath/javascript-xpath-0.1.12.js, scripts/user-extensions.js

Above all javascript libraries are heart of selenium IDE, which are very important to run selenium commands.

So, Do you want to add your own / custom functionality? Here is the way.
Because Selenium's core is developed in JavaScript, creating an extension follows the standard rules for prototypal languages. To create an extension, we create a function in the following design pattern.
Ex: C:\Users\ USER_ACCOUNT \Downloads\selenium-ide-2.9.0\selenium-ide\chrome\content\selenium-core/script/user-extensions.js.sample

Selenium.prototype.assertValueRepeated = function(locator, text) {
    // All locator-strategies are automatically handled by "findElement"
    var element = this.page().findElement(locator);
    // Create the text to verify
    var expectedValue = text + text;
    // Get the actual element value
    var actualValue = element.value;
    // Make sure the actual value matches the expected
    Assert.matches(expectedValue, actualValue);
};
Save the above code as 'user-extensions.js"

By default, Selenium looks for a file called "user-extensions.js", and loads and javascript  code found in that file.  user-extensions.js provides a convenient location for adding extensions to Selenium, like  new actions, checks and locator-strategies.


By default, this file does not exist. Users can create this file and place their extension code  in this common location.
How to use newly created core extension?
1.     Go to Selenium IDE - Click on Options -> Options…
2.     In General section select the location of the newly created Selenium Core Extension
3.     Click OK and restart Selenium IDE

You will find the extension in the command list






Architecture:

Advantages:
  • Selenium IDE is very easy to use.
  • It has the capability to convert the test to different programming languages such as html, java etc
  • Programming language experience is not required for Selenium IDE
  • Selenium IDE provides Logging capabilities using file login plug-in.
  • In Selenium IDE, user can debug and set breakpoints
  • Selenium IDE is flexible for the users.
  • Auto complete for all common Selenium commands
  • Debug and set breakpoints
  • Option to automatically assert the title of every page
  • Support for Selenium user-extensions.js file
Disadvantage:
  • Selenium IDE is Firefox plugin, thus its support is limited to Firefox only
  • It will not support iteration and conditional statement
  • Selenium IDE doesn't support Exception and Error handling
  • Doesn't support test script grouping
  • No Reporting
  • No Test Fixtures and data-driven tests
  • No Test Dependencies
  • No way to take screen shots
  • Selenium IDE do not support Database testing
  • It is not playing multiple windows when we record it ( switching between windows).
  • limitations to open/ identifying the child windows,clicking on the pop ups, etc.,


Clue to Selenium Remote Controller:


Why not use Selenium IDE alone? For one thing, it works only with FireFox, version 1.5 or later. If we run the tests on the server, we can test our application using any browser.

Shutdown Selenium Server from browser URL

Selenium server operates a web server under Jetty it can receive commands via http through browsers.
The following URL will be used to shut down the server.

http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer

If we want to leave the server running and just close down the current session we could issue the following URL in a browser.
http://localhost:4444/selenium-server/driver/?cmd=shutDown