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

Commit

Permalink
Merge pull request #26724 from davehunt/bug1074117-phone
Browse files Browse the repository at this point in the history
Bug 1074117 - Use expected conditions and optimise element lookups in phone app object
  • Loading branch information
Florin Strugariu committed Jan 19, 2015
2 parents d8bcb2c + fa92d23 commit 3060d16
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 50 deletions.
32 changes: 20 additions & 12 deletions tests/python/gaia-ui-tests/gaiatest/apps/phone/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def keypad(self):

def _switch_to_contacts_frame(self):
# This is a nested frame and we cannot locate it with AppWindowManager
frame = self.wait_for_element_present(*self._contacts_frame_locator)
frame = Wait(self.marionette).until(
expected.element_present(*self._contacts_frame_locator))
self.marionette.switch_to_frame(frame)

from gaiatest.apps.contacts.app import Contacts
Expand Down Expand Up @@ -75,28 +76,35 @@ def confirmation_dialog_text(self):
return self.marionette.find_element(*self._dialog_title_locator).text

def wait_for_confirmation_dialog(self):
self.wait_for_element_displayed(*self._dialog_locator)
Wait(self.marionette).until(
expected.element_displayed(*self._dialog_locator))

def tap_call_log_toolbar_button(self):
self.wait_for_element_displayed(*self._call_log_toolbar_button_locator)
self.marionette.find_element(*self._call_log_toolbar_button_locator).tap()
element = Wait(self.marionette).until(
expected.element_present(*self._call_log_toolbar_button_locator))
Wait(self.marionette).until(expected.element_displayed(element))
element.tap()
return self.call_log

def a11y_click_call_log_toolbar_button(self):
self.wait_for_element_displayed(*self._call_log_toolbar_button_locator)
self.accessibility.click(self.marionette.find_element(
*self._call_log_toolbar_button_locator))
element = Wait(self.marionette).until(
expected.element_present(*self._call_log_toolbar_button_locator))
Wait(self.marionette).until(expected.element_displayed(element))
self.accessibility.click(element)
return self.call_log

def tap_keypad_toolbar_button(self):
self.wait_for_element_displayed(*self._keypad_toolbar_button_locator)
self.marionette.find_element(*self._keypad_toolbar_button_locator).tap()
element = Wait(self.marionette).until(
expected.element_present(*self._keypad_toolbar_button_locator))
Wait(self.marionette).until(expected.element_displayed(element))
element.tap()
return self.keypad

def a11y_click_keypad_toolbar_button(self):
self.wait_for_element_displayed(*self._keypad_toolbar_button_locator)
self.accessibility.click(self.marionette.find_element(
*self._keypad_toolbar_button_locator))
element = Wait(self.marionette).until(
expected.element_present(*self._keypad_toolbar_button_locator))
Wait(self.marionette).until(expected.element_displayed(element))
self.accessibility.click(element)
return self.keypad

def make_call_and_hang_up(self, phone_number):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

try:
from marionette import (expected,
Wait)
from marionette.by import By
except:
from marionette_driver import (expected,
Wait)
from marionette_driver.by import By

from gaiatest.apps.base import Base
Expand All @@ -16,7 +20,8 @@ class AttentionScreen(Base):

def __init__(self, marionette):
Base.__init__(self, marionette)
self.wait_for_element_displayed(*self._message_locator)
Wait(self.marionette).until(
expected.element_displayed(*self._message_locator))

@property
def message(self):
Expand Down
24 changes: 13 additions & 11 deletions tests/python/gaia-ui-tests/gaiatest/apps/phone/regions/call_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# 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.phone.app import Phone
from gaiatest.apps.base import PageRegion

try:
from marionette import (expected,
Wait)
Expand All @@ -16,6 +13,9 @@
from marionette_driver.by import By
from marionette_driver.errors import StaleElementException

from gaiatest.apps.phone.app import Phone
from gaiatest.apps.base import PageRegion


class CallLog(Phone):

Expand All @@ -42,8 +42,10 @@ class CallLog(Phone):

def __init__(self, marionette):
Phone.__init__(self, marionette)
self.wait_for_element_not_displayed(*self._upgrade_progress_locator)
self.wait_for_element_displayed(*self._all_calls_tab_link_locator)
Wait(self.marionette).until(
expected.element_not_displayed(*self._upgrade_progress_locator))
Wait(self.marionette).until(
expected.element_displayed(*self._all_calls_tab_link_locator))

def tap_all_calls_tab(self):
self.marionette.find_element(*self._all_calls_tab_link_locator).tap()
Expand Down Expand Up @@ -72,13 +74,13 @@ def tap_delete_button(self):
self._call_log_edit_delete_button_locator[1])

def tap_delete_confirmation_button(self):
Wait(self.marionette).until(expected.element_displayed(
Wait(self.marionette).until(expected.element_present(
*self._call_log_delete_confirmation_locator))))
self.marionette.find_element(*self._call_log_delete_confirmation_locator).tap()
confirm = Wait(self.marionette).until(
expected.element_present(*self._call_log_delete_confirmation_locator))
Wait(self.marionette).until(expected.element_displayed(confirm))
confirm.tap()

Wait(self.marionette, ignored_exceptions=[StaleElementException])\
.until(lambda m: len(self.call_list) == 0)
Wait(self.marionette, ignored_exceptions=StaleElementException).until(
lambda m: len(self.call_list) == 0)

@property
def header_text(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from marionette.marionette import Actions
except:
from marionette_driver import (expected,
Wait)
Wait)
from marionette_driver.by import By
from marionette_driver.marionette import Actions

Expand Down Expand Up @@ -55,11 +55,9 @@ def __init__(self, marionette):

def switch_to_call_screen_frame(self):
self.marionette.switch_to_frame()

