• Pat Viafore
•ADTRAN
•Past work at TOA Systems
•Python at home
• What is Selenium?
• How Do I Use It?
• Getting Information Off a Page
• Controlling Input
• Advanced Features
• Limitations
• Rejoicing
And what can it do for me?
• Allows scripts to take control of a web browser
• Supports multiple language bindings
• We’ll focus on Python today
• Windows/Linux/MacOS Support
• $> pip install selenium
• Licensed under Apache 2.0
• Easy to use
Selenium
Remote
Control
Selenium 2.0
Selenium IDE
Selenium
Grid
Selenium
Remote
Control
Selenium 2.0
Selenium IDE
Selenium
Grid
• I currently work on an internal web-app
• I use Selenium to drive acceptance tests – making sure
the web page operates as we expect it to
• Database interactions
• Error conditions
• External service tests (e-mail, LDAP, etc.)
• I use Python to “glue” web browser interaction with
system events
• We’re not just limited to acceptance tests
• Automate common tasks you use a web browser for
• Hook up Selenium to data feeds to control web pages
• Hulu
• Pandora
• YouTube
• Take care of things on a schedule
• Pay bills online
• Sign up for more Python Meetings
Enough with the blah, blah, blah….Let’s Code!
• browser.find_element_by_css_selector
• browser.find_element_by_xpath
Because just getting things is boring
• Go to YouTube
• Search for Python programming
• Sort by Recent Date
• Click on a random video
Bring on the cool stuff
• Screenshotting
• Execute arbitrary Javascript code
• browser.execute_script(jsCode)
• Also an async version
• Browser Capabilities
• Proxying
• Navigate to Google Maps
• Move mouse to center of map
• Start scrolling north a bunch
• Move the mouse or press keys through chainable actions
• More options about ActionChains
http://selenium-python.readthedocs.org/en/latest/api.html
• We could use XVFB or something similar on certain
Linux distros
• Instead, we’ll use PhantomJS to create a headless
browser
• Separate JS installation
• We’ll create X threads that do a series of interactions and time
them
There is no such thing as a Silver Bullet
• Why Use Selenium?
• Why Not Mocha?
• Why Not Jasmine?
• Why Not GUI Recorders?
• RESTful Interactions
• Requests does a far better job
• User Interface (UI) testing
• Selenium does offer Location/Size/CSS, but you’ll
probably be rolling your own layer on top of Selenium
to handle UI testing
• Brittle UIs
• UIs change often (classes, ID changes, buttons
changes)
• Can mitigate by providing a wrapper around Selenium
to interact with your site – DRY (Don’t Repeat Yourself)
Principle
Pizza, pizza, pizza!