From 707255b9923ab0e8fa9553afd6c94f0172ccadf8 Mon Sep 17 00:00:00 2001 From: Robert Chira Date: Mon, 1 Sep 2014 09:41:11 +0300 Subject: [PATCH] Bug 1059245 - Update tests and framework to use the new Browser app --- .../gaiatest/apps/browser/app.py | 147 ------------------ .../apps/homescreen/regions/bookmark_menu.py | 4 + .../apps/homescreen/regions/search_panel.py | 3 + .../gaiatest/apps/keyboard/app.py | 5 +- .../apps/{browser => search}/__init__.py | 0 .../gaia-ui-tests/gaiatest/apps/search/app.py | 29 ++++ .../{browser => search}/regions/__init__.py | 0 .../gaiatest/apps/search/regions/browser.py | 67 ++++++++ .../regions/html5_player.py | 0 .../tests/functional/browser/manifest.ini | 2 - .../browser/test_browser_bookmark.py | 13 +- .../browser/test_browser_cell_data.py | 11 +- .../functional/browser/test_browser_lan.py | 9 +- .../browser/test_browser_navigation.py | 9 +- .../test_browser_play_youtube_video.py | 12 +- .../functional/browser/test_browser_search.py | 9 +- .../functional/browser/test_browser_tabs.py | 52 ------- .../test_cost_control_data_alert_mobile.py | 13 +- .../test_cost_control_reset_wifi.py | 15 +- .../gaiatest/tests/tbpl-manifest.ini | 1 - 20 files changed, 159 insertions(+), 242 deletions(-) delete mode 100644 tests/python/gaia-ui-tests/gaiatest/apps/browser/app.py rename tests/python/gaia-ui-tests/gaiatest/apps/{browser => search}/__init__.py (100%) create mode 100644 tests/python/gaia-ui-tests/gaiatest/apps/search/app.py rename tests/python/gaia-ui-tests/gaiatest/apps/{browser => search}/regions/__init__.py (100%) create mode 100644 tests/python/gaia-ui-tests/gaiatest/apps/search/regions/browser.py rename tests/python/gaia-ui-tests/gaiatest/apps/{browser => search}/regions/html5_player.py (100%) delete mode 100644 tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_tabs.py diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/browser/app.py b/tests/python/gaia-ui-tests/gaiatest/apps/browser/app.py deleted file mode 100644 index e9447eec7682..000000000000 --- a/tests/python/gaia-ui-tests/gaiatest/apps/browser/app.py +++ /dev/null @@ -1,147 +0,0 @@ -# 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 re -import time - -from marionette.by import By -from gaiatest.apps.base import Base -from gaiatest.apps.base import PageRegion -from gaiatest.apps.homescreen.regions.bookmark_menu import BookmarkMenu - - -class Browser(Base): - - name = "Browser" - - _browser_frame_locator = (By.CSS_SELECTOR, 'iframe.browser-tab') - _main_screen_locator = (By.ID, 'main-screen') - - # Awesome bar/url bar - _awesome_bar_locator = (By.ID, 'url-input') - _url_button_locator = (By.ID, 'url-button') - _throbber_locator = (By.ID, 'throbber') - - # Tab list area - _tab_badge_locator = (By.ID, 'tabs-badge') - _new_tab_button_locator = (By.ID, 'new-tab-button') - _tabs_list_locator = (By.CSS_SELECTOR, '#tabs-list > ul li a') - - # Browser footer - _back_button_locator = (By.ID, 'back-button') - _forward_button_locator = (By.ID, 'forward-button') - _bookmark_button_locator = (By.ID, 'bookmark-button') - - # Bookmark menu - _bookmark_menu_locator = (By.ID, 'bookmark-menu') - _add_bookmark_to_home_screen_choice_locator = (By.ID, 'bookmark-menu-add-home') - - def launch(self): - Base.launch(self) - self.wait_for_condition(lambda m: m.execute_script("return window.wrappedJSObject.Browser.hasLoaded;")) - - def go_to_url(self, url, timeout=30): - self.wait_for_element_displayed(*self._awesome_bar_locator) - self.marionette.find_element(*self._awesome_bar_locator).tap() - self.keyboard.send(url) - self.tap_go_button(timeout=timeout) - - @property - def url_src(self): - return self.marionette.find_element(*self._browser_frame_locator).get_attribute('src') - - @property - def url(self): - return self.marionette.execute_script("return window.wrappedJSObject.Browser.currentTab.url;") - - def switch_to_content(self): - web_frames = self.marionette.find_elements(*self._browser_frame_locator) - for web_frame in web_frames: - if web_frame.is_displayed(): - self.marionette.switch_to_frame(web_frame) - break - - def switch_to_chrome(self): - self.marionette.switch_to_frame() - self.marionette.switch_to_frame(self.app.frame) - - def tap_go_button(self, timeout=30): - self.marionette.find_element(*self._url_button_locator).tap() - # TODO wait_for_throbber can resolve before the page has started loading - time.sleep(2) - self.wait_for_throbber_not_visible(timeout=timeout) - self.wait_for_element_displayed(*self._bookmark_button_locator) - - def tap_back_button(self): - current_url = self.url - self.marionette.find_element(*self._back_button_locator).tap() - self.wait_for_condition(lambda m: self.url != current_url) - - def tap_forward_button(self): - current_url = self.url - self.marionette.find_element(*self._forward_button_locator).tap() - self.wait_for_condition(lambda m: self.url != current_url) - - def tap_bookmark_button(self): - self.marionette.find_element(*self._bookmark_button_locator).tap() - self.wait_for_element_displayed(*self._bookmark_menu_locator) - - def tap_add_bookmark_to_home_screen_choice_button(self): - self.wait_for_element_displayed(*self._add_bookmark_to_home_screen_choice_locator) - self.marionette.find_element(*self._add_bookmark_to_home_screen_choice_locator).tap() - return BookmarkMenu(self.marionette) - - def wait_for_throbber_not_visible(self, timeout=30): - # TODO see if we can reduce this timeout in the future. >10 seconds is poor UX - self.wait_for_condition(lambda m: not self.is_throbber_visible, timeout=timeout) - - @property - def is_throbber_visible(self): - return self.marionette.find_element(*self._throbber_locator).get_attribute('class') == 'loading' - - @property - def is_awesome_bar_visible(self): - return self.marionette.find_element(*self._awesome_bar_locator).is_displayed() - - def tap_tab_badge_button(self): - self.wait_for_element_displayed(*self._tab_badge_locator) - self.marionette.find_element(*self._tab_badge_locator).tap() - self.wait_for_condition(self.tab_list_loaded()) - - def tap_add_new_tab_button(self): - self.marionette.find_element(*self._new_tab_button_locator).tap() - main_screen = self.marionette.find_element(*self._main_screen_locator) - self.wait_for_condition(lambda m: main_screen.location['x'] == 0) - - @property - def displayed_tabs_number(self): - displayed_number = self.marionette.find_element(*self._tab_badge_locator).text - return int(re.match(r'\d+', displayed_number).group()) - - @property - def tabs_count(self): - return len(self.marionette.find_elements(*self._tabs_list_locator)) - - @property - def tabs(self): - return [self.Tab(marionette=self.marionette, element=tab) - for tab in self.marionette.find_elements(*self._tabs_list_locator)] - - class tab_list_loaded(object): - - def __call__(self, marionette): - el = marionette.find_element(*Browser._main_screen_locator) - locations = [] - for i in range(3): - locations.append(el.location) - time.sleep(0.1) - return locations[1:] == locations[:-1] - - class Tab(PageRegion): - - def tap_tab(self): - self.root_element.tap() - - # TODO This wait is a workaround until Marionette can correctly interpret the displayed state - self.wait_for_condition(lambda m: m.execute_script("return window.wrappedJSObject.Browser.currentScreen;") == 'page-screen') diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/homescreen/regions/bookmark_menu.py b/tests/python/gaia-ui-tests/gaiatest/apps/homescreen/regions/bookmark_menu.py index 2005d1aee338..f6febacc9ce5 100644 --- a/tests/python/gaia-ui-tests/gaiatest/apps/homescreen/regions/bookmark_menu.py +++ b/tests/python/gaia-ui-tests/gaiatest/apps/homescreen/regions/bookmark_menu.py @@ -30,6 +30,10 @@ def tap_add_bookmark_to_home_screen_dialog_button(self): def type_bookmark_title(self, value): element = self.marionette.find_element(*self._bookmark_title_input_locator) + + # Wait for the default value to load into the input field + self.wait_for_condition(lambda m: element.get_attribute('value') != "") element.clear() + self.keyboard.send(value) self.keyboard.dismiss() diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/homescreen/regions/search_panel.py b/tests/python/gaia-ui-tests/gaiatest/apps/homescreen/regions/search_panel.py index cd5f4979da44..76ab73ffe7d3 100644 --- a/tests/python/gaia-ui-tests/gaiatest/apps/homescreen/regions/search_panel.py +++ b/tests/python/gaia-ui-tests/gaiatest/apps/homescreen/regions/search_panel.py @@ -26,6 +26,9 @@ def type_into_search_box(self, search_term): # The search results frame is not findable with AppWindowManager self._switch_to_search_results_frame() + def go_to_url(self, url): + self.keyboard.send(url, self.keyboard._enter_key) + def wait_for_everything_me_results_to_load(self, minimum_expected_results=1): self.wait_for_condition(lambda m: len(m.find_elements(*self._search_results_locator)) > minimum_expected_results) diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/keyboard/app.py b/tests/python/gaia-ui-tests/gaiatest/apps/keyboard/app.py index d3e00d9b48b1..8c1a8ea3cd00 100644 --- a/tests/python/gaia-ui-tests/gaiatest/apps/keyboard/app.py +++ b/tests/python/gaia-ui-tests/gaiatest/apps/keyboard/app.py @@ -215,7 +215,7 @@ def enable_caps_lock(self): self.apps.switch_to_displayed_app() # this would go through fastest way to tap/click through a string - def send(self, string): + def send(self, string, tap_key_at_end=None): self.switch_to_keyboard() for val in string: if ord(val) > 127: @@ -237,6 +237,9 @@ def send(self, string): self._switch_to_correct_layout(val) self._tap(val) + if tap_key_at_end: + self._tap(tap_key_at_end) + self.apps.switch_to_displayed_app() # Switch keyboard language diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/browser/__init__.py b/tests/python/gaia-ui-tests/gaiatest/apps/search/__init__.py similarity index 100% rename from tests/python/gaia-ui-tests/gaiatest/apps/browser/__init__.py rename to tests/python/gaia-ui-tests/gaiatest/apps/search/__init__.py diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/search/app.py b/tests/python/gaia-ui-tests/gaiatest/apps/search/app.py new file mode 100644 index 000000000000..987a6d391bbb --- /dev/null +++ b/tests/python/gaia-ui-tests/gaiatest/apps/search/app.py @@ -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 gaiatest.apps.base import Base +from marionette.by import By + + +class Search(Base): + + name = 'Browser' + + _url_bar_locator = (By.CSS_SELECTOR, 'div.search-app .urlbar .title') + + def launch(self): + Base.launch(self) + self.wait_for_condition(lambda m: self.apps.displayed_app.name == self.name) + self.wait_for_element_displayed(*self._url_bar_locator) + + def go_to_url(self, url): + self.marionette.find_element(*self._url_bar_locator).tap() + + from gaiatest.apps.homescreen.regions.search_panel import SearchPanel + search_panel = SearchPanel(self.marionette) + search_panel.go_to_url(url) + self.wait_for_condition(lambda m: self.apps.displayed_app.name == url) + + from regions.browser import Browser2 + return Browser2(self.marionette) diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/browser/regions/__init__.py b/tests/python/gaia-ui-tests/gaiatest/apps/search/regions/__init__.py similarity index 100% rename from tests/python/gaia-ui-tests/gaiatest/apps/browser/regions/__init__.py rename to tests/python/gaia-ui-tests/gaiatest/apps/search/regions/__init__.py diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/search/regions/browser.py b/tests/python/gaia-ui-tests/gaiatest/apps/search/regions/browser.py new file mode 100644 index 000000000000..49071cf1ca88 --- /dev/null +++ b/tests/python/gaia-ui-tests/gaiatest/apps/search/regions/browser.py @@ -0,0 +1,67 @@ +# 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 gaiatest.apps.base import Base +from marionette.by import By + + +class Browser2(Base): + + _browser_app_locator = (By.CSS_SELECTOR, 'div.browser[transition-state="opened"]') + _browser_frame_locator = (By.CSS_SELECTOR, 'iframe.browser') + + _menu_button_locator = (By.CSS_SELECTOR, '.menu-button') + _add_to_home_button_locator = (By.ID, 'add-to-home') + _browser_menu_locator = (By.CSS_SELECTOR, '.overflow-menu') + + _back_button_locator = (By.CSS_SELECTOR, '.back-button') + _forward_button_locator = (By.CSS_SELECTOR, '.forward-button') + + def __init__(self, marionette): + Base.__init__(self, marionette) + self.marionette.switch_to_frame() + self._root_element = self.marionette.find_element(*self._browser_app_locator) + + def switch_to_content(self): + web_frame = self._root_element.find_element(*self._browser_frame_locator) + self.marionette.switch_to_frame(web_frame) + + def switch_to_chrome(self): + self.marionette.switch_to_frame() + + @property + def is_page_loading(self): + return "loading" in self._root_element.value_of_css_property('class') + + def wait_for_page_to_load(self, timeout=30): + self.wait_for_condition(lambda m: not self.is_page_loading, timeout=timeout) + + def tap_menu_button(self): + self._root_element.find_element(*self._menu_button_locator).tap() + self.wait_for_element_displayed(*self._browser_menu_locator) + + def tap_add_to_home(self): + self.wait_for_element_displayed(*self._add_to_home_button_locator) + self._root_element.find_element(*self._add_to_home_button_locator).tap() + from gaiatest.apps.homescreen.regions.bookmark_menu import BookmarkMenu + + return BookmarkMenu(self.marionette) + + @property + def url(self): + return self._root_element.find_element(*self._browser_frame_locator).get_attribute('data-url') + + @property + def data_origin(self): + return self._root_element.find_element(*self._browser_frame_locator).get_attribute('data-frame-origin') + + def tap_back_button(self): + current_url = self.url + self._root_element.find_element(*self._back_button_locator).tap() + self.wait_for_condition(lambda m: self.url != current_url) + + def tap_forward_button(self): + current_url = self.url + self._root_element.find_element(*self._forward_button_locator).tap() + self.wait_for_condition(lambda m: self.url != current_url) diff --git a/tests/python/gaia-ui-tests/gaiatest/apps/browser/regions/html5_player.py b/tests/python/gaia-ui-tests/gaiatest/apps/search/regions/html5_player.py similarity index 100% rename from tests/python/gaia-ui-tests/gaiatest/apps/browser/regions/html5_player.py rename to tests/python/gaia-ui-tests/gaiatest/apps/search/regions/html5_player.py diff --git a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/manifest.ini b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/manifest.ini index 1079f6134bfe..d8986b3d0a04 100644 --- a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/manifest.ini +++ b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/manifest.ini @@ -19,8 +19,6 @@ lan = true smoketest = true sanity = true -[test_browser_tabs.py] - [test_browser_search.py] [test_browser_navigation.py] diff --git a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_bookmark.py b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_bookmark.py index b993510d0df2..33bb3d471279 100644 --- a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_bookmark.py +++ b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_bookmark.py @@ -5,8 +5,8 @@ import time from gaiatest import GaiaTestCase -from gaiatest.apps.browser.app import Browser from gaiatest.apps.homescreen.app import Homescreen +from gaiatest.apps.search.app import Search class TestBrowserBookmark(GaiaTestCase): @@ -16,6 +16,7 @@ class TestBrowserBookmark(GaiaTestCase): def setUp(self): GaiaTestCase.setUp(self) self.connect_to_network() + self.apps.set_permission('Browser', 'geolocation', 'deny') if self.device.is_desktop_b2g or self.data_layer.is_wifi_connected(): self.test_url = self.marionette.absolute_url('mozilla.html') @@ -26,13 +27,13 @@ def setUp(self): self.bookmark_title = 'gaia%s' % curr_time[10:] def test_browser_bookmark(self): - browser = Browser(self.marionette) - browser.launch() + search = Search(self.marionette) + search.launch() - browser.go_to_url(self.test_url) - browser.tap_bookmark_button() + browser = search.go_to_url(self.test_url) + browser.tap_menu_button() + bookmark = browser.tap_add_to_home() - bookmark = browser.tap_add_bookmark_to_home_screen_choice_button() bookmark.type_bookmark_title(self.bookmark_title) bookmark.tap_add_bookmark_to_home_screen_dialog_button() diff --git a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_cell_data.py b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_cell_data.py index 7f68e00d36ff..19549a591566 100644 --- a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_cell_data.py +++ b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_cell_data.py @@ -5,7 +5,7 @@ from marionette.by import By from gaiatest import GaiaTestCase -from gaiatest.apps.browser.app import Browser +from gaiatest.apps.search.app import Search class TestBrowserCellData(GaiaTestCase): @@ -14,15 +14,18 @@ class TestBrowserCellData(GaiaTestCase): def setUp(self): GaiaTestCase.setUp(self) + self.apps.set_permission('Browser', 'geolocation', 'deny') + self.data_layer.connect_to_cell_data() def test_browser_cell_data(self): """https://moztrap.mozilla.org/manage/case/1328/""" - browser = Browser(self.marionette) - browser.launch() + search = Search(self.marionette) + search.launch() - browser.go_to_url('http://mozqa.com/data/firefox/layout/mozilla.html', timeout=120) + browser = search.go_to_url('http://mozqa.com/data/firefox/layout/mozilla.html') + browser.wait_for_page_to_load(120) browser.switch_to_content() diff --git a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_lan.py b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_lan.py index 24c478be1e12..636b1b70c036 100644 --- a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_lan.py +++ b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_lan.py @@ -5,7 +5,7 @@ from marionette import Wait from gaiatest import GaiaTestCase -from gaiatest.apps.browser.app import Browser +from gaiatest.apps.search.app import Search class TestBrowserLAN(GaiaTestCase): @@ -13,6 +13,7 @@ class TestBrowserLAN(GaiaTestCase): def setUp(self): GaiaTestCase.setUp(self) self.connect_to_local_area_network() + self.apps.set_permission('Browser', 'geolocation', 'deny') if self.device.is_desktop_b2g or self.data_layer.is_wifi_connected(): self.test_url = self.marionette.absolute_url('mozilla.html') @@ -21,8 +22,8 @@ def setUp(self): def test_browser_lan(self): """https://moztrap.mozilla.org/manage/case/1327/""" - browser = Browser(self.marionette) - browser.launch() - browser.go_to_url(self.test_url) + search = Search(self.marionette) + search.launch() + browser = search.go_to_url(self.test_url) browser.switch_to_content() Wait(self.marionette).until(lambda m: m.title == 'Mozilla') diff --git a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_navigation.py b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_navigation.py index c5b12511c4f1..0f74b36c653c 100644 --- a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_navigation.py +++ b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_navigation.py @@ -6,7 +6,7 @@ from marionette import Wait from gaiatest import GaiaTestCase -from gaiatest.apps.browser.app import Browser +from gaiatest.apps.search.app import Search class TestBrowserNavigation(GaiaTestCase): @@ -14,6 +14,7 @@ class TestBrowserNavigation(GaiaTestCase): def setUp(self): GaiaTestCase.setUp(self) self.connect_to_network() + self.apps.set_permission('Browser', 'geolocation', 'deny') if self.device.is_desktop_b2g or self.data_layer.is_wifi_connected(): self.test_url = self.marionette.absolute_url('mozilla.html') @@ -21,9 +22,9 @@ def setUp(self): self.test_url = 'http://mozqa.com/data/firefox/layout/mozilla.html' def test_browser_back_button(self): - browser = Browser(self.marionette) - browser.launch() - browser.go_to_url(self.test_url) + search = Search(self.marionette) + search.launch() + browser = search.go_to_url(self.test_url) browser.switch_to_content() Wait(self.marionette).until(lambda m: m.title == 'Mozilla') diff --git a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_play_youtube_video.py b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_play_youtube_video.py index a09ec0639a02..85c94eca3aca 100644 --- a/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_play_youtube_video.py +++ b/tests/python/gaia-ui-tests/gaiatest/tests/functional/browser/test_browser_play_youtube_video.py @@ -4,8 +4,8 @@ from marionette.by import By from gaiatest import GaiaTestCase -from gaiatest.apps.browser.app import Browser -from gaiatest.apps.browser.regions.html5_player import HTML5Player +from gaiatest.apps.search.app import Search +from gaiatest.apps.search.regions.html5_player import HTML5Player class TestYouTube(GaiaTestCase): @@ -20,15 +20,17 @@ class TestYouTube(GaiaTestCase): def setUp(self): GaiaTestCase.setUp(self) self.connect_to_network() + self.apps.set_permission('Browser', 'geolocation', 'deny') def test_play_youtube_video(self): """Confirm YouTube video playback https://moztrap.mozilla.org/manage/case/6073/ """ - browser = Browser(self.marionette) - browser.launch() - browser.go_to_url(self.video_URL, timeout=180) + search = Search(self.marionette) + search.launch() + browser = search.go_to_url(self.video_URL) + browser.wait_for_page_to_load(180) browser.switch_to_content() # Tap the video container to load the