Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Automation With Selenium
1. Trivia:
Selenium has a strong bonding affinity with mercury and arsenic, so if you eat
fish, it’s a good idea to choose types of fish high in selenium.
But although it’s a necessary nutrient, more than a trace amount of it will have
you pushing up daisies in a heartbeat.
(Or lack thereof.)
The name for the Selenium, the browser automation tool, comes from a joke
made by founders in an email, mocking their competitor “Mercury” – since
selenium is a cure for mercury poisoning. The rest of the devs took it and ran
with it.
2. What’s Selenium?
Selenium automates browsers for testing purposes, and also can be
used for automating mind-numbing, soul-crushing tasks (like searching
for “new” users in PUMA and changing their status to “active”).
The primary products are Selenium IDE, Selenium WebDriver (aka
Selenium 2), and Selenium Server.
Examples/info based on using Java w/Eclipse ( v. Kepler has Maven
integrated – Maven will import all necessary Se dependencies), Firebug
(cool inspection tool), Firepath
3. Selenium Server needs to be used for:
• Distributing tests over multiple machines or VMs at once
• Connecting to a remote machine that has a browser version that’s not
on your specific machine
• Instructions for Java at
http://code.google.com/p/selenium/wiki/Grid2
4. Selenium IDE
• Runs as a Firefox add-on and can
record, edit, play, and debug tests.
• Can record user actions or be edited by hand, then played back as browser
emulation. It’s as though a ghost were using your computer! Aaaagh!!!
• It can be experimentally exported in several code languages
• Brilliant if you need to script a ton of crap, super fast (see February VA
move)
• Creates a good, lightning-fast base for any automated, which can then be
coded as necessary
• It’s a nice introduction to Selenese, Selenium’s set of commands
6. Selenium IDE limitations
• No conditional or looping statements
• Limited to Firefox out of the box
• Formatted reporting not supported
• Uses html language – exporting in others is currently ‘experimental’ –
tends to import defunct dependencies and other extraneous crap
• Can’t read from external databases or files
7. Selenium Webdriver (aka Se 2)
• It’s a collection of bindings which drives browsers natively as a user
would, either locally or remotely with Selenium Server
• It makes direct calls to a browser using the browser’s native support
for automation
• Can be used in Java (recommended), C#, Perl, PHP, Python, and Ruby
• Has WebDrivers for IE, Chrome, Firefox, Safari, IOS, Android and
Opera. Chrome and IE require a separate server download.
8. Webdriver has a few limitations…
• Like everything else, has a few bugs
• It’s Open Source – tech problems need
to be resolved through Se community,
and you’re on your own to learn it
• Can only automate web applications
• No inbuilt reporting capabilities
• IE, and to a lesser extent, Chrome, can
be buggy (recall that it uses a browsers
native support for automation…..)
9. What can Webdriver do?
• Finding, retrieving, and verifying/asserting web elements by
Name, ID, TagName, Class, LinkText, PartialLinkText, Xpath, and CSS
• Mouse-based interactions including mouse position by absolute (using x,y)
or relative, clicking at current or specified locations or elements, click and
hold, release, drag and drop, double click, right click
• Keyboard interactions: Typing text, multiple keys (such as Ctrl +
PrntScrn), key up/down
• Taking screenshots, accepting security alerts, locating/switching between
windows, executing custom Javascript, enabling browsers to interact with
window alerts, navigating back/forward, implicit/explicit
waits, downloading/copying files, permissioning files to be executable and
much more both universal and specific to individual browsers
10. Success!
Generic success output –
everything works as
expected. Success and
fail reports can be coded
with as much or little
detail as you like by
conditional output to the
console.
11. Example of failed test;
element “Agout” not found.
Problematic line on
failure trace, below –
Assertion Error.
12. Selenium website – seleniumhq.org
The website will tell you where to download
and how to set it up (but not how
to use it).
Helpful book on Selenium for developers
using java:
“Selenium Webdriver Practical Guide”
by Satya Avasarala
If you’d like to use Selenium, make sure you don’t seek out any info
before about 6 months ago. It always changes fast, but in the last few
months has undergone huge changes. Search on “Selenium
Webdriver”.