4 What is Selenium?Selenium is a robust set of tools that supports rapid development of test automation for web-based applicationsSelenium is a combination of tools for functional tests, smoke tests, and integration tests of Web applications, including Rich Internet Applications (RIA, using Ajax.)A Java Script Based so work any whereEmbeds test automation engine in your browserSupported on Multiple Browsers
5 Why Selenium ?Cross Platform and Browser CompatibilityThe beauty of doing these scripts in Selenium is that you could run these scripts after they are just written and see instantly where they may need tweaking and amendingFlexibility and Extensibility: Selenium’s strongest characteristic when compared with proprietary test automation tools and other open source solutions. Selenium-RC supports multiple programming and scripting languages.Allows running multiple tests parallely in single/multiple browsersPortability: Allows to record scripts in Windows and replay it in Linux without re-creating the script
8 Using Selenium IDEIntegrated development environment for Selenium testAllows you to record, edit and debug tests.
9 Selenese – The language of Selenium Commands of SeleniumSelenese consists of Actions, Accessors, Element Locators and VariablesActions – Combination of Command, Target and ValueCommand : Scripts perform a particular action on a web applicationTarget : Typically take element locatorValue : Value for any inputExample:Open - Open a URLClick – Click button, link, etc...Type – Type text in text fieldThere are only about 6 commands you need to know to be able to automate tests. Same as a manual test case really (open, click, select, type, assert (check), wait).
10 Selenese – The language of Selenium Accessors – Accessors examine the state of the application and store the results in variables. Verification / Validation checkpoints for the toolExample:Store (locator, variables)Verify (locator, pattern)They are also used to automatically generate AssertionsAssertions – 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 modes1. assert2. verify3. waitfor
11 Selenese – The language of Selenium Element Locator –These can be id, name, identifier, link, xpath, etc...Variables used in scriptingInformation regarding Actions, Accessors can be found in class ‘Selenium Driver’ in installed directory
12 Selenium – Locating Elements Using Firebug Tool Locating by XPathRule 1: if value is assigned to any attributeStep 1 Inspect objectStep 2 Look for first word say “Input”Step 3 start all xpath with //Step 4 Step attributeStep 6 value ->>Rule 2: if value is not assigned to any attributeStep 2 Look for first word say “a”Step 5 text()Step 6 value ->> //a[text() = “Maps“]Rule 3: If two same objects are displayed on same page and you have to find out your choice of object//a[text()="Maps"]/following:: a[text()="Maps"]/]
13 Table or driver based? Table based approach fine for simple tests. No programming requiredDoesn't scale – duplication is a major issueDriver approach better for 'Real' test suitesCan develop tests in language of choiceC#, Java, Ruby, Python, PerlEasier data management via DB / Excel
14 Using Selenium RCAlthough 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 lineSelenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logicSelenium-RC provides an API (Application Programming Interface) and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby.
16 Configuring Selenium-RC With Eclipse Eclipse is a software that allows you to write and execute programs in many different languages. In our case we will be using Eclipse to write and execute Selenium via Java
17 Using Selenium GridSelenium-Grid allows the Selenium-RC solution to scale for test suites or test suites to 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.
18 Know Issues & Workarounds Part 3:Know Issues & Workarounds
19 Selenese – Element not found on page Potential Cause:Can happen due to execution speed of seleniumElements do not load on page in timeFix:Add code in scripts which waits for elementsAdditional issues:Sometime existing elements on a page are not deletedSometime elements on a page have same labelSolution:Obtain exact element label from source codeLabel can be used in scripts for accuracy
20 Selenese – Handling of Popup Windows Steps:Window id required for automated operation in windowUse following commands for handling alert messages:Put following commands before assertalert command1) storeAlert and value ($variableName)2) storeAlertPresent and value ($variableName)
21 Selenese – Handling of Frames Option:Multi-window option handles potential frame problemsCause:At times required name of frame not obtained in recordingFix:Obtain frame label from source codeAlso can be obtained from browser URL bar
22 Practice that we decided to implement Agile, Automation, and Continuous IntegrationPractice that we decided to implementRun Selenium tests as part of the buildRun all acceptance tests in the regression test suite with the build, daily (at a minimum). Run all unit tests with every build. Run multiple builds per day.Can generate HTML reports, published to entire teamHelps catch bugs ASAPAddresses risk of catching bugs late in the cycle
25 Why Selenium ? Scripting Capabilities Simplified Script Creation – In selenium, the default script is in html and it is the most common scripting language used among peoples.Keyword driven testingStandard Scripting Language allows you to easily create/update scripts without much programming knowledgeObject Repository is not available in selenium but it is one of the features of all Functional testing toolData driven Testing enables you to perform functional testing in different scenarios by just changing the test data in an external data source. Selenium supports Data driven testingUnicode supports allows you to test multi-language deployments of your applicationsSupports pattern-matching capabilities to improve test script reuse, if application changes frequently
26 Why Selenium ? Portability : Allows you to record scripts in Windows and replay it in Linux without re-creating the scriptsBrowser Abstraction Layer allows scripts recorded in one browser to be replayed in all other supported browsersRuntime locale option lets you to simultaneously test all language versions of your application with a single script
28 Why Selenium ? Playback Options Automatic/Customizable Error Recovery for unattended testing to handle unexpected window, like an ASSERT box, pop- ups, etc. But automatic error recovery for unattended testing is not available for selenium but user can write his/her own scripts to handle this.Playback Synchronization to handle the variation in time the application takes to load a new page. Ex: In selenium ClickAndWait is a command which will wait for the page to load and start executing the next command.Option to chain scripts for controlling the order of script execution. In selenium core, we can do the order of execution and if user wish he can execute everything as a batch file.Multiple Play back options that enables testers to debug test errors while creating and maintaining test scripts. Selenium supports multiple play back options.Allows execution of individual and/or groups of tests from one or many workstations.Provision for command-line invocation allows invocation from batch files or scheduling utilities.
29 Why Selenium ? Reporting Capabilities Clear and Powerful Reports are provided to indicate the status of the test execution.Hyperlinks or color coding (RED color for failure) allow easy navigation through the report.This helps you to quickly identify application failures and clearly assess application quality.
30 Why Selenium ? Compatibility Testing: Today organizations trying to automate their web applications/web sites are looking for a uniform testing solution. This will help them to reuse test scripts to test it in different platforms/different browsers/different languages/different databases/different servers