Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Â
Automated testing with selenium prasad bapatla
1.
2.
3. âSelenium automates browsersâ
Why automate testing?
Test automation has specific advantages for improving the
long-term efficiency of a software teamâs testing processes.
Test automation supports:
0 Frequent regression testing
0 Rapid feedback to developers
0 Virtually unlimited iterations of test case execution
0 Support for Agile and extreme development methodologies
0 Disciplined documentation of test cases
0 Customized defect reporting
0 Finding defects missed by manual testing
4. Selenium History
0 2004 - at ThoughtWorks in Chicago, Jason Huggins built the Core mode as
"JavaScriptTestRunner" for the testing of an internal Time and Expenses
application (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 around
the limitations of the product. The WebDriver project began with the aim to
solve the Seleniumâ pain-points.
0 2008 - merging of Selenium and WebDriver. Selenium had massive community
and commercial support, but WebDriver was clearly the tool of the future. The
joining of the two tools provided a common set of features for all users and
brought some of the brightest minds in test automation under one roof.
0 Shinya Kasatani in Japan became interested in Selenium, he
0 Wrapped the core code into an IDE module into the Firefox browser
0 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 is
not bound to the same origin policy.
0 See http://docs.seleniumhq.org/about/history.jsp for more interesting details
0 http://docs.seleniumhq.org/about/contributors.jsp
9. Selenium IDE - Demo
0 Recording
0 Adding Verifications and Asserts With the Context
Menu
0 Using Base URL to Run Test Cases in Different
Domains
10. Selenium Commands â
âSeleneseâ
0 Selenium commands, often called selenese, are the set of
commands that run your tests.
0 A sequence of these commands is a test script.
0 In selenese, one can test
0 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, and
0 table data among other things.
0 Selenium commands support testing of window size, mouse
position, alerts, Ajax functionality, pop up windows, event
handling, and many other web-application features.
11. Selenese
Selenium 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 of
the current test is stopped.
0 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.
0 Accessors examine the state of the application and store the results in variables, e.g. âstoreTitleâ. They are
also used to automatically generate Assertions.
0 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â.
0 All Selenium Assertions can be used in 3 modes:
0 âassertâ,
0 âverifyâ, and
0 â 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 the
failure.
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 Ajax
applications). They will succeed immediately if the condition is already true. However, they will fail and
halt the test if the condition does not become true within the current timeout setting
12. Script Syntax
0 Selenium scripts that will be run from Selenium-IDE
are stored in an HTML text file format.
0 HTML table with three columns.
0The first column identifies the Selenium command
0the second is a target, and
0the final column contains a value.
0The second and third columns may not require values
depending on the chosen Selenium command, but they
should be present.
0Each table row represents a new Selenium command.
13. Commonly Used Selenium
Commands
ï¶ 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 its 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.
14. Locating Elements
0 For many Selenium commands, a target is required. This
target identifies an element in the content of the web
application, and consists of the location strategy followed
by the location in the format locatorType=location
0 Locating by Identifier : the most common method of
locating elements and is the catch-all default when no
recognized locator type is used
0 the first element with the id attribute value matching the
location will be used. If no element has a matching id
attribute, then the first element with a name attribute
matching the location will be used
15. Locating Elements
0 Locating by Id: more limited than the identifier locator
type, 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 a
matching name attribute. If multiple elements have the
same value for a name attribute, then you can use filters
to further refine your location strategy.
0 The default filter type is value (matching the value
attribute).
16. Locating Elements
0 Locating by Xpath : XPath extends beyond (as well as
supporting) the simple methods of locating by id or name
attributes, and opens up all sorts of new possibilities such as
locating the third checkbox on the page.
0 Since only xpath locators start with â//â, it is not necessary to
include 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 slightest
adjustment to the application. By finding a nearby element with
an id or name attribute (ideally a parent element) you can locate
your target element based on the relationship. This is much less
likely to change and can make your tests more robust.
17. Locating Elements
0 Locating Hyperlinks by Link Text: simple method of locating
a hyperlink in your web page by using the text of the link. If
two links with the same text are present, then the first match
will be used.
0 Locating by DOM: The Document Object Model represents an
HTML document and can be accessed using JavaScript. This
location strategy takes JavaScript that evaluates to an element
on the page, which can be simply the elementâs location using
the hierarchical dotted notation.
0 Since only dom locators start with âdocumentâ, it is not necessary
to include the dom= label when specifying a DOM locator.
18. Locating Elements
0 Locating by CSS: CSS uses Selectors for binding style
properties to elements in the document. These Selectors
can be used by Selenium as another locating strategy.
0 Most experienced Selenium users recommend CSS as their
locating strategy of choice as itâs considerably faster than
XPath and can find the most complicated objects in an
intrinsic HTML document.
19. Locator Assistance
0 Whenever Selenium-IDE records a locator-type
argument, it stores additional information which
allows the user to view other possible locator-type
arguments that could be used instead.
0 This feature can be very useful for learning more
about locators, and is often needed to help one build a
different type of locator than the type that was
recorded.
20. Matching Text Patterns
0 Like locators, patterns are a type of parameter frequently
required by Selenese commands.
0 Examples of commands which require patterns are
0 verifyTextPresent,
0 verifyTitle,
0 verifyAlert,
0 assertConfirmation,
0 verifyText, and
0 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 text
exactly.
21. Matching Text Patterns
0 Three types of patterns:
0 Globbing (Selenium globbing patterns only support the asterisk and
character class)
0 * which translates to âmatch anything,â i.e., nothing, a single character, or
many characters.
0 [ ] (character class) which translates to âmatch any single character found
inside the square brackets.â A dash (hyphen) can be used as a shorthand to
specify a range of characters (which are contiguous in the ASCII character
set).
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 an
actual asterisk character (which is special for both globbing and regular
expression patterns
0 glob:Real * vs exact:Real *
22. User Extensions
0 User extensions are JavaScript files that allow one to
create his or her own customizations and features to
add additional functionality.
0 Often this is in the form of customized commands
although this extensibility is not limited to additional
commands
0 See
http://wiki.openqa.org/display/SEL/Contributed+Us
er-Extensions
23. Sequence of Evaluation and
Flow Control
0 When a script runs, it simply runs in sequence, one
command after another.
0 Selenese, by itself, does not support condition
statements (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 library
such as Java or PHP to utilize the programming
languageâs flow control features.
0 Run a small JavaScript snippet from within the script
using the storeEval command.
0 Install the goto_sel_ide.js extension.
24. A few tips
0 Saving a test suite does not save the test case.
0 Make sure that you save the test case every time you
make a change and not just the test suite.
0 echo - The Selenese Print Command
0 Use Find button to see which UI element on the
currently displayed webpage (in the browser) is used
in the currently selected Selenium command. This is
useful when building a locator for a commandâs first
parameter
26. Selenium Web Driver
0 WebDriver is a tool for automating web application
testing, and in particular to verify that they work as
expected.
0 It aims to provide a friendly API thatâs easy to explore
and understand, easier to use than the Selenium-RC
(1.0) API, which will help to make your tests easier to
read and maintain.
0 Itâs not tied to any particular test framework, so it can
be used equally well in a unit testing or from a plain
old âmainâ method.
27. Selenium Web Driver â
Browser Support
Selenium-WebDriver supports the following browsers along
with the operating systems these browsers are compatible
with.
0 Google Chrome 12.0.712.0+
0 Internet Explorer 6, 7, 8, 9 - 32 and 64-bit where applicable
0 Firefox 3.0, 3.5, 3.6, 4.0, 5.0, 6, 7
0 Opera 11.5+
0 HtmlUnit 2.9
0 Android â 2.3+ for phones and tablets (devices & emulators)
0 iOS 3+ for phones (devices & emulators) and 3.2+ for tablets
(devices & emulators)
28. WebDriver &
Selenium-Server
0 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 not
need the Selenium-Server.
0 If your browser and tests will all run on the same
machine, and your tests only use the WebDriver API,
then you do not need to run the Selenium-Server;
WebDriver will run the browser directly.
29. WebDriver &
Selenium-Server
Some reasons to use the Selenium-Server with
Selenium-WebDriver.
0 You are using Selenium-Grid to distribute your tests
over multiple machines or virtual machines (VMs).
0 You want to connect to a remote machine that has a
particular browser version that is not on your current
machine.
0 You are not using the Java bindings (i.e. Python, C#, or
Ruby) and would like to use HtmlUnit Driver
31. Selenium RC
Selenium RC comes in two
parts.
A server which automatically
launches and kills browsers,
and acts as a HTTP proxy for
web requests from them.
Client libraries for your
favorite computer language.
32. References
0 http://docs.seleniumhq.org/
0 Selenium and Section 508 by David Sills
0 http://java.dzone.com/articles/selenium-and-section-508
0 Selenium Tutorial for Beginner/Tips for Experts
0 http://www.jroller.com/selenium/
0 Get Test-Infected With Selenium
0 http://net.tutsplus.com/tutorials/tools-and-tips/get-test-
infected-with-selenium-2/
0 https://code.google.com/p/selenium/
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.