Skip to content

Instantly share code, notes, and snippets.

@davehunt
Last active Apr 11, 2016
Embed
What would you like to do?
Test installing an add-on using Marionette and Firefox Puppeteer
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from firefox_puppeteer import Puppeteer
from firefox_puppeteer.ui.browser.window import BrowserWindow
from marionette_driver.marionette import Marionette
import pytest
def pytest_addoption(parser):
parser.addoption(
'--base-url',
default='https://addons-dev.allizom.org',
help='base url for the application under test.')
parser.addoption(
'--firefox-path',
default='/usr/local/bin/firefox',
help='path for Firefox binary')
@pytest.fixture(scope='session')
def base_url(request):
"""Return a base URL"""
return request.config.getoption('base_url')
@pytest.fixture
def marionette(request):
marionette = Marionette(bin=request.config.getoption('firefox_path'))
marionette.start_session()
request.addfinalizer(marionette.delete_session)
return marionette
@pytest.fixture
def puppeteer(marionette):
puppeteer = Puppeteer()
puppeteer.marionette = marionette
# enable browser toolbox
puppeteer.prefs.set_pref('devtools.chrome.enabled', True)
puppeteer.prefs.set_pref('devtools.debugger.remote-enabled', True)
# prevent ui popups auto-hiding
puppeteer.prefs.set_pref('ui.popup.disable_autohide', True)
return puppeteer
@pytest.fixture
def firefox(marionette, puppeteer):
firefox = puppeteer.windows.current
with marionette.using_context(marionette.CONTEXT_CHROME):
firefox.focus()
marionette.set_context(marionette.CONTEXT_CONTENT)
return firefox
from urlparse import urlparse
from firefox_puppeteer.ui.browser.notifications import (
AddOnInstallBlockedNotification,
AddOnInstallConfirmationNotification,
AddOnInstallCompleteNotification)
from marionette_driver import By
def test_install(base_url, firefox, marionette):
origin = urlparse(base_url).hostname
add_on = 'MemChaser'
print marionette.session_capabilities
assert False
assert firefox.notification is None
marionette.navigate('{0}/en-US/firefox/addon/{1}/'.format(base_url, add_on.lower()))
marionette.find_element(By.CSS_SELECTOR, '#addon .install-button a').click()
with marionette.using_context(marionette.CONTEXT_CHROME):
if 'allizom' in origin:
firefox.wait_for_notification(AddOnInstallBlockedNotification)
assert 'prevented this site from asking you to install software on your computer.' in firefox.notification.label
firefox.notification.allow()
firefox.wait_for_notification(AddOnInstallConfirmationNotification)
assert origin == firefox.notification.origin
assert 'This site would like to install an add-on' in firefox.notification.label
assert add_on == firefox.notification.add_on
firefox.notification.install()
firefox.wait_for_notification(AddOnInstallCompleteNotification)
assert origin == firefox.notification.origin
assert '{0} has been installed successfully.'.format(add_on) == firefox.notification.label
firefox.notification.close()
@davehunt

This comment has been minimized.

Copy link
Owner Author

@davehunt davehunt commented Apr 11, 2016

See patch on bug 1144873 for required Puppeteer changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment