Firefox: The Puppet Show

Automating Firefox with WebDriver using Selenium and GeckoDriver

Topics

Browser automation with Selenium

What is Firefox Driver?

Marionette & GeckoDriver

Introducing FoxPuppet

Browser automation
with Selenium

Selenium

  • Suite of tools for browser automation
  • Supports all major web browsers
  • Clients provide the WebDriver API
  • Officially supports several clients:
    • Python, Java, Ruby, JavaScript, & .NET

What is Firefox Driver?

Firefox Driver

  • Specific driver to control Firefox
  • Works through a Firefox add-on
  • Maintained by the Selenium community

Example


from selenium.webdriver import Firefox

selenium = Firefox()
selenium.get('https://addons.mozilla.org')
selenium.find_element_by_id('search-q').send_keys('DuckDuckGo Plus')
selenium.find_element_by_class_name('search-button').click()
          

Deprecated due to
add-on signing in Firefox 48

How to solve this problem?

Marionette & GeckoDriver

Marionette

  • Introduced in 2012 for Firefox OS
  • Automation framework for Gecko
  • Directly built into Firefox and Fennec
  • Can control both chrome and content
  • Communicates via TCP sockets

GeckoDriver

  • Proxy for W3C WebDriver and Gecko
  • HTTP API complies with WebDriver spec
  • Translates calls for use with Marionette
  • Not feature complete yet

Introducing FoxPuppet

Interact with Firefox using Selenium!

FoxPuppet

  • Python package with a simple API
  • Locate and interact with the Firefox UI
  • Supports latest Firefox releases
  • Will be used to test Firefox itself

Without FoxPuppet


from selenium.webdriver import Firefox

selenium = Firefox()
selenium.get('http://addons.mozilla.org/addon/duckduckgo-for-firefox')
selenium.find_element_by_css_selector('#addon .installer').click()
with selenium.context(selenium.CONTEXT_CHROME):
    notification = selenium.find_element_by_css_selector(
        '#addon-install-confirmation-notification')
    notification.find_anonymous_element_by_attribute(
        'anonid', 'button').click()
    notification = selenium.find_element_by_css_selector(
        '#addon-install-complete-notification')
    notification.find_anonymous_element_by_attribute(
        'anonid', 'closebutton').click()
          

With FoxPuppet


from foxpuppet import FoxPuppet
from foxpuppet.windows.browser.notifications.addons import (
    AddOnInstallComplete, AddOnInstallConfirmation)
from selenium.webdriver import Firefox

selenium = Firefox()
browser = FoxPuppet(selenium).browser
selenium.get('http://addons.mozilla.org/addon/duckduckgo-for-firefox')
selenium.find_element_by_css_selector('#addon .installer').click()
browser.wait_for_notification(AddOnInstallConfirmation).install()
browser.wait_for_notification(AddOnInstallComplete).close()
          

Q&A

Thanks

Slides: https://bit.ly/17-puppetshow


Dave Hunt <dhunt@mozilla.com>
http://davehunt.co.uk/

Henrik Skupin <hskupin@mozilla.com>
https://hskupin.info/