self.wait_for_element_present(*self._call_screen_locator, timeout=30)

call_screen = self.marionette.find_element(*self._call_screen_locator)
self.marionette.switch_to_frame(call_screen)
frame = Wait(self.marionette, timeout=30).until(
expected.element_present(*self._call_screen_locator))
self.marionette.switch_to_frame(frame)

@property
def outgoing_calling_contact(self):
Expand All @@ -77,10 +75,6 @@ def incoming_calling_contact_while_on_call(self):
def calling_contact_information(self):
return self.marionette.find_element(*self._outgoing_call_locator).find_element(*self._calling_contact_information_locator).text

@property
def calling_contact_information(self):
return self.marionette.find_element(*self._outgoing_call_locator).find_element(*self._calling_contact_information_locator).text

@property
def conference_label(self):
return self.marionette.find_element(*self._conference_call_label_locator).text
Expand All @@ -98,19 +92,21 @@ def incoming_via_sim(self):
return self.marionette.find_element(*self._incoming_call_locator).find_element(*self._via_sim_locator).text

def wait_for_outgoing_call(self):
outgoing_call = self.marionette.find_element(*self._outgoing_call_locator)
self.wait_for_condition(lambda m: outgoing_call.location['y'] == 0)
self.wait_for_condition(lambda m: self.outgoing_calling_contact != u'')
call = self.marionette.find_element(*self._outgoing_call_locator)
contact = call.find_element(*self._calling_contact_locator)
Wait(self.marionette).until(lambda m: call.location['y'] == 0 and contact.text)

def wait_for_incoming_call(self):
main_window = self.marionette.find_element(*self._main_window_locator)
Wait(self.marionette).until(expected.element_displayed(main_window))
Wait(self.marionette).until(lambda m: main_window.location['y'] == 0)
Wait(self.marionette).until(lambda m: self.incoming_calling_contact != u'')
call = self.marionette.find_element(*self._incoming_call_locator)
contact = call.find_element(*self._calling_contact_locator)
Wait(self.marionette).until(lambda m: main_window.location['y'] == 0 and contact.text)

def wait_for_incoming_call_while_on_call(self):
self.wait_for_condition(lambda m: self.is_element_displayed(*self._incoming_info_while_on_call_locator))
self.wait_for_condition(lambda m: self.incoming_calling_contact_while_on_call != u'')
call = self.marionette.find_element(*self._incoming_info_while_on_call_locator)
contact = self.marionette.find_element(*self._incoming_number_while_on_call_locator)
Wait(self.marionette).until(lambda m: call.is_displayed() and contact.text)

def answer_call(self):
self.marionette.find_element(*self._answer_bar_locator).tap()
Expand All @@ -127,17 +123,20 @@ def a11y_click_keypad_hang_up(self):
def hang_up(self):
self.marionette.find_element(*self._hangup_bar_locator).tap()
self.marionette.switch_to_frame()
self.wait_for_element_not_displayed(*self._call_screen_locator)
Wait(self.marionette).until(
expected.element_not_displayed(*self._call_screen_locator))

def a11y_hang_up(self):
self.a11y_click_hang_up()
self.marionette.switch_to_frame()
self.wait_for_element_not_displayed(*self._call_screen_locator)
Wait(self.marionette).until(
expected.element_not_displayed(*self._call_screen_locator))

def a11y_keypad_hang_up(self):
self.a11y_click_keypad_hang_up()
self.marionette.switch_to_frame()
self.wait_for_element_not_displayed(*self._call_screen_locator)
Wait(self.marionette).until(
expected.element_not_displayed(*self._call_screen_locator))

def _handle_incoming_call(self, destination):

Expand All @@ -155,15 +154,18 @@ def _handle_incoming_call(self, destination):
).perform()

def reject_call(self):
self.wait_for_element_displayed(*self._lockscreen_handle_locator)
Wait(self.marionette).until(
expected.element_displayed(*self._lockscreen_handle_locator))
self._handle_incoming_call('reject')
self.marionette.switch_to_frame()
self.wait_for_element_not_displayed(*self._call_screen_locator)
Wait(self.marionette).until(
expected.element_not_displayed(*self._call_screen_locator))

def a11y_click_keypad_visibility_button(self):
self.accessibility.click(self.marionette.find_element(
*self._keypad_visibility_button_locator))

def merge_calls(self):
self.marionette.find_element(*self._merge_calls_button_locator).tap()
self.wait_for_condition(lambda m: self.marionette.find_element(*self._conference_call_locator).is_displayed())
Wait(self.marionette).until(
expected.element_displayed(*self._conference_call_locator))
10 changes: 7 additions & 3 deletions tests/python/gaia-ui-tests/gaiatest/apps/phone/regions/keypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def tap_add_contact(self):
return AddNewNumber(self.marionette)

def wait_for_search_popup_visible(self):
self.wait_for_element_displayed(*self._search_popup_locator)
Wait(self.marionette).until(
expected.element_displayed(*self._search_popup_locator))

@property
def suggested_name(self):
Expand All @@ -107,8 +108,11 @@ def tap_search_popup(self):
return CallScreen(self.marionette)

def wait_for_phone_number_ready(self):
# Entering dialer and expecting a phone number there is js that sets the phone value and enables this button
self.wait_for_condition(lambda m: m.find_element(*self._add_new_contact_button_locator).is_enabled())
# entering dialer and expecting a phone number there is javascript that
# sets the phone value and enables this button
add_contact = self.marionette.find_element(
*self._add_new_contact_button_locator)
Wait(self.marionette).until(expected.element_enabled(add_contact))


class AddNewNumber(Base):
Expand Down

0 comments on commit 3060d16

Please sign in to comment.