SlideShare une entreprise Scribd logo
1  sur  34
“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
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
Selenium World
Which tool to use?
Selenium IDE
Installing Selenium IDE
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
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.
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
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.
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.
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
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).
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.
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.
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.
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.
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.
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 *
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
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.
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
Selenium IDE - Limitations
0 Firefox only
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.
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)
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.
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
Selenium WebDriver - .NET
0 http://www.nuget.org/packages/Selenium.WebDriver
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.
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/
Books
Thanks
&
enjoy the rest of the code
camp 

Contenu connexe

Similaire à Automate Browser Testing with Selenium

Automated_Testing_Selenium
Automated_Testing_SeleniumAutomated_Testing_Selenium
Automated_Testing_SeleniumJagdish Kaushal
 
How to use selenium locators effectively for web automation.pdf
How to use selenium locators effectively for web automation.pdfHow to use selenium locators effectively for web automation.pdf
How to use selenium locators effectively for web automation.pdfpcloudy2
 
Selenium
SeleniumSelenium
Seleniumeduquer
 
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...Simplilearn
 
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlotInterview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlotLearning Slot
 
Selenium corporate-training-in-mumbai
Selenium corporate-training-in-mumbaiSelenium corporate-training-in-mumbai
Selenium corporate-training-in-mumbaivibrantuser
 
Selenium corporate-training-in-mumbai
Selenium corporate-training-in-mumbaiSelenium corporate-training-in-mumbai
Selenium corporate-training-in-mumbaivibrantuser
 
Selenium-corporate-training-in-mumbai
Selenium-corporate-training-in-mumbaiSelenium-corporate-training-in-mumbai
Selenium-corporate-training-in-mumbaiUnmesh Baile
 
Top 30 Selenium Interview Questions.pptx
Top 30 Selenium Interview Questions.pptxTop 30 Selenium Interview Questions.pptx
Top 30 Selenium Interview Questions.pptxSyntax Technologies
 
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDETDevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDETDevLabs Alliance
 
Dev labs alliance top 50 selenium interview questions for SDET
Dev labs alliance top 50 selenium interview questions for SDETDev labs alliance top 50 selenium interview questions for SDET
Dev labs alliance top 50 selenium interview questions for SDETdevlabsalliance
 
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDETDevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDETDevLabs Alliance
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersAjit Jadhav
 
Seleniuminterviewquestions
Seleniuminterviewquestions Seleniuminterviewquestions
Seleniuminterviewquestions laxmiraj01
 

Similaire à Automate Browser Testing with Selenium (20)

Automated_Testing_Selenium
Automated_Testing_SeleniumAutomated_Testing_Selenium
Automated_Testing_Selenium
 
Selenium and The Grinder
Selenium and The GrinderSelenium and The Grinder
Selenium and The Grinder
 
How to use selenium locators effectively for web automation.pdf
How to use selenium locators effectively for web automation.pdfHow to use selenium locators effectively for web automation.pdf
How to use selenium locators effectively for web automation.pdf
 
Selenium
SeleniumSelenium
Selenium
 
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
Selenium Interview Questions And Answers | Selenium Interview Questions | Sel...
 
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlotInterview question & Answers for 3+ years experienced in Selenium | LearningSlot
Interview question & Answers for 3+ years experienced in Selenium | LearningSlot
 
Selenium
SeleniumSelenium
Selenium
 
Selenium corporate-training-in-mumbai
Selenium corporate-training-in-mumbaiSelenium corporate-training-in-mumbai
Selenium corporate-training-in-mumbai
 
Selenium corporate-training-in-mumbai
Selenium corporate-training-in-mumbaiSelenium corporate-training-in-mumbai
Selenium corporate-training-in-mumbai
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
 
Selenium-corporate-training-in-mumbai
Selenium-corporate-training-in-mumbaiSelenium-corporate-training-in-mumbai
Selenium-corporate-training-in-mumbai
 
Top 30 Selenium Interview Questions.pptx
Top 30 Selenium Interview Questions.pptxTop 30 Selenium Interview Questions.pptx
Top 30 Selenium Interview Questions.pptx
 
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDETDevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
 
Dev labs alliance top 50 selenium interview questions for SDET
Dev labs alliance top 50 selenium interview questions for SDETDev labs alliance top 50 selenium interview questions for SDET
Dev labs alliance top 50 selenium interview questions for SDET
 
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDETDevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
 
Selenium (2)
Selenium (2)Selenium (2)
Selenium (2)
 
Selenium (2)
Selenium (2)Selenium (2)
Selenium (2)
 
Selenium Overview
Selenium OverviewSelenium Overview
Selenium Overview
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 
Seleniuminterviewquestions
Seleniuminterviewquestions Seleniuminterviewquestions
Seleniuminterviewquestions
 

Dernier

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Dernier (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

Automate Browser Testing with Selenium

  • 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
  • 25. Selenium IDE - Limitations 0 Firefox only
  • 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
  • 30. Selenium WebDriver - .NET 0 http://www.nuget.org/packages/Selenium.WebDriver
  • 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/
  • 33. Books
  • 34. Thanks & enjoy the rest of the code camp 

Notes de l'éditeur

  1. 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.