Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions foxpuppet/windows/browser/navbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class NavBar(Region):

_tracking_protection_shield_locator = (By.ID, 'tracking-protection-icon')

@property
def extensions(self):
"""List of current extensions installed."""
return self.Extensions(self, self.root).extensions_list

@property
def is_tracking_shield_displayed(self):
"""Tracking Protection shield.
Expand All @@ -34,3 +39,39 @@ def is_tracking_shield_displayed(self):
el = self.selenium.find_element(
*self._tracking_protection_shield_locator)
return bool(el.get_attribute('state'))

class Extensions(Region):
"""Representation of the extension secrtion of the navbar."""

_extension_locator = (By.CLASS_NAME, 'webextension-browser-action')

@property
def extensions_list(self):
"""List of current extensions installed."""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
els = self.selenium.find_elements(*self._extension_locator)
return [self.Extension(self, el) for el in els]

class Extension(Region):
"""Representation of a single extension."""

@property
def name(self):
"""Extension name."""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
return self.root.get_attribute('label')

def click(self):
"""Click on the extension."""
handles = len(self.selenium.window_handles)
with self.selenium.context(self.selenium.CONTEXT_CHROME):
self.root.click()
# Wait for tab to open
self.wait.until(
lambda _: len(self.selenium.window_handles) != handles)
# Switch to tab
self.selenium.switch_to.window(
self.selenium.window_handles[-1])
# Wait for the URL request to process
self.wait.until(
lambda _: self.selenium.current_url != 'about:blank')
66 changes: 66 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import pytest
from foxpuppet import FoxPuppet
from foxpuppet.windows.browser.notifications.addons import ( # noqa: I001
AddOnInstallBlocked, # noqa: I001
AddOnInstallComplete, # noqa: I001
AddOnInstallConfirmation) # noqa: I001


@pytest.mark.hookwrapper
Expand Down Expand Up @@ -45,3 +49,65 @@ def browser(foxpuppet):
def foxpuppet(selenium):
"""Initialize the FoxPuppet object."""
return FoxPuppet(selenium)


@pytest.fixture
def firefox_options(firefox_options):
"""Fixture for configuring Firefox."""
# Due to https://bugzilla.mozilla.org/show_bug.cgi?id=1329939 we need the
# initial browser window to be in the foreground. Without this, the
# notifications will not be displayed.
firefox_options.add_argument('-foreground')
return firefox_options


@pytest.fixture
def addon():
"""Fixture for creating an installable add-on.

Returns:
:py:class:`AddOn`: Add-on object containing a name and a path to the
add-on.

"""
class AddOn(object):
name = 'WebExtension'
path = 'webextension.xpi'
return AddOn()


@pytest.fixture
def blocked_notification(addon, browser, webserver, selenium):
"""Fixture causing a blocked notification to appear in Firefox.

Returns:
:py:class:`AddOnInstallBlocked`: Firefox notification.

"""
selenium.get(webserver.url())
selenium.find_element_by_link_text(addon.path).click()
return browser.wait_for_notification(AddOnInstallBlocked)


@pytest.fixture
def confirmation_notification(browser, blocked_notification):
"""Fixture that allows an add-on to be installed.

Returns:
:py:class:`AddOnInstallConfirmation`: Firefox notification.

"""
blocked_notification.allow()
return browser.wait_for_notification(AddOnInstallConfirmation)


@pytest.fixture
def complete_notification(browser, confirmation_notification):
"""Fixture that installs an add-on.

Returns:
:py:class:`AddOnInstallComplete` Firefox notification.

"""
confirmation_notification.install()
return browser.wait_for_notification(AddOnInstallComplete)
9 changes: 9 additions & 0 deletions tests/test_browser_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ def test_tracking_protection_shield(foxpuppet, selenium):
selenium.get('https://www.washingtonpost.com/')
WebDriverWait(selenium, timeout=5).until(
lambda _: browser.navbar.is_tracking_shield_displayed)


def test_opening_a_webextension(foxpuppet, selenium, complete_notification):
"""Test clicking on an installed WebExtension."""
browser = foxpuppet.browser
extensions = browser.navbar.extensions
assert 'WebExtension' in extensions[0].name
extensions[0].click()
assert 'https://developer.mozilla.org/' in selenium.current_url
62 changes: 0 additions & 62 deletions tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,6 @@
AddOnInstallConfirmation) # noqa: I001


@pytest.fixture
def firefox_options(firefox_options):
"""Fixture for configuring Firefox."""
# Due to https://bugzilla.mozilla.org/show_bug.cgi?id=1329939 we need the
# initial browser window to be in the foreground. Without this, the
# notifications will not be displayed.
firefox_options.add_argument('-foreground')
return firefox_options


@pytest.fixture
def addon():
"""Fixture for creating an installable add-on.

Returns:
:py:class:`AddOn`: Add-on object containing a name and a path to the
add-on.

"""
class AddOn(object):
name = 'WebExtension'
path = 'webextension.xpi'
return AddOn()


@pytest.fixture
def blocked_notification(addon, browser, webserver, selenium):
"""Fixture causing a blocked notification to appear in Firefox.

Returns:
:py:class:`AddOnInstallBlocked`: Firefox notification.

"""
selenium.get(webserver.url())
selenium.find_element_by_link_text(addon.path).click()
return browser.wait_for_notification(AddOnInstallBlocked)


@pytest.fixture
def confirmation_notification(browser, blocked_notification):
"""Fixture that allows an add-on to be installed.

Returns:
:py:class:`AddOnInstallConfirmation`: Firefox notification.

"""
blocked_notification.allow()
return browser.wait_for_notification(AddOnInstallConfirmation)


@pytest.fixture
def complete_notification(browser, confirmation_notification):
"""Fixture that installs an add-on.

Returns:
:py:class:`AddOnInstallComplete` Firefox notification.

"""
confirmation_notification.install()
return browser.wait_for_notification(AddOnInstallComplete)


def test_open_close_notification(browser, blocked_notification):
"""Trigger and dismiss a notification."""
assert blocked_notification is not None
Expand Down
Binary file modified tests/web/webextension.xpi
Binary file not shown.