當前位置: 首頁>>代碼示例>>Python>>正文


Python gaiatest.GaiaApps類代碼示例

本文整理匯總了Python中gaiatest.GaiaApps的典型用法代碼示例。如果您正苦於以下問題:Python GaiaApps類的具體用法?Python GaiaApps怎麽用?Python GaiaApps使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了GaiaApps類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_up_device

def set_up_device(opt):
    if not opt.wifi_ssid or not opt.wifi_key or not opt.wifi_pass:
        raise ValueError('Missing --wifi options')

    mc = Marionette('localhost', opt.adb_port)
    for i in range(2):
        try:
            mc.start_session()
            break
        except socket.error:
            sh('adb forward tcp:%s tcp:%s' % (opt.adb_port, opt.adb_port))
    if opt.shell:
        from pdb import set_trace
        set_trace()
        return

    # watch out! This is how gaiatest does it.
    mc.__class__ = type('Marionette', (Marionette, MarionetteTouchMixin), {})
    device = GaiaDevice(mc)

    device.restart_b2g()

    apps = GaiaApps(mc)
    data_layer = GaiaData(mc)
    lockscreen = LockScreen(mc)
    mc.setup_touch()

    lockscreen.unlock()
    apps.kill_all()

    data_layer.enable_wifi()
    if opt.wifi_key == 'WPA-PSK':
        pass_key = 'psk'
    elif opt.wifi_key == 'WEP':
        pass_key = 'wep'
    else:
        assert 0, 'unknown key management'
    data = {'ssid': opt.wifi_ssid, 'keyManagement': opt.wifi_key,
            pass_key: opt.wifi_pass}
    data_layer.connect_to_wifi(data)

    mc.switch_to_frame()
    all_apps = set(a['manifest']['name'] for a in get_installed(apps))
    if 'Marketplace Dev' not in all_apps:
        mc.execute_script(
            'navigator.mozApps.install'
            '("https://marketplace-dev.allizom.org/manifest.webapp");')
        wait_for_element_displayed(mc, 'id', 'app-install-install-button')
        yes = mc.find_element('id', 'app-install-install-button')
        mc.tap(yes)
        wait_for_element_displayed(mc, 'id', 'system-banner')

    print 'Pushing payment prefs'
    sh('adb shell stop b2g')
    sh('adb push "%s" /data/local/user.js' % (
        os.path.join(os.path.dirname(__file__), 'payment-prefs.js')))
    sh('adb shell start b2g')

    print 'When your device reboots, Marketplace Dev will be installed'
開發者ID:flodolo,項目名稱:webpay,代碼行數:59,代碼來源:set_up_device.py

示例2: set_up_device

def set_up_device(args):
    mc = get_marionette(args)
    device = GaiaDevice(mc)
    try:
        device.restart_b2g()
    except Exception:
        print ' ** Check to make sure you don\'t have desktop B2G running'
        raise

    apps = GaiaApps(mc)
    data_layer = GaiaData(mc)
    lockscreen = LockScreen(mc)
    mc.setup_touch()

    lockscreen.unlock()
    apps.kill_all()

    if args.wifi_ssid:
        print 'Configuring WiFi'
        if not args.wifi_key or not args.wifi_pass:
            args.error('Missing --wifi_key or --wifi_pass option')
        args.wifi_key = args.wifi_key.upper()

        data_layer.enable_wifi()
        if args.wifi_key == 'WPA-PSK':
            pass_key = 'psk'
        elif args.wifi_key == 'WEP':
            pass_key = 'wep'
        else:
            args.error('not sure what key to use for %r' % args.wifi_key)

        data = {'ssid': args.wifi_ssid, 'keyManagement': args.wifi_key,
                pass_key: args.wifi_pass}
        data_layer.connect_to_wifi(data)

    for manifest in args.apps:
        # There is probably a way easier way to do this by adb pushing
        # something. Send me a patch!
        mc.switch_to_frame()
        try:
            data = requests.get(manifest).json()
            app_name = data['name']
            all_apps = set(a['manifest']['name'] for a in get_installed(apps))
            if app_name not in all_apps:
                print 'Installing %s from %s' % (app_name, manifest)
                mc.execute_script('navigator.mozApps.install("%s");' % manifest)
                wait_for_element_displayed(mc, 'id', 'app-install-install-button')
                yes = mc.find_element('id', 'app-install-install-button')
                mc.tap(yes)
                # This still works but the id check broke.
                # See https://bugzilla.mozilla.org/show_bug.cgi?id=853878
                wait_for_element_displayed(mc, 'id', 'system-banner')
        except Exception, exc:
            print ' ** installing manifest %s failed (maybe?)' % manifest
            print ' ** error: %s: %s' % (exc.__class__.__name__, exc)
            continue
