From aa95a9e63124dec139bc50d261e2c585cf92e7a8 Mon Sep 17 00:00:00 2001 From: Teodosia Date: Thu, 22 Mar 2012 13:01:30 +0200 Subject: [PATCH 1/2] [mobile]Test for checking the header text and title Added new: - base.py (empty at the moment, but it will be needed in the next pull) - home.py - test_homepage.py --- pages/mobile/base.py | 14 ++++++++++++++ pages/mobile/home.py | 28 ++++++++++++++++++++++++++++ tests/mobile/test_homepage.py | 22 ++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 pages/mobile/base.py create mode 100644 pages/mobile/home.py create mode 100644 tests/mobile/test_homepage.py diff --git a/pages/mobile/base.py b/pages/mobile/base.py new file mode 100644 index 0000000..4181144 --- /dev/null +++ b/pages/mobile/base.py @@ -0,0 +1,14 @@ +#!/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): + + pass diff --git a/pages/mobile/home.py b/pages/mobile/home.py new file mode 100644 index 0000000..b71b92c --- /dev/null +++ b/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') diff --git a/tests/mobile/test_homepage.py b/tests/mobile/test_homepage.py new file mode 100644 index 0000000..26d382b --- /dev/null +++ b/tests/mobile/test_homepage.py @@ -0,0 +1,22 @@ +#!/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: + + @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) From 7d14d48834bcb55988303180198c7971ffe36944 Mon Sep 17 00:00:00 2001 From: Teodosia Date: Thu, 22 Mar 2012 16:11:35 +0200 Subject: [PATCH 2/2] [mobile]Test to check the expandable header menu --- pages/mobile/base.py | 46 +++++++++++++++++++++++++++++++++++ pages/mobile/home.py | 28 +++++++++++++++++++++ tests/mobile/test_homepage.py | 28 +++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 pages/mobile/base.py create mode 100644 pages/mobile/home.py create mode 100644 tests/mobile/test_homepage.py diff --git a/pages/mobile/base.py b/pages/mobile/base.py new file mode 100644 index 0000000..325e39b --- /dev/null +++ b/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 diff --git a/pages/mobile/home.py b/pages/mobile/home.py new file mode 100644 index 0000000..b71b92c --- /dev/null +++ b/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') diff --git a/tests/mobile/test_homepage.py b/tests/mobile/test_homepage.py new file mode 100644 index 0000000..9d636a8 --- /dev/null +++ b/tests/mobile/test_homepage.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/. + +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)