• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Automated testing with selenium prasad bapatla
 

Automated testing with selenium prasad bapatla

on

  • 971 views

Automated testing using selenium IDE, presentation from Phily.Net code camp May 11, 2013

Automated testing using selenium IDE, presentation from Phily.Net code camp May 11, 2013

Statistics

Views

Total Views
971
Views on SlideShare
971
Embed Views
0

Actions

Likes
0
Downloads
59
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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.

Automated testing with selenium prasad bapatla Automated testing with selenium prasad bapatla Presentation Transcript

  • “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 History0 2004 - at ThoughtWorks in Chicago, Jason Huggins built the Core mode as"JavaScriptTestRunner" for the testing of an internal Time and Expensesapplication (Python, Plone).0 2006 - at Google, Simon Stewart started work on a project he called WebDriver.Google had long been a heavy user of Selenium, but testers had to work aroundthe limitations of the product. The WebDriver project began with the aim tosolve the Selenium’ pain-points.0 2008 - merging of Selenium and WebDriver. Selenium had massive communityand commercial support, but WebDriver was clearly the tool of the future. Thejoining of the two tools provided a common set of features for all users andbrought some of the brightest minds in test automation under one roof.0 Shinya Kasatani in Japan became interested in Selenium, he0 Wrapped the core code into an IDE module into the Firefox browser0 Added the ability to record tests as well as play them back in the same plugin.0 This tool, turned out an eye opener in more ways that was originally thought as it isnot bound to the same origin policy.0 See http://docs.seleniumhq.org/about/history.jsp for more interesting details0 http://docs.seleniumhq.org/about/contributors.jsp
  • Selenium World
  • Which tool to use?
  • Selenium IDE
  • Installing Selenium IDE
  • 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 Hyperlinks by Link Text: simple method of locatinga hyperlink in your web page by using the text of the link. Iftwo links with the same text are present, then the first matchwill be used.0 Locating by DOM: The Document Object Model represents anHTML document and can be accessed using JavaScript. Thislocation strategy takes JavaScript that evaluates to an elementon the page, which can be simply the element’s location usingthe hierarchical dotted notation.0 Since only dom locators start with “document”, it is not necessaryto include the dom= label when specifying a DOM locator.
  • 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.
  • Matching Text Patterns0 Three types of patterns:0 Globbing (Selenium globbing patterns only support the asterisk andcharacter class)0 * which translates to “match anything,” i.e., nothing, a single character, ormany characters.0 [ ] (character class) which translates to “match any single character foundinside the square brackets.” A dash (hyphen) can be used as a shorthand tospecify a range of characters (which are contiguous in the ASCII characterset).0 Regular expressions - most powerful of the three types of patterns(same wide array of special characters that exist in JavaScript)0 need to be prefixed with either regexp: (case-sensitive) or regexpi: (case-insensitive)0 Exact - uses no special characters at all - if you needed to look for anactual asterisk character (which is special for both globbing and regularexpression patterns0 glob:Real * vs exact:Real *
  • User Extensions0 User extensions are JavaScript files that allow one tocreate his or her own customizations and features toadd additional functionality.0 Often this is in the form of customized commandsalthough this extensibility is not limited to additionalcommands0 Seehttp://wiki.openqa.org/display/SEL/Contributed+User-Extensions
  • Sequence of Evaluation andFlow Control0 When a script runs, it simply runs in sequence, onecommand after another.0 Selenese, by itself, does not support conditionstatements (if-else, etc.) or iteration (for, while, etc.).0 When flow control is needed, there are three options:0 Run the script using Selenium-RC and a client librarysuch as Java or PHP to utilize the programminglanguage’s flow control features.0 Run a small JavaScript snippet from within the scriptusing the storeEval command.0 Install the goto_sel_ide.js extension.
  • 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 IDE - Limitations0 Firefox only
  • 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 WebDriver - .NET0 http://www.nuget.org/packages/Selenium.WebDriver
  • 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/
  • Books
  • Thanks&enjoy the rest of the codecamp 