Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Merge remote branch 'upstream/master' into methods_return_pages-kb
Browse files Browse the repository at this point in the history
  • Loading branch information
klrmn committed Mar 22, 2012
2 parents 49a4d35 + f940c51 commit 453d158
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pages/mobile/base.py
@@ -0,0 +1,46 @@
#!/usr/bin/env python

# 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 pages.page import Page


class Base(Page):

@property
def header(self):
return Base.HeaderRegion(self.testsetup)

class HeaderRegion(Page):

_dropdown_expanded_menu_locator = (By.CSS_SELECTOR, 'div.moz-menu')
_menu_items_locator = (By.CSS_SELECTOR, '.menu-items li')
_menu_button_locator = (By.CSS_SELECTOR, '.tab > a')

def click_header_menu(self):
self.selenium.find_element(*self._menu_button_locator).click()

@property
def is_dropdown_menu_expanded(self):
return "expand" in self.selenium.find_element(*self._dropdown_expanded_menu_locator).get_attribute('class')

@property
def dropdown_menu_items(self):
#returns a list containing all the menu items
return [self.MenuItem(self.testsetup, web_element) for web_element in self.selenium.find_elements(*self._menu_items_locator)]

class MenuItem(Page):

_name_items_locator = (By.CSS_SELECTOR, 'a')

def __init__(self, testsetup, element):
Page.__init__(self, testsetup)
self._root_element = element

@property
def name(self):
return self._root_element.find_element(*self._name_items_locator).text
28 changes: 28 additions & 0 deletions pages/mobile/home.py
@@ -0,0 +1,28 @@
#!/usr/bin/env python

# 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 pages.mobile.base import Base


class Home(Base):

_page_title = 'Firefox for Mobile Support Home Page | Firefox Help'

_header_locator = (By.CSS_SELECTOR, 'h1.site-title > a')

def __init__(self, testsetup):
Base.__init__(self, testsetup)
self.selenium.get(self.base_url)

@property
def header_text(self):
return self.selenium.find_element(*self._header_locator).text

@property
def header_title(self):
return self.selenium.find_element(*self._header_locator).get_attribute('title')
36 changes: 36 additions & 0 deletions tests/mobile/test_homepage.py
@@ -0,0 +1,36 @@
#!/usr/bin/env python

# 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 pytest

from unittestzero import Assert

from pages.mobile.home import Home


class TestHome:

expected_menu_items = ['MOZILLA FIREFOX', 'FEATURES', 'DESKTOP', 'ADD-ONS', 'SUPPORT', 'VISIT MOZILLA']

@pytest.mark.nondestructive
def test_the_expandable_header_menu(self, mozwebqa):
home = Home(mozwebqa)
home.header.click_header_menu()
Assert.true(home.header.is_dropdown_menu_expanded)

menu_names = [menu.name for menu in home.header.dropdown_menu_items]
Assert.equal(menu_names, self.expected_menu_items)

home.header.click_header_menu()
Assert.false(home.header.is_dropdown_menu_expanded)

@pytest.mark.nondestructive
def test_the_header_text_and_page_title(self, mozwebqa):
home = Home(mozwebqa)
home.is_the_current_page

Assert.equal('Firefox Help\nfor Mobile', home.header_text)
Assert.equal('Return to Firefox Support homepage', home.header_title)

0 comments on commit 453d158

Please sign in to comment.