The name comes from a joke made by Huggins in an email, mocking a competitor named Mercury, saying that you can cure mercury poisoning by taking Selenium supplements. The others that received the email took the name and ran with it.
Transcript of "Automated testing with selenium prasad bapatla"
“Selenium automates browsers”Why automate testing?Test automation has specific advantages for improving thelong-term efficiency of a software team’s testing processes.Test automation supports:0 Frequent regression testing0 Rapid feedback to developers0 Virtually unlimited iterations of test case execution0 Support for Agile and extreme development methodologies0 Disciplined documentation of test cases0 Customized defect reporting0 Finding defects missed by manual testing
Selenium IDE - Demo0 Recording0 Adding Verifications and Asserts With the ContextMenu0 Using Base URL to Run Test Cases in DifferentDomains
Selenium Commands –“Selenese”0 Selenium commands, often called selenese, are the set ofcommands that run your tests.0 A sequence of these commands is a test script.0 In selenese, one can test0 the existence of UI elements based on their HTML tags,0 test for specific content,0 test for broken links, input fields, selection list options,submitting forms, and0 table data among other things.0 Selenium commands support testing of window size, mouseposition, alerts, Ajax functionality, pop up windows, eventhandling, and many other web-application features.
SeleneseSelenium commands come in three “flavors”: Actions, Accessors, and Assertions.0 Actions are commands that generally manipulate the state of the application.0 They do things like “click this link” and “select that option”. If an Action fails, or has an error, the execution ofthe current test is stopped.0 Many Actions can be called with the “AndWait” suffix, e.g. “clickAndWait”. This suffix tells Selenium that theaction will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.0 Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”. They arealso used to automatically generate Assertions.0 Assertions are like Accessors, but they verify that the state of the application conforms to what isexpected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”.0 All Selenium Assertions can be used in 3 modes:0 “assert”,0 “verify”, and0 ” waitFor”.0 For example, you can “assertText”, “verifyText” and “waitForText”.0 When an “assert” fails, the test is aborted. When a “verify” fails, the test will continue execution, logging thefailure.0 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.0 “waitFor” commands wait for some condition to become true (which can be useful for testing Ajaxapplications). They will succeed immediately if the condition is already true. However, they will fail andhalt the test if the condition does not become true within the current timeout setting
Script Syntax0 Selenium scripts that will be run from Selenium-IDEare stored in an HTML text file format.0 HTML table with three columns.0The first column identifies the Selenium command0the second is a target, and0the final column contains a value.0The second and third columns may not require valuesdepending on the chosen Selenium command, but theyshould be present.0Each table row represents a new Selenium command.
Commonly Used SeleniumCommands Open - opens a page using a URL. click/clickAndWait - performs a click operation, and optionally waits for a newpage 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 HTMLtag, is present on the page. verifyText - verifies expected text and its corresponding HTML tag are present onthe 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, asdefined by its HTML tag, is present on the page.
Locating Elements0 For many Selenium commands, a target is required. Thistarget identifies an element in the content of the webapplication, and consists of the location strategy followedby the location in the format locatorType=location0 Locating by Identifier : the most common method oflocating elements and is the catch-all default when norecognized locator type is used0 the first element with the id attribute value matching thelocation will be used. If no element has a matching idattribute, then the first element with a name attributematching the location will be used
Locating Elements0 Locating by Id: more limited than the identifier locatortype, but also more explicit.0 Use this when you know an element’s id attribute.0 Locating by Name: will locate the first element with amatching name attribute. If multiple elements have thesame value for a name attribute, then you can use filtersto further refine your location strategy.0 The default filter type is value (matching the valueattribute).
Locating Elements0 Locating by Xpath : XPath extends beyond (as well assupporting) the simple methods of locating by id or nameattributes, and opens up all sorts of new possibilities such aslocating the third checkbox on the page.0 Since only xpath locators start with “//”, it is not necessary toinclude the xpath= label when specifying an XPath locator.0 Absolute XPaths contain the location of all elements from the root(html) and as a result are likely to fail with only the slightestadjustment to the application. By finding a nearby element withan id or name attribute (ideally a parent element) you can locateyour target element based on the relationship. This is much lesslikely to change and can make your tests more robust.
Locating Elements0 Locating by CSS: CSS uses Selectors for binding styleproperties to elements in the document. These Selectorscan be used by Selenium as another locating strategy.0 Most experienced Selenium users recommend CSS as theirlocating strategy of choice as it’s considerably faster thanXPath and can find the most complicated objects in anintrinsic HTML document.
Locator Assistance0 Whenever Selenium-IDE records a locator-typeargument, it stores additional information whichallows the user to view other possible locator-typearguments that could be used instead.0 This feature can be very useful for learning moreabout locators, and is often needed to help one build adifferent type of locator than the type that wasrecorded.
Matching Text Patterns0 Like locators, patterns are a type of parameter frequentlyrequired by Selenese commands.0 Examples of commands which require patterns are0 verifyTextPresent,0 verifyTitle,0 verifyAlert,0 assertConfirmation,0 verifyText, and0 verifyPrompt.0 link locators can utilize a pattern.0 Patterns allow you to describe, via the use of special characters,what text is expected rather than having to specify that textexactly.
A few tips0 Saving a test suite does not save the test case.0 Make sure that you save the test case every time youmake a change and not just the test suite.0 echo - The Selenese Print Command0 Use Find button to see which UI element on thecurrently displayed webpage (in the browser) is usedin the currently selected Selenium command. This isuseful when building a locator for a command’s firstparameter
Selenium Web Driver0 WebDriver is a tool for automating web applicationtesting, and in particular to verify that they work asexpected.0 It aims to provide a friendly API that’s easy to exploreand understand, easier to use than the Selenium-RC(1.0) API, which will help to make your tests easier toread and maintain.0 It’s not tied to any particular test framework, so it canbe used equally well in a unit testing or from a plainold “main” method.
Selenium Web Driver –Browser SupportSelenium-WebDriver supports the following browsers alongwith the operating systems these browsers are compatiblewith.0 Google Chrome 12.0.712.0+0 Internet Explorer 6, 7, 8, 9 - 32 and 64-bit where applicable0 Firefox 3.0, 3.5, 3.6, 4.0, 5.0, 6, 70 Opera 11.5+0 HtmlUnit 2.90 Android – 2.3+ for phones and tablets (devices & emulators)0 iOS 3+ for phones (devices & emulators) and 3.2+ for tablets(devices & emulators)
WebDriver &Selenium-Server0 You may, or may not, need the Selenium Server,depending on how you intend to use Selenium-WebDriver.0 If you will be only using the WebDriver API you do notneed the Selenium-Server.0 If your browser and tests will all run on the samemachine, and your tests only use the WebDriver API,then you do not need to run the Selenium-Server;WebDriver will run the browser directly.
WebDriver &Selenium-ServerSome reasons to use the Selenium-Server withSelenium-WebDriver.0 You are using Selenium-Grid to distribute your testsover multiple machines or virtual machines (VMs).0 You want to connect to a remote machine that has aparticular browser version that is not on your currentmachine.0 You are not using the Java bindings (i.e. Python, C#, orRuby) and would like to use HtmlUnit Driver
Selenium RCSelenium RC comes in twoparts.A server which automaticallylaunches and kills browsers,and acts as a HTTP proxy forweb requests from them.Client libraries for yourfavorite computer language.
References0 http://docs.seleniumhq.org/0 Selenium and Section 508 by David Sills0 http://java.dzone.com/articles/selenium-and-section-5080 Selenium Tutorial for Beginner/Tips for Experts0 http://www.jroller.com/selenium/0 Get Test-Infected With Selenium0 http://net.tutsplus.com/tutorials/tools-and-tips/get-test-infected-with-selenium-2/0 https://code.google.com/p/selenium/