Skip to content

Instantly share code, notes, and snippets.

@davehunt
Last active May 13, 2016 16:15
Show Gist options
  • Save davehunt/61f5a54982821e920818d61c8e034751 to your computer and use it in GitHub Desktop.
Save davehunt/61f5a54982821e920818d61c8e034751 to your computer and use it in GitHub Desktop.
Installing an add-on using Selenium
# 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/.
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as expected
from selenium.webdriver.support.ui import WebDriverWait as Wait
import pytest
from pages.desktop.home import Home
@pytest.fixture
def firefox_profile(firefox_profile):
firefox_profile.set_preference('browser.tabs.remote.force-enable', True)
firefox_profile.set_preference('ui.popup.disable_autohide', True)
firefox_profile.update_preferences()
return firefox_profile
@pytest.mark.nondestructive
@pytest.mark.capabilities(marionette=True)
def test_install_extension(base_url, selenium, firefox_profile, capabilities):
"""Install an extension"""
page = Home(selenium, base_url).open()
addon_page = page.most_popular.extensions[0].click()
addon_page.click_add_to_firefox()
selenium.set_context('chrome')
notification = Wait(selenium, 10).until(
expected.presence_of_element_located((
By.ID, 'addon-install-confirmation-notification')))
time.sleep(10)
# Wait(selenium, 10).until(expected.visibility_of(notification))
notification.find_element(
By.ID, 'addon-install-confirmation-accept').click()
notification = Wait(selenium, 10).until(
expected.presence_of_element_located((
By.ID, 'addon-install-complete-notification')))
# Wait(selenium, 10).until(expected.visibility_of(notification))
time.sleep(10)
notification.find_element(
By.ANON_ATTRIBUTE, {'anonid': 'closebutton'}).click()
@davehunt
Copy link
Author

davehunt commented May 13, 2016

Requires pytest, pytest-selenium, and a command line such as:

py.test --driver Firefox \
--driver-path ~/Downloads/wires-0.7.1 \
--capability binary /Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin \
--base-url https://addons-dev.allizom.org \
test_install.py 

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