Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Add tracking protection API (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbenny35 authored and davehunt committed Jul 18, 2017
1 parent 26b3c69 commit 9c01d08
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
1 change: 0 additions & 1 deletion foxpuppet/windows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ def close(self):

def switch_to(self):
"""Switches focus for Selenium commands to this window."""

self.selenium.switch_to.window(self.handle)
29 changes: 29 additions & 0 deletions foxpuppet/windows/browser/navbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 selenium.webdriver.common.by import By

from foxpuppet.region import Region


class NavBar(Region):

"""Representation of the Navigation Bar
:param window: Window object this region appears in.
:param root: element that serves as the root for the region.
:type window: :py:class:`~.windows.BaseWindow`
:type root: :py:class:`~selenium.webdriver.remote.webelement.WebElement`
"""
_tracking_protection_shield_locator = (By.ID, 'tracking-protection-icon')

@property
def is_tracking_shield_displayed(self):
"""Tracking Protection shield
:returns: True or False if the Tracking Shield is displayed
:type return: boolean
"""
with self.selenium.context(self.selenium.CONTEXT_CHROME):
el = self.selenium.find_element(
*self._tracking_protection_shield_locator)
return bool(el.get_attribute('state'))
12 changes: 12 additions & 0 deletions foxpuppet/windows/browser/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from foxpuppet import expected
from foxpuppet.windows import BaseWindow
from foxpuppet.windows.browser.navbar import NavBar
from foxpuppet.windows.browser.notifications import BaseNotification


Expand All @@ -23,6 +24,17 @@ class BrowserWindow(BaseWindow):
By.CSS_SELECTOR, '#notification-popup popupnotification')
_tab_browser_locator = (By.ID, 'tabbrowser-tabs')

@property
def navbar(self):
"""Provides access to the Navigation Bar.
:returns: :py:class:`~foxpuppet.windows.browser.navbar.NavBar`
:return type: object
"""
window = BaseWindow(self.selenium, self.selenium.current_window_handle)
with self.selenium.context(self.selenium.CONTEXT_CHROME):
el = self.selenium.find_element(*self._nav_bar_locator)
return NavBar(window, el)

@property
def notification(self):
"""Provides access to the currently displayed notification."""
Expand Down
14 changes: 13 additions & 1 deletion tests/test_browser_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# 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 pytest
from selenium.webdriver.support.wait import WebDriverWait


def test_initial_browser_window(foxpuppet):
"""Tests initial state of browser windows"""
Expand Down Expand Up @@ -36,7 +39,16 @@ def test_close_window(foxpuppet):
def test_switch_to(foxpuppet, selenium):
"""Test Switch to function"""
foxpuppet.browser.open_window()

# Switch to originally window opened by pytest
foxpuppet.browser.switch_to()
assert foxpuppet.browser.handle == selenium.current_window_handle


@pytest.mark.firefox_preferences({'privacy.trackingprotection.enabled': True})
def test_tracking_protection_shield(foxpuppet, selenium):
"""Tests if the tracking protection icon displays"""
browser = foxpuppet.browser
assert not browser.navbar.is_tracking_shield_displayed
selenium.get('https://www.washingtonpost.com/')
WebDriverWait(selenium, timeout=5).until(
lambda _: browser.navbar.is_tracking_shield_displayed)

0 comments on commit 9c01d08

Please sign in to comment.