開發者ID:nhirata,項目名稱:ezboot,代碼行數:56,代碼來源:__init__.py

示例3: __init__

 def __init__(self, marionette):
     self.marionette = marionette
     self.apps = GaiaApps(self.marionette)
     self.accessibility = Accessibility(self.marionette)
     self.frame = None
     self.manifest_url = None
     self.entry_point = None
開發者ID:Shekharrajak,項目名稱:gaia,代碼行數:7,代碼來源:base.py

示例4: __init__

 def __init__(self, marionette):
     self.marionette = marionette
     self.apps = GaiaApps(self.marionette)
     self.accessibility = Accessibility(self.marionette)
     self.frame = None
     self.manifest_url = hasattr(self, 'manifest_url') and self.manifest_url or None
     self.entry_point = hasattr(self, 'entry_point') and self.entry_point or None
開發者ID:ssainz,項目名稱:gaia,代碼行數:7,代碼來源:base.py

示例5: install_apps

    def install_apps():
        mc = get_marionette(args)
        device = GaiaDevice(mc)
        try:
            device.restart_b2g()
            print 'Your device is rebooting.'
        except Exception:
            print ' ** Check to make sure you don\'t have desktop B2G running'
            raise

        apps = GaiaApps(mc)
        apps.kill_all()

        lockscreen = LockScreen(mc)
        lockscreen.unlock()

        if args.wifi_ssid:
            print 'Configuring WiFi'
            if not args.wifi_key or not args.wifi_pass:
                args.error('Missing --wifi_key or --wifi_pass option')
            args.wifi_key = args.wifi_key.upper()

            data_layer = GaiaData(mc)
            data_layer.enable_wifi()
            if args.wifi_key == 'WPA-PSK':
                pass_key = 'psk'
            elif args.wifi_key == 'WEP':
                pass_key = 'wep'
            else:
                args.error('not sure what key to use for %r' % args.wifi_key)

            data = {'ssid': args.wifi_ssid, 'keyManagement': args.wifi_key,
                    pass_key: args.wifi_pass}
            data_layer.connect_to_wifi(data)

        # disconnect marionette client because install_app would need it
        mc.client.close()

        # install apps one by one
        for manifest in args.apps:
            args.manifest = manifest
            args.app = None
            install_app(args)
開發者ID:kumar303,項目名稱:ezboot,代碼行數:43,代碼來源:__init__.py

示例6: Base

