What is Selenium:
Selenium is a robust set of tools that supports rapid development of test automation for web-based applications. Selenium provides a rich set of testing functions specifically geared to the needs of testing of a web application. These operations are highly flexible, allowing many options for locating UI elements and comparing expected test results against actual application behaviour.
One of Selenium’s key features is the support for executing one’s tests on multiple browser platforms.
Who should use it ?
• Developers can use it - for “browser” regression testing ( and replace htmlunit/httpunit in some cases) .
• It should really be used by Business Analyst first .
• QA should enhance/use it do regression test/cross browsers testing on all platforms .
Components of Selenium:
Selenium-IDE :
Selenium-IDE is the Integrated Development Environment for building Selenium test cases. It operates as a Firefox add-on and provides an easy-to-use interface for developing and running individual test cases or entire test suites. Selenium-IDE has a recording feature, which will keep account of user actions as they are performed and store them as a reusable script to play back. It also has a context menu (right-click) integrated with the Firefox browser, which allows the user to pick from a list of assertions and verifications for the selected location. Selenium-IDE also offers full editing of test cases for more precision and control.
Although Selenium-IDE is a Firefox only add-on, tests created in it can also be run against other browsers by using Selenium-RC and specifying the name of the test suite on the command line.
Selenium-RC (Remote Control):
Selenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logic. For instance, if the application under test returns a result set, and if the automated test program needs to run tests on each element in the result set, the programming language’s iteration support can be used to iterate through the result set, calling Selenium commands to run tests on each item.
Selenium-RC provides an API (Application Programming Interface) and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby. This ability to use Selenium-RC with a high-level programming language to develop test cases also allows the automated testing to be integrated with a project’s automated build environment.
Selenium-Grid:
Selenium-Grid allows the Selenium-RC solution to scale for large test suites or test suites that must be run in multiple environments. With Selenium-Grid, multiple instances of Selenium-RC are running on various operating system and browser configurations; Each of these when launching register with a hub. When tests are sent to the hub they are then redirected to an available Selenium-RC, which will launch the browser and run the test. This allows for running tests in parallel, with the entire test suite theoretically taking only as long to run as the longest individual test.
A closer look at Selenium IDE:
Selenium IDE is very easy to install . We can also run scripts from Selenium IDE. It’s simple to use and us recommended for less-technical users. The IDE allows developing and running tests without the need for programming skills as required by Selenium-RC. The Selenium-IDE can serve as an excellent way to train junior-level employees in test automation. Anyone who understands how to conduct manual testing of a website can easily transition to using the Selenium-IDE for running and developing tests.
Introducing Selenium Commands:
Selenium Commands – Selenese:
Selenium provides a rich set of commands for fully testing your web-app in virtually any way you can imagine. The command set is often called selenese. These commands essentially create a testing language.
In selenese, one can test the existence of UI elements based on their HTML tags, test for specific content, test for broken links, input fields, selection list options, submitting forms, and table data among other things. In addition Selenium commands support testing of window size, mouse position, alerts, Ajax functionality, pop up windows, event handling, and many other web-application features.
A command is what tells Selenium what to do. Selenium commands come in three “flavors”: Actions, Accessors and Assertions.
• Actions are commands that generally manipulate the state of the application. They do things like “click this link” and “select that option”. If an Action fails, or has an error, the execution of the current test is stopped.
Many Actions can be called with the “AndWait” suffix, e.g. “clickAndWait”. This suffix tells Selenium that the action will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.
• Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”. They are also used to automatically generate Assertions.
• Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”.
All Selenium Assertions can be used in 3 modes: “assert”, “verify”, and ” waitFor”. For example, you can “assertText”, “verifyText” and “waitForText”. When an “assert” fails, the test is aborted. When a “verify” fails, the test will continue execution, logging the failure. This allows a single “assert” to ensure that the application is on the correct page, followed by a bunch of “verify” assertions to test form field values, labels, etc.
Selenium commands are simple, they consist of the command and two parameters. For example:
verifyText //div//a[2] Login
The parameters are not always required; it depends on the command. In some cases both are required, in others one parameter is required, and in still others the command may take no parameters at all.
Selenium scripts that will be run from Selenium-IDE may be stored in an HTML text file format. This consists of an HTML table with three columns. The first column identifies the Selenium command, the second is a target, and the final column contains a value. The second and third columns may not require values depending on the chosen Selenium command, but they should be present. Each table row represents a new Selenium command
Commonly Used Selenium Commands:
These are probably the most commonly used commands for building test.
- open -opens a page using a URL.
- click/clickAndWait -performs a click operation, and optionally waits for a new page to load.
- verifyTitle/assertTitle -verifies an expected page title.
- verifyTextPresent -verifies expected text is somewhere on the page.
- verifyElementPresent -verifies an expected UI element, as defined by its HTML tag, is present on the page.
- verifyText -verifies expected text and it’s corresponding HTML tag are present on the page.
- verifyTable -verifies a table’s expected contents.
- waitForPageToLoad -pauses execution until an expected new page loads. Called automatically when clickAndWait is used.
- waitForElementPresent -pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.
Advantages of Selenium:
Selenium is highly flexible. There are multiple ways in which one can add functionality to Selenium’s framework to customize test automation for one’s specific testing needs. This is, perhaps, Selenium’s strongest characteristic when compared with proprietary test automation tools and other open source solutions. Selenium-RC support for multiple programming and scripting languages allows the test writer to build any logic they need into their automated testing and to use a preferred programming or scripting language of one’s choice.
Selenium-IDE allows for the addition of user-defined “user-extensions” for creating additional commands customized to the user’s needs. Also, it is possible to re-configure how the Selenium-IDE generates its Selenium-RC code. This allows users to customize the generated code to fit in with their own test frameworks. Finally, Selenium is an Open Source project where code can be modified and enhancements can be submitted for contribution.
Simple demonstration of Selenium usage:
Please click on the below link to view a simple demonstration of Selenium usage. You need to have Webex player to view the demo.
Selenium Demo
No comments:
Post a Comment