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

Bug 931781 - Use timeout arg on the command line to change timeout for d... #13478

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/python/gaia-ui-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Options:
--restart restart target instance between tests. This option will remove
the /data/local/indexedDB and /data/b2g/mozilla folders and restore the
device back to a common state
--timeout < time in milliseconds > to set default timeout values (30s for page load timeout,
10s for search timeout and 10s for script timeout) to a common specified value

Testing on a Device
===================
Expand Down
37 changes: 20 additions & 17 deletions tests/python/gaia-ui-tests/gaiatest/apps/base.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@


class Base(object):
# deafult timeout in seconds for the wait_for methods
_default_timeout = 30

def __init__(self, marionette):
self.marionette = marionette
Expand All @@ -27,10 +25,11 @@ def __init__(self, marionette):
def launch(self, launch_timeout=None):
self.app = self.apps.launch(self.name, launch_timeout=launch_timeout)

def wait_for_element_present(self, by, locator, timeout=_default_timeout):
timeout = float(timeout) + time.time()
def wait_for_element_present(self, by, locator, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()

while time.time() < timeout:
while time.time() < end_time:
time.sleep(0.5)
try:
return self.marionette.find_element(by, locator)
Expand All @@ -40,10 +39,11 @@ def wait_for_element_present(self, by, locator, timeout=_default_timeout):
raise TimeoutException(
'Element %s not found before timeout' % locator)

def wait_for_element_not_present(self, by, locator, timeout=_default_timeout):
timeout = float(timeout) + time.time()
def wait_for_element_not_present(self, by, locator, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()

while time.time() < timeout:
while time.time() < end_time:
time.sleep(0.5)
try:
self.marionette.find_element(by, locator)
Expand All @@ -53,10 +53,11 @@ def wait_for_element_not_present(self, by, locator, timeout=_default_timeout):
raise TimeoutException(
'Element %s still present after timeout' % locator)

def wait_for_element_displayed(self, by, locator, timeout=_default_timeout):
timeout = float(timeout) + time.time()
def wait_for_element_displayed(self, by, locator, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()
e = None
while time.time() < timeout:
while time.time() < end_time:
time.sleep(0.5)
try:
if self.marionette.find_element(by, locator).is_displayed():
Expand All @@ -69,10 +70,11 @@ def wait_for_element_displayed(self, by, locator, timeout=_default_timeout):
else:
raise TimeoutException('Element %s present but not displayed before timeout' % locator)

def wait_for_element_not_displayed(self, by, locator, timeout=_default_timeout):
timeout = float(timeout) + time.time()
def wait_for_element_not_displayed(self, by, locator, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()

while time.time() < timeout:
while time.time() < end_time:
time.sleep(0.5)
try:
if not self.marionette.find_element(by, locator).is_displayed():
Expand All @@ -85,9 +87,10 @@ def wait_for_element_not_displayed(self, by, locator, timeout=_default_timeout):
raise TimeoutException(
'Element %s still visible after timeout' % locator)

def wait_for_condition(self, method, timeout=_default_timeout, message="Condition timed out"):
def wait_for_condition(self, method, timeout=None, message="Condition timed out"):
"""Calls the method provided with the driver as an argument until the return value is not False."""
end_time = time.time() + timeout
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()
while time.time() < end_time:
try:
value = method(self.marionette)
Expand All @@ -107,7 +110,7 @@ def is_element_present(self, by, locator):
except NoSuchElementException:
return False
finally:
self.marionette.set_search_timeout(10000)
self.marionette.set_search_timeout(self.marionette.timeout or 10000)

def is_element_displayed(self, by, locator):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ def connect_to_network(self, network_info):
self.marionette.find_element(*self._password_ok_button_locator).tap()

self.wait_for_condition(
lambda m: m.find_element(*self._connected_message_locator).text == "Connected")
lambda m: m.find_element(*self._connected_message_locator).text == "Connected",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script_timeout is not a valid keyword argument for find_element method. You should be using the timeout argument of the wait_for_condition method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've changed it from script_timeout to timeout, but it's still on the wrong method call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, very sorry... I was temporarily blinded and blame my cold!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe No problem :) , just a funny incident :D

timeout = max(self.marionette.timeout and self.marionette.timeout / 1000, 60))
60 changes: 29 additions & 31 deletions tests/python/gaia-ui-tests/gaiatest/gaia_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def kill_all(self):
def runningApps(self):
return self.marionette.execute_script("return GaiaApps.getRunningApps()")

def switch_to_frame(self, app_frame, url=None, timeout=30):
def switch_to_frame(self, app_frame, url=None, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
self.marionette.switch_to_frame(app_frame)
start = time.time()
if not url:
Expand All @@ -141,7 +142,6 @@ def __init__(self, marionette, testvars=None):
self.testvars = testvars or {}
js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_data_layer.js"))
self.marionette.import_script(js)
self.marionette.set_search_timeout(10000)

def set_time(self, date_number):
self.marionette.set_context(self.marionette.CONTEXT_CHROME)
Expand All @@ -163,12 +163,11 @@ def insert_contact(self, contact):
result = self.marionette.execute_async_script('return GaiaDataLayer.insertContact(%s);' % json.dumps(contact), special_powers=True)
assert result, 'Unable to insert contact %s' % contact

def remove_all_contacts(self, default_script_timeout=60000):
def remove_all_contacts(self):
self.marionette.switch_to_frame()
self.marionette.set_script_timeout(max(default_script_timeout, 1000 * len(self.all_contacts)))
result = self.marionette.execute_async_script('return GaiaDataLayer.removeAllContacts();', special_powers=True)
timeout = max(self.marionette.timeout or 60000, 1000 * len(self.all_contacts))
result = self.marionette.execute_async_script('return GaiaDataLayer.removeAllContacts();', special_powers=True, script_timeout=timeout)
assert result, 'Unable to remove all contacts'
self.marionette.set_script_timeout(default_script_timeout)

def get_setting(self, name):
return self.marionette.execute_async_script('return GaiaDataLayer.getSetting("%s")' % name, special_powers=True)
Expand Down Expand Up @@ -297,7 +296,8 @@ def connect_to_wifi(self, network=None):
assert network, 'No WiFi network provided'
self.enable_wifi()
self.marionette.switch_to_frame()
result = self.marionette.execute_async_script("return GaiaDataLayer.connectToWiFi(%s)" % json.dumps(network))
result = self.marionette.execute_async_script("return GaiaDataLayer.connectToWiFi(%s)" % json.dumps(network),
script_timeout = max(self.marionette.timeout, 60000))
assert result, 'Unable to connect to WiFi network'

def forget_all_networks(self):
Expand Down Expand Up @@ -488,13 +488,6 @@ def stop_b2g(self):


class GaiaTestCase(MarionetteTestCase):

_script_timeout = 60000
_search_timeout = 10000

# deafult timeout in seconds for the wait_for methods
_default_timeout = 30

def __init__(self, *args, **kwargs):
self.restart = kwargs.pop('restart', False)
kwargs.pop('iterations', None)
Expand All @@ -517,9 +510,9 @@ def setUp(self):
self.device.manager.removeDir('/data/b2g/mozilla')
self.device.start_b2g()

# the emulator can be really slow!
self.marionette.set_script_timeout(self._script_timeout)
self.marionette.set_search_timeout(self._search_timeout)
if not self.marionette.timeout:
self.marionette.set_search_timeout(10000)

self.lockscreen = LockScreen(self.marionette)
self.apps = GaiaApps(self.marionette)
self.data_layer = GaiaData(self.marionette, self.testvars)
Expand Down Expand Up @@ -649,10 +642,11 @@ def screen_width(self):
def screen_orientation(self):
return self.marionette.execute_script('return window.screen.mozOrientation')

def wait_for_element_present(self, by, locator, timeout=_default_timeout):
timeout = float(timeout) + time.time()
def wait_for_element_present(self, by, locator, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()

while time.time() < timeout:
while time.time() < end_time:
time.sleep(0.5)
try:
return self.marionette.find_element(by, locator)
Expand All @@ -662,10 +656,11 @@ def wait_for_element_present(self, by, locator, timeout=_default_timeout):
raise TimeoutException(
'Element %s not present before timeout' % locator)

def wait_for_element_not_present(self, by, locator, timeout=_default_timeout):
timeout = float(timeout) + time.time()
def wait_for_element_not_present(self, by, locator, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()

while time.time() < timeout:
while time.time() < end_time:
time.sleep(0.5)
try:
self.marionette.find_element(by, locator)
Expand All @@ -675,10 +670,11 @@ def wait_for_element_not_present(self, by, locator, timeout=_default_timeout):
raise TimeoutException(
'Element %s still present after timeout' % locator)

def wait_for_element_displayed(self, by, locator, timeout=_default_timeout):
timeout = float(timeout) + time.time()
def wait_for_element_displayed(self, by, locator, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()
e = None
while time.time() < timeout:
while time.time() < end_time:
time.sleep(0.5)
try:
if self.marionette.find_element(by, locator).is_displayed():
Expand All @@ -692,10 +688,11 @@ def wait_for_element_displayed(self, by, locator, timeout=_default_timeout):
else:
raise TimeoutException('Element %s present but not displayed before timeout' % locator)

def wait_for_element_not_displayed(self, by, locator, timeout=_default_timeout):
timeout = float(timeout) + time.time()
def wait_for_element_not_displayed(self, by, locator, timeout=None):
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()

while time.time() < timeout:
while time.time() < end_time:
time.sleep(0.5)
try:
if not self.marionette.find_element(by, locator).is_displayed():
Expand All @@ -708,11 +705,12 @@ def wait_for_element_not_displayed(self, by, locator, timeout=_default_timeout):
raise TimeoutException(
'Element %s still visible after timeout' % locator)

def wait_for_condition(self, method, timeout=_default_timeout,
def wait_for_condition(self, method, timeout=None,
message="Condition timed out"):
"""Calls the method provided with the driver as an argument until the \
return value is not False."""
end_time = time.time() + timeout
timeout = timeout or (self.marionette.timeout and self.marionette.timeout / 1000) or 30
end_time = float(timeout) + time.time()
while time.time() < end_time:
try:
value = method(self.marionette)
Expand Down