class Base(object):

    def __init__(self, marionette, name=None):
        self.marionette = marionette
        self.apps = GaiaApps(self.marionette)
        self.name = name or self.name

    def launch(self):
        self.app = self.apps.launch(self.name)

    def wait_for_element_present(self, by, locator, timeout=10):
        timeout = float(timeout) + time.time()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                return self.marionette.find_element(by, locator)
            except NoSuchElementException:
                pass
        else:
            raise TimeoutException(
                'Element %s not found before timeout' % locator)

    def wait_for_element_displayed(self, by, locator, timeout=10):
        timeout = float(timeout) + time.time()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                if self.marionette.find_element(by, locator).is_displayed():
                    break
            except NoSuchElementException:
                pass
        else:
            raise TimeoutException(
                'Element %s not visible before timeout' % locator)

    def wait_for_condition(self, method, timeout=10, 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
        while time.time() < end_time:
            try:
                value = method(self.marionette)
                if value:
                    return value
            except NoSuchElementException:
                pass
            time.sleep(0.5)
        else:
            raise TimeoutException(message)
開發者ID:AndreiH,項目名稱:gaia-ui-tests,代碼行數:50,代碼來源:base.py

示例7: install_app

def install_app(args):
    def confirm_installation():
        _yes_button_locator = ('id', 'app-install-install-button')

        wait_for_element_displayed(mc, *_yes_button_locator)
        mc.find_element(*_yes_button_locator).tap()
        wait_for_element_not_displayed(mc, *_yes_button_locator)

        print 'App successfully installed.'

    # marketplace loading fragment locator
    _loading_fragment_locator = ('css selector', 'div#splash-overlay')
    _search_locator = ('id', 'search-q')

    if not args.app and not args.manifest and not args.app_url:
        args.error('Provide either app name (using --app), URL of app\'s '
                   'manifest file (using --manifest) or URL of the app '
                   'on marketpalce (using --app_url).')

    mc = get_marionette(args)
    lockscreen = LockScreen(mc)
    lockscreen.unlock()

    apps = GaiaApps(mc)
    apps.kill_all()

    no_internet_error = ('Unable to download app.\nReason: You are probably '
                         'not connected to internet on your device.')

    if args.manifest:
        mc.execute_script('navigator.mozApps.install("%s")' % args.manifest)
        try:
            confirm_installation()
        except TimeoutException, exc:
            print '** %s: %s' % (exc.__class__.__name__, exc)
            args.error(no_internet_error)
        return
開發者ID:kumar303,項目名稱:ezboot,代碼行數:37,代碼來源:__init__.py

示例8: __init__

 def __init__(self, marionette):
     self.marionette = marionette
     self.apps = GaiaApps(self.marionette)
     self.accessibility = Accessibility(self.marionette)
     self.frame = None
開發者ID:Bharatpattani,項目名稱:gaia,代碼行數:5,代碼來源:base.py

示例9: Base

class Base(object):

    def __init__(self, marionette):
        self.marionette = marionette
        self.apps = GaiaApps(self.marionette)
        self.accessibility = Accessibility(self.marionette)
        self.frame = None

    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=None):
        return Wait(self.marionette, timeout, ignored_exceptions=NoSuchElementException).until(
            lambda m: m.find_element(by, locator))

    def wait_for_element_not_present(self, by, locator, timeout=None):
        self.marionette.set_search_timeout(0)
        try:
            return Wait(self.marionette, timeout).until(
                lambda m: not m.find_element(by, locator))
        except NoSuchElementException:
            pass
        self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def wait_for_element_displayed(self, by, locator, timeout=None):
        Wait(self.marionette, timeout, ignored_exceptions=[NoSuchElementException, StaleElementException]).until(
            lambda m: m.find_element(by, locator).is_displayed())

    def wait_for_element_not_displayed(self, by, locator, timeout=None):
        self.marionette.set_search_timeout(0)
        try:
            Wait(self.marionette, timeout, ignored_exceptions=StaleElementException).until(
                lambda m: not m.find_element(by, locator).is_displayed())
        except NoSuchElementException:
            pass
        self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def wait_for_condition(self, method, timeout=None, message=None):
        Wait(self.marionette, timeout).until(method, message=message)

    def is_element_present(self, by, locator):
        self.marionette.set_search_timeout(0)
        try:
            self.marionette.find_element(by, locator)
            return True
        except NoSuchElementException:
            return False
        finally:
            self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def is_element_displayed(self, by, locator):
        self.marionette.set_search_timeout(0)
        try:
            return self.marionette.find_element(by, locator).is_displayed()
        except NoSuchElementException:
            return False
        finally:
            self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def select(self, match_string):
        # cheeky Select wrapper until Marionette has its own
        # due to the way B2G wraps the app's select box we match on text

        _list_item_locator = (By.XPATH, "id('value-selector-container')/descendant::li[descendant::span[.='%s']]" % match_string)
        _close_button_locator = (By.CSS_SELECTOR, 'button.value-option-confirm')

        # have to go back to top level to get the B2G select box wrapper
        self.marionette.switch_to_frame()
        # TODO we should find something suitable to wait for, but this goes too
        # fast against desktop builds causing intermittent failures
        time.sleep(0.2)

        li = self.wait_for_element_present(*_list_item_locator)

       # TODO Remove scrollintoView upon resolution of bug 877651
        self.marionette.execute_script(
            'arguments[0].scrollIntoView(false);', [li])
        li.tap()

        # Tap close and wait for it to hide
        close_button = self.marionette.find_element(*_close_button_locator)
        close_button.tap()
        self.wait_for_element_not_displayed(*_close_button_locator)

        # TODO we should find something suitable to wait for, but this goes too
        # fast against desktop builds causing intermittent failures
        time.sleep(0.2)

        # now back to app
        self.apps.switch_to_displayed_app()

    @property
    def keyboard(self):
        from gaiatest.apps.keyboard.app import Keyboard
        return Keyboard(self.marionette)
開發者ID:Bharatpattani,項目名稱:gaia,代碼行數:95,代碼來源:base.py

示例10: __init__

 def __init__(self, marionette):
     self.marionette = marionette
     self.apps = GaiaApps(self.marionette)
     self.accessibility = Accessibility(self.marionette)
     self.frame = None
     self.entry_point = hasattr(self, "entry_point") and self.entry_point or None
開發者ID:rockwyc992,項目名稱:gaia,代碼行數:6,代碼來源:base.py

示例11: __init__

 def __init__(self, marionette):
     self.marionette = marionette
     self.apps = GaiaApps(self.marionette)
開發者ID:malini,項目名稱:gaia-ui-tests-1,代碼行數:3,代碼來源:base.py

示例12: Base

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

    def __init__(self, marionette):
        self.marionette = marionette
        self.apps = GaiaApps(self.marionette)

    def launch(self):
        self.app = self.apps.launch(self.name)

    def wait_for_element_present(self, by, locator, timeout=_default_timeout):
        timeout = float(timeout) + time.time()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                return self.marionette.find_element(by, locator)
            except NoSuchElementException:
                pass
        else:
            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()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                self.marionette.find_element(by, locator)
            except NoSuchElementException:
                break
        else:
            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()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                if self.marionette.find_element(by, locator).is_displayed():
                    break
            except (NoSuchElementException, StaleElementException):
                pass
        else:
            raise TimeoutException("Element %s not visible before timeout" % locator)

    def wait_for_element_not_displayed(self, by, locator, timeout=_default_timeout):
        timeout = float(timeout) + time.time()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                if not self.marionette.find_element(by, locator).is_displayed():
                    break
            except StaleElementException:
                pass
            except NoSuchElementException:
                break
        else:
            raise TimeoutException("Element %s still visible after timeout" % locator)

    def wait_for_condition(self, method, timeout=_default_timeout, 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
        while time.time() < end_time:
            try:
                value = method(self.marionette)
                if value:
                    return value
            except (NoSuchElementException, StaleElementException):
                pass
            time.sleep(0.5)
        else:
            raise TimeoutException(message)

    def is_element_present(self, by, locator):
        try:
            self.marionette.find_element(by, locator)
            return True
        except NoSuchElementException:
            return False

    def is_element_displayed(self, by, locator):
        try:
            return self.marionette.find_element(by, locator).is_displayed()
        except (NoSuchElementException, ElementNotVisibleException):
            return False

    def select(self, match_string):
        # cheeky Select wrapper until Marionette has its own
        # due to the way B2G wraps the app's select box we match on text

        # have to go back to top level to get the B2G select box wrapper
        self.marionette.switch_to_frame()

        self.wait_for_condition(
            lambda m: len(self.marionette.find_elements("css selector", "#value-selector-container li")) > 0
        )
#.........這裏部分代碼省略.........
開發者ID:malini,項目名稱:gaia-ui-tests-1,代碼行數:101,代碼來源:base.py

示例13: Base

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

    def __init__(self, marionette):
        self.marionette = marionette
        self.apps = GaiaApps(self.marionette)

    def launch(self):
        self.app = self.apps.launch(self.name)

    def wait_for_element_present(self, by, locator, timeout=_default_timeout):
        timeout = float(timeout) + time.time()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                return self.marionette.find_element(by, locator)
            except NoSuchElementException:
                pass
        else:
            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()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                self.marionette.find_element(by, locator)
            except NoSuchElementException:
                break
        else:
            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()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                if self.marionette.find_element(by, locator).is_displayed():
                    break
            except NoSuchElementException:
                pass
        else:
            raise TimeoutException(
                'Element %s not visible before timeout' % locator)

    def wait_for_element_not_displayed(self, by, locator, timeout=_default_timeout):
        timeout = float(timeout) + time.time()

        while time.time() < timeout:
            time.sleep(0.5)
            try:
                if not self.marionette.find_element(by, locator).is_displayed():
                    break
            except NoSuchElementException:
                break
        else:
            raise TimeoutException(
                'Element %s still visible after timeout' % locator)

    def wait_for_condition(self, method, timeout=_default_timeout, 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
        while time.time() < end_time:
            try:
                value = method(self.marionette)
                if value:
                    return value
            except NoSuchElementException:
                pass
            time.sleep(0.5)
        else:
            raise TimeoutException(message)

    def is_element_present(self, by, locator):
        try:
            self.marionette.find_element(by, locator)
            return True
        except NoSuchElementException:
            return False

    def is_element_displayed(self, by, locator):
        try:
            return self.marionette.find_element(by, locator).is_displayed()
        except (NoSuchElementException, ElementNotVisibleException):
            return False
開發者ID:gregglind,項目名稱:gaia-ui-tests,代碼行數:91,代碼來源:base.py

示例14: Base

class Base(object):

    def __init__(self, marionette):
        self.marionette = marionette
        self.apps = GaiaApps(self.marionette)
        self.accessibility = Accessibility(self.marionette)
        self.frame = None
        self.manifest_url = hasattr(self, 'manifest_url') and self.manifest_url or None
        self.entry_point = hasattr(self, 'entry_point') and self.entry_point or None

    def launch(self, launch_timeout=None):
        self.app = self.apps.launch(self.name, self.manifest_url, self.entry_point, launch_timeout=launch_timeout)

    def is_element_present(self, by, locator):
        self.marionette.set_search_timeout(0)
        try:
            self.marionette.find_element(by, locator)
            return True
        except NoSuchElementException:
            return False
        finally:
            self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def is_element_displayed(self, by, locator):
        self.marionette.set_search_timeout(0)
        try:
            return self.marionette.find_element(by, locator).is_displayed()
        except NoSuchElementException:
            return False
        finally:
            self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def find_select_item(self, match_string):
        _list_item_locator = (
            By.XPATH, "//section[contains(@class,'value-selector-container')]/descendant::li[descendant::span[.='%s']]" %
            match_string)
        # have to go back to top level to get the B2G select box wrapper
        self.marionette.switch_to_frame()
        # TODO we should find something suitable to wait for, but this goes too
        # fast against desktop builds causing intermittent failures
        time.sleep(0.2)

        li = Wait(self.marionette).until(expected.element_present(*_list_item_locator))
        # We need to keep this because the Ok button may hang over the element and stop
        # Marionette from scrolling the element entirely into view
        self.marionette.execute_script(
            'arguments[0].scrollIntoView(false);', [li])
        return li

    def wait_for_select_closed(self, by, locator):
        Wait(self.marionette).until(expected.element_not_displayed(by, locator))

        # now back to app
        self.apps.switch_to_displayed_app()

        # TODO we should find something suitable to wait for, but this goes too
        # fast against desktop builds causing intermittent failures
        # This sleep is necessary to make sure the select is completely faded out,
        # see bug 1148154
        time.sleep(1)

    def select(self, match_string, tap_close=True):
        # cheeky Select wrapper until Marionette has its own
        # due to the way B2G wraps the app's select box we match on text
        _close_button_locator = (By.CSS_SELECTOR, 'button.value-option-confirm')

        li = self.find_select_item(match_string)
        li.tap()

        # Tap close and wait for it to hide
        if tap_close:
          self.marionette.find_element(*_close_button_locator).tap()
        self.wait_for_select_closed(*_close_button_locator)

    def a11y_select(self, match_string):
        # Accessibility specific select method
        _close_button_locator = (By.CSS_SELECTOR, 'button.value-option-confirm')

        li = self.find_select_item(match_string)
        self.accessibility.click(li)

        # A11y click close and wait for it to hide
        self.accessibility.click(self.marionette.find_element(*_close_button_locator))
        self.wait_for_select_closed(*_close_button_locator)

    def tap_element_from_system_app(self, element=None, add_statusbar_height=False, x=None, y=None):        # Workaround for bug 1109213, where tapping on the button inside the app itself
        # makes Marionette spew out NoSuchWindowException errors
        cx = element.rect['x']
        cy = element.rect['y']
        cx += element.rect['width']//2 if x is None else x
        cy += element.rect['height']//2 if y is None else y

        from gaiatest.apps.system.app import System
        system = System(self.marionette)
        if add_statusbar_height:
          cy = cy + system.status_bar.height
        system.tap(cx, cy)

    @property
    def keyboard(self):
#.........這裏部分代碼省略.........
開發者ID:ssainz,項目名稱:gaia,代碼行數:101,代碼來源:base.py

示例15: Base

class Base(object):

    def __init__(self, marionette):
        self.marionette = marionette
        self.apps = GaiaApps(self.marionette)
        self.accessibility = Accessibility(self.marionette)
        self.frame = None
        self.manifest_url = hasattr(self, 'manifest_url') and self.manifest_url or None
        self.entry_point = hasattr(self, 'entry_point') and self.entry_point or None

    def launch(self, launch_timeout=None):
        self.app = self.apps.launch(self.name, self.manifest_url, self.entry_point, launch_timeout=launch_timeout)

    def wait_for_element_present(self, by, locator, timeout=None):
        return Wait(self.marionette, timeout, ignored_exceptions=NoSuchElementException).until(
            lambda m: m.find_element(by, locator))

    def wait_for_element_not_present(self, by, locator, timeout=None):
        self.marionette.set_search_timeout(0)
        try:
            return Wait(self.marionette, timeout).until(
                lambda m: not m.find_element(by, locator))
        except NoSuchElementException:
            pass
        self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def wait_for_element_displayed(self, by, locator, timeout=None):
        Wait(self.marionette, timeout, ignored_exceptions=[NoSuchElementException, StaleElementException]).until(
            lambda m: m.find_element(by, locator).is_displayed())

    def wait_for_element_not_displayed(self, by, locator, timeout=None):
        self.marionette.set_search_timeout(0)
        try:
            Wait(self.marionette, timeout, ignored_exceptions=StaleElementException).until(
                lambda m: not m.find_element(by, locator).is_displayed())
        except NoSuchElementException:
            pass
        self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def wait_for_condition(self, method, timeout=None, message=None):
        Wait(self.marionette, timeout).until(method, message=message)

    def is_element_present(self, by, locator):
        self.marionette.set_search_timeout(0)
        try:
            self.marionette.find_element(by, locator)
            return True
        except NoSuchElementException:
            return False
        finally:
            self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def is_element_displayed(self, by, locator):
        self.marionette.set_search_timeout(0)
        try:
            return self.marionette.find_element(by, locator).is_displayed()
        except NoSuchElementException:
            return False
        finally:
            self.marionette.set_search_timeout(self.marionette.timeout or 10000)

    def find_select_item(self, match_string):
        _list_item_locator = (
            By.XPATH, "//section[contains(@class,'value-selector-container')]/descendant::li[descendant::span[.='%s']]" %
            match_string)
        # have to go back to top level to get the B2G select box wrapper
        self.marionette.switch_to_frame()
        # TODO we should find something suitable to wait for, but this goes too
        # fast against desktop builds causing intermittent failures
        time.sleep(0.2)

        li = self.wait_for_element_present(*_list_item_locator)
        # We need to keep this because the Ok button may hang over the element and stop
        # Marionette from scrolling the element entirely into view
        self.marionette.execute_script(
            'arguments[0].scrollIntoView(false);', [li])
        return li

    def wait_for_select_closed(self, by, locator):
        self.wait_for_element_not_displayed(by, locator)

        # TODO we should find something suitable to wait for, but this goes too
        # fast against desktop builds causing intermittent failures
        time.sleep(0.2)

        # now back to app
        self.apps.switch_to_displayed_app()

    def select(self, match_string):
        # cheeky Select wrapper until Marionette has its own
        # due to the way B2G wraps the app's select box we match on text
        _close_button_locator = (By.CSS_SELECTOR, 'button.value-option-confirm')

        li = self.find_select_item(match_string)
        li.tap()

        # Tap close and wait for it to hide
        self.marionette.find_element(*_close_button_locator).tap()
        self.wait_for_select_closed(*_close_button_locator)

#.........這裏部分代碼省略.........
開發者ID:4gh,項目名稱:gaia,代碼行數:101,代碼來源:base.py


注:本文中的gaiatest.GaiaApps類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。