class TestConsoleLogCapture():
    def setup(self):
        try:
            self.client = Marionette(host='localhost', port=2828)
            self.client.start_session()
            self.client.set_pref('general.warnOnAboutConfig', False)
        except:
            sys.exit("Could not find Firefox browser running")

    def test_push_notification_received(self):
        self.client.navigate(
            "https://people.mozilla.org/~ewong2/push-notification-test/")

        unregister_button = self.client.find_element(By.ID, "unreg_btn")
        if unregister_button.is_displayed() == True:
            unregister_button.click()
            Wait(self.client, timeout=5, interval=1).until(
                expected.element_not_displayed(By.ID, "unreg_btn"))

        Wait(self.client).until(expected.element_displayed(By.ID, "reg_btn"))
        self.client.find_element(By.ID, "reg_btn").click()
        Wait(self.client).until(
            expected.element_displayed(By.ID, "subscribe_btn"))
        self.client.find_element(By.ID, "subscribe_btn").click()
        Wait(self.client).until(expected.element_displayed(By.ID, "doXhr_btn"))
        self.client.find_element(By.ID, "doXhr_btn").click()

        result = self.web_console_filter_for_string("Received a push message")
        assert result == 1

    def web_console_filter_for_string(self, console_string=None):
        self.client.set_context(self.client.CONTEXT_CHROME)

        handles = self.client.window_handles
        chrome_handles = self.client.chrome_window_handles
        browser_handle = self.client.current_chrome_window_handle
        notifications = 0
        for handle in chrome_handles:
            if handle != browser_handle:
                console_handle = handle
                self.client.switch_to_window(console_handle)
                time.sleep(1)
                results = self.client.find_elements(By.CLASS_NAME,
                                                    "console-string")
                for result in results:
                    if console_string in result.text:
                        notifications = notifications + 1
        self.client.find_element(By.CLASS_NAME,
                                 "webconsole-clear-console-button").click()
        return notifications

    def tear_down(self):
        self.client.close()
Ejemplo n.º 2
0
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'
class TestConsoleLogCapture():
    def setup(self):
        try:
            self.client = Marionette(host='localhost', port=2828)
            self.client.start_session()
            self.client.set_pref('general.warnOnAboutConfig', False)
        except:
            sys.exit("Could not find Firefox browser running")

    def test_push_notification_received(self):
        self.client.navigate("https://people.mozilla.org/~ewong2/push-notification-test/")

        unregister_button = self.client.find_element(By.ID, "unreg_btn")
        if unregister_button.is_displayed() == True:
            unregister_button.click()
            Wait(self.client, timeout=5, interval=1).until(expected.element_not_displayed(By.ID, "unreg_btn"))

        Wait(self.client).until(expected.element_displayed(By.ID, "reg_btn"))
        self.client.find_element(By.ID, "reg_btn").click()
        Wait(self.client).until(expected.element_displayed(By.ID, "subscribe_btn"))
        self.client.find_element(By.ID, "subscribe_btn").click()
        Wait(self.client).until(expected.element_displayed(By.ID, "doXhr_btn"))
        self.client.find_element(By.ID, "doXhr_btn").click()

        result = self.web_console_filter_for_string("Received a push message")
        assert result == 1

    def web_console_filter_for_string(self, console_string=None):
        self.client.set_context(self.client.CONTEXT_CHROME)

        handles = self.client.window_handles
        chrome_handles = self.client.chrome_window_handles
        browser_handle = self.client.current_chrome_window_handle
        notifications = 0
        for handle in chrome_handles:
            if handle != browser_handle:
                console_handle = handle
                self.client.switch_to_window(console_handle)
                time.sleep(1)
                results = self.client.find_elements(By.CLASS_NAME, "console-string")
                for result in results:
                    if console_string in result.text:
                        notifications = notifications + 1
        self.client.find_element(By.CLASS_NAME, "webconsole-clear-console-button").click()
        return notifications


    def tear_down(self):
        self.client.close()
Ejemplo n.º 4
0
class current_frame():
    
    def main(self, p_snippet, p_frame_array=False):
        #
        # p_el is an array for the element.
        # p_frame_array is a list of iframes to iterate through (optional).
        #
        self.marionette = Marionette(host='localhost', port=2828)  
        self.marionette.start_session()
        self.marionette.set_search_timeout(1000)
        self.actions    = Actions(self.marionette)
        
        #
        # Switch to the correct iframe (unless it's "()").
        #
        self.marionette.switch_to_frame()
        
        first_iframe = True
        for x in p_frame_array:
            # (just to make it look nice ;)
            typ_str = "'" + x[0] + "'"
            
            if first_iframe:
                first_iframe = False
                print ""
                print "Switching to iframe with " + typ_str.rjust(10) + " = '" + x[1] + "'"
            else:
                print "... then to iframe with  " + typ_str.rjust(10) + " = '" + x[1] + "'"
            
            my_iframe = self.marionette.find_element("xpath", "//iframe[@" + x[0] + "='" + x[1] + "']")
            self.marionette.switch_to_frame(my_iframe)
            
        if first_iframe:
            print ""
            print "Using 'top level' iframe () ..."
            
        
        # Run the code snippet.
        print ""
        print "Running code snippet from this location ..."
        print ""
        execfile(p_snippet)
Ejemplo n.º 5
0
class current_frame():
    
    def main(self, LOGDIR, p_el, p_frame_array=False):
        #
        # p_el is an array for the element.
        # p_frame_array is a list of iframes to iterate through (optional).
        #
        self.marionette = Marionette(host='localhost', port=2828)  
        self.marionette.start_session()
        self.marionette.set_search_timeout(1000)
        
        #
        # Switch to the correct iframe (unless it's "()").
        #
        self.marionette.switch_to_frame()
        
        first_iframe = True
        for x in p_frame_array:
            # (just to make it look nice ;)
            typ_str = "'" + x[0] + "'"
            
            if first_iframe:
                first_iframe = False
                print ""
                print "Switching to iframe with " + typ_str.rjust(10) + " = '" + x[1] + "'"
            else:
                print "... then to iframe with  " + typ_str.rjust(10) + " = '" + x[1] + "'"
            
            my_iframe = self.marionette.find_element("xpath", "//iframe[@" + x[0] + "='" + x[1] + "']")
            self.marionette.switch_to_frame(my_iframe)
            
        if first_iframe:
            print ""
            print "Using 'top level' iframe () ..."
        
        #
        # Grab a screenshot and html dump of this frame.
        #
        p_sfnam = LOGDIR + "screenshot.png"
        p_hfnam = LOGDIR + "html_dump.html"
        print ""
        print "Screenshot of this frame saved to: " + p_sfnam
        screenshot = self.marionette.screenshot()[22:]
        with open(p_sfnam, 'w') as f:
            f.write(base64.decodestring(screenshot))
        f.close()

        print "HTML dump of this frame saved to : " + p_hfnam
        f = open(p_hfnam, 'w')
        f.write(self.marionette.page_source.encode('ascii', 'ignore') )
        f.close()

        #
        # Test to see if the element is present / displayed / etc...
        #
        print ""
        print "Checking for element: " + str(p_el)
        b_present   = False
        b_displayed = False
        b_enabled   = False
        try:
            x = self.marionette.find_element(*p_el)
            if x:
                b_present = True
                
                if x.is_displayed():
                    b_displayed = True
                    
                if x.is_enabled():
                    b_enabled = True
        except:
            pass
        
        print ""
        print "Present  : " + str(b_present)
        print "Displayed: " + str(b_displayed)
        print "Enabled  : " + str(b_enabled)
        print ""
Ejemplo n.º 6
0
class B2gExecutor(Executor):
    def __init__(self, app_name, app_id, device=False):
        self.device = device
        if self.device:
            call(['adb', 'forward', 'tcp:2828', 'tcp:2828'])
        self._app_name = app_name
        self._app_id = app_id
        self._marionette = Marionette()
        self._marionette.start_session()
        self._gaia_apps = GaiaApps(self._marionette)
        self._gaia_data = GaiaData(self._marionette)
        self._gaia_device = GaiaDevice(self._marionette)
        ''' Deprecated
        # https://github.com/mozilla-b2g/gaia/blob/b568b7ae8adb6ee3651bd75acbaaedff86a08912/tests/python/gaia-ui-tests/gaiatest/gaia_test.py
        js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_apps.js"))
        self._marionette.import_script(js)
        js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_data_layer.js"))
        self._marionette.set_context(self._marionette.CONTEXT_CHROME)
        self._marionette.import_script(js)
        self._marionette.set_context(self._marionette.CONTEXT_CONTENT)

        # C:\Users\Jun-Wei\Desktop\b2g\battery\manifest.webapp
        #app = GaiaApps(self._marionette).launch(self._app_name)
        #app = GaiaApps(self._marionette).launch('Battery', manifest_url='C:/Users/Jun-Wei/Desktop/b2g/battery/manifest.webapp', entry_point='/index.html')

        app = GaiaApps(self._marionette).launch('Battery')
        print app.frame
        print app.src
        print app.origin
        print app.name
        #print g_app.manifest_url

        #self._app_frame = g_app.frame
        self._app_frame_id = app.frame
        self._app_src = app.src
        self._app_origin = app.origin
        #self.app_manifest_url = g_app.manifest_url

        #self.gaia_apps = GaiaApps(self.__marionette)
        #print self.gaia_apps.displayed_app.name
        #print self.gaia_apps.installed_apps
        #print self.gaia_apps.running_apps()
        #js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_apps.js"))
        #self.__marionette.import_script(js)
        '''

    def fire_event(self, clickable):
        logger.info('fire_event: id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
        try:
            # id staring with DomAnalyzer.serial_prefix is given by our monkey and should be ignored when locating
            if clickable.get_id() and not clickable.get_id().startswith(DomAnalyzer.serial_prefix):
                self._marionette.find_element('id', clickable.get_id()).tap()
            elif clickable.get_xpath():
                self._marionette.find_element('xpath', clickable.get_xpath()).tap()
            else:
                logger.error('No id nor xpath for the clickable: id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
                sys.exit()
        except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
            logger.info('Element is not interactable in fire_event(): id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
        except Exception as e:
            logger.error('Unknown Exception: %s in fire_event(): id: %s (xpath: %s)', str(e), clickable.get_id(), clickable.get_xpath())
            sys.exit()

    def fill_form(self, clickable):
        for f in clickable.get_forms():
            for input_field in f.get_inputs():
                try:
                    if input_field.get_id() and not input_field.get_id().startswith(DomAnalyzer.serial_prefix):
                        self._marionette.find_element('id', input_field.get_id()).send_keys(input_field.get_value())
                    elif input_field.get_xpath():
                        self._marionette.find_element('xpath', input_field.get_xpath()).send_keys(input_field.get_value())
                    else:
                        logger.error('No id nor xpath for an input field in the form id: %s (xpath: %s)', f.get_id(), f.get_xpath())
                        sys.exit()
                except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
                    logger.info('Element is not interactable in fill_form(): id: %s (xpath: %s)', f.get_id(), f.get_xpath())
                except Exception as e:
                    logger.error('Unknown Exception: %s in fill_form(): id: %s (xpath: %s)', str(e), f.get_id(), f.get_xpath())
                    sys.exit()

    def empty_form(self, clickable):
        for f in clickable.get_forms():
            for input_field in f.get_inputs():
                try:
                    if input_field.get_id() and not input_field.get_id().startswith(DomAnalyzer.serial_prefix):
                        self._marionette.find_element('id', input_field.get_id()).clear()
                    elif input_field.get_xpath():
                        self._marionette.find_element('xpath', input_field.get_xpath()).clear()
                    else:
                        logger.error('No id nor xpath for an input field in the form %s (%s)', f.get_id(), f.get_xpath())
                        sys.exit()
                except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
                    logger.info('Element is not interactable in empty_form(): id: %s (xpath: %s)', f.get_id(), f.get_xpath())
                except Exception as e:
                    logger.error('Unknown Exception: %s in empty_form(): id: %s (xpath: %s)', str(e), f.get_id(), f.get_xpath())
                    sys.exit()

    def get_source(self):
        return self._marionette.page_source.encode(sys.stdout.encoding, 'ignore')

    def get_screenshot(self, clickable=None):
        element = None
        if clickable:
            try:
                if clickable.get_id() and not clickable.get_id().startswith(DomAnalyzer.serial_prefix):
                    element = self._marionette.find_element('id', clickable.get_id())
                elif clickable.get_xpath():
                    element = self._marionette.find_element('xpath', clickable.get_xpath())
                else:
                    logger.error('No id nor xpath for the clickable: id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
                    sys.exit()
            except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
                logger.info('Element is not interactable in get_screenshot(): id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
            except Exception as e:
                logger.error('Unknown Exception: %s in get_screenshot(): id: %s (xpath: %s)', str(e), clickable.get_id(), clickable.get_xpath())
                sys.exit()
        if not element:
            # set context to CHROME to capture whole screen
            # system frame e.g. FileNotFound cannot be captured without CONTEXT_CHROME (Don't know why)
            self._marionette.set_context(self._marionette.CONTEXT_CHROME)
        screenshot = self._marionette.screenshot(element)
        self._marionette.set_context(self._marionette.CONTEXT_CONTENT)
        return screenshot

    def switch_to_frame(self, by, frame_str):
        """
        :param by: options: "id", "xpath", "link text", "partial link text", "name",
        "tag name", "class name", "css selector", "anon attribute"
        """
        # self.switch_to_top_frame()
        frame = self._marionette.find_element(by, frame_str)
        self._marionette.switch_to_frame(frame)

    def switch_to_top_frame(self):
        self._marionette.switch_to_frame()  # switch to the top-level frame

    def restart_app(self):
        # remember to disable screen timeout and screen lock before testing
        # todo: open b2g simulator, install app,
        # unlock_screen
        # self._marionette.execute_script('window.wrappedJSObject.lockScreen.unlock();')

        self.kill_all_apps()
        # kill_all_apps() will also kill the 'homescreen app' on real device
        # so trigger a home event to restore homescreen
        if self.device:
            self._dispatch_home_button_event()
        self.clear_data()
        self.touch_home_button()

        # launch the app
        self._gaia_apps.launch(self._app_name)
        ''' Deprecated
        if self.device:
            icon = self._marionette.find_element('xpath', "//li[contains(@aria-label, '" + self._app_name + "')]")
        else:
            icon = self._marionette.find_element('xpath', "//div[contains(@class, 'icon')]//span[contains(text(),'" + self._app_name + "')]")
        icon.tap()
        '''
        time.sleep(5)  # wait for app screen
        self._marionette.switch_to_frame()
        # this wait seems not working, need to find another useful one
        Wait(self._marionette).until(lambda m: m.find_element('css selector', "iframe[data-url*='" + self._app_id + "']").is_displayed())
        app_frame = self._marionette.find_element('css selector', "iframe[data-url*='" + self._app_id + "']")
        self._marionette.switch_to_frame(app_frame)

    def touch_home_button(self):
        # ref: https://github.com/mozilla-b2g/gaia/blob/master/tests/python/gaia-ui-tests/gaiatest/gaia_test.py#L751
        apps = self._gaia_apps
        if apps.displayed_app.name.lower() != 'homescreen':
            # touching home button will return to homescreen
            self._dispatch_home_button_event()
            Wait(self._marionette).until(
                lambda m: apps.displayed_app.name.lower() == 'homescreen')
            apps.switch_to_displayed_app()
        else:
            apps.switch_to_displayed_app()
            mode = self._marionette.find_element(By.TAG_NAME, 'body').get_attribute('class')
            self._dispatch_home_button_event()
            apps.switch_to_displayed_app()
            if 'edit-mode' in mode:
                # touching home button will exit edit mode
                Wait(self._marionette).until(lambda m: m.find_element(
                    By.TAG_NAME, 'body').get_attribute('class') != mode)
            else:
                # touching home button inside homescreen will scroll it to the top
                Wait(self._marionette).until(lambda m: m.execute_script(
                    "return window.wrappedJSObject.scrollY") == 0)

    def _dispatch_home_button_event(self):
        self._gaia_device._dispatch_home_button_event()
        ''' Deprecated
        self._marionette.switch_to_frame()
        self._marionette.execute_script("window.wrappedJSObject.dispatchEvent(new Event('home'));")
        '''
        time.sleep(0.5)

    def clear_data(self):
        # for now, clear contact data
        # https://github.com/mozilla-b2g/gaia/blob/v2.2/tests/python/gaia-ui-tests/gaiatest/gaia_test.py#L208
        self._marionette.set_context(self._marionette.CONTEXT_CHROME)
        result = self._marionette.execute_async_script('return GaiaDataLayer.removeAllContacts();')
        assert result, 'Unable to remove all contacts'
        self._marionette.set_context(self._marionette.CONTEXT_CONTENT)
        time.sleep(0.5)

    def kill_all_apps(self):
        self._marionette.switch_to_frame()
        self._marionette.execute_async_script("""
        // Kills all running apps, except the homescreen.
        function killAll() {
          let manager = window.wrappedJSObject.appWindowManager;

          let apps = manager.getApps();
          for (let id in apps) {
            let origin = apps[id].origin;
            if (origin.indexOf('verticalhome') == -1) {
              manager.kill(origin);
            }
          }
        };
        killAll();
        // return true so execute_async_script knows the script is complete
        marionetteScriptFinished(true);
        """)
        time.sleep(0.5)
Ejemplo n.º 7
0
def ftu(locale, device_flags, hashes):

    db = get_db(locale)

    app = 'ftu'
    app_categ = 'communications'
    app_type = 'apps'
    gaia_hash = hashes[0]
    hg_hash = hashes[1]
    screenshot_path = app_type + '/' + app_categ + '/' + app

    create_screenshot_dir(locale, screenshot_path)

    client = Marionette('localhost', 2828)
    client.start_session()

    change_screen_timeout(client)

    ftu_iframe = client.find_element(
        'css selector',
        "iframe[src='app://communications.gaiamobile.org/ftu/index.html']")

    if client.switch_to_frame(ftu_iframe):

        time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#languages
        file_name = 'languages'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#activation-screen')

            # switch to app://communications.gaiamobile.org/ftu/index.html#data_3g (unlock-sim-screen screen)
            next = client.find_element('css selector', '#forward')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim pin screen - unlock-sim-screen - 1st attempt)
        file_name = 'data_3g-unlock_sim_screen-pin_screen'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # invalid pin -> error about pin characters
            # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (unlock-sim-screen screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim pin screen - unlock-sim-screen - pin error)
        file_name = 'data_3g-unlock_sim_screen-pin_screen-invalid_pin'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # insert wrong pin (attempt 1 of 3)
            pin_input = client.find_element('css selector', '#pin-input')
            pin_input.send_keys(wrong_sim_pin)

            # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (unlock-sim-screen screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim pin screen - unlock-sim-screen - 2nd attempt)
        file_name = 'data_3g-unlock_sim_screen-pin_screen-wrong_pin-1st_time'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # insert wrong pin (attempt 2 of 3)
            pin_input = client.find_element('css selector', '#pin-input')
            pin_input.send_keys(wrong_sim_pin)

            # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (unlock-sim-screen screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim pin screen - unlock-sim-screen - 3rd attempt)
        file_name = 'data_3g-unlock_sim_screen-pin_screen-wrong_pin-2nd_time'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # insert wrong pin (atempt 3 of 3) - continues to puk screen
            pin_input = client.find_element('css selector', '#pin-input')
            pin_input.send_keys(wrong_sim_pin)

            # switch to app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

            # tap the header in order to hide keyboard and get full screenshot of the puk screen
            header = client.find_element('css selector', '#unlock-sim-header')
            header.tap()

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - 1st attempt)
        file_name = 'data_3g-unlock_sim_screen-puk_screen'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # invalid puk -> error about puk characters
            # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - puk error)
        file_name = 'data_3g-unlock_sim_screen-puk_screen-invalid_puk'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # insert wrong puk - invalid new pin -> error about pin characters
            puk_input = client.find_element('css selector', '#puk-input')
            puk_input.send_keys(wrong_sim_puk)

            # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - pin error)
        file_name = 'data_3g-unlock_sim_screen-puk_screen-invalid_new_pin'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # insert new pin without confirmed it -> error about pin confirmation (wrong puk is preserved at its input)
            newpin_input = client.find_element('css selector', '#newpin-input')
            newpin_input.send_keys(sim_pin)

            # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - pin error)
        file_name = 'data_3g-unlock_sim_screen-puk_screen-invalid_new_pin_confirmation'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # insert confirmation of the new pin (wrong puk and new pin are preserved at their inputs)
            newpin_input = client.find_element('css selector',
                                               '#confirm-newpin-input')
            newpin_input.send_keys(sim_pin)

            # wrong puk (attempt 1 of 9)
            # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - puk error)
        file_name = 'data_3g-unlock_sim_screen-puk_screen-wrong_puk-1st_time'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # insert wrong puk (attempt 2 of 9) (new pin and its confirmation are preserved at their inputs)
            puk_input = client.find_element('css selector', '#puk-input')
            puk_input.send_keys(wrong_sim_puk)

            # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - 2nd attempt)
        file_name = 'data_3g-unlock_sim_screen-puk_screen-wrong_puk-2nd_time'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#unlock-sim-screen')

            # insert right puk (attempt 2 of 9) (new pin and its confirmation are preserved at their inputs)
            puk_input = client.find_element('css selector', '#puk-input')
            puk_input.send_keys(sim_puk)

            # switch to app://communications.gaiamobile.org/ftu/index.html#data_3g
            next = client.find_element('css selector', '#unlock-sim-button')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#data_3g
        file_name = 'data_3g'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {"sim": True, "no-sim": False}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#activation-screen')

            # switch to app://communications.gaiamobile.org/ftu/index.html#wifi
            next = client.find_element('css selector', '#forward')
            next.tap()
            time.sleep(long_time)

            # enable overlay "scanningNetworks" spinner screen (loading-overlay)
            client.execute_script(
                "window.wrappedJSObject.utils.overlay.show('scanningNetworks', 'spinner');"
            )
            time.sleep(middle_time)

        # overlay "scanningNetworks" spinner screen
        file_name = 'wifi-loading_overlay-scanning_networks'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#loading-overlay')

            # disable overlay "scanningNetworks" spinner screen
            client.execute_script(
                "window.wrappedJSObject.utils.overlay.hide('scanningNetworks', 'spinner');"
            )
            time.sleep(middle_time)

        # app://communications.gaiamobile.org/ftu/index.html#wifi
        file_name = 'wifi'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#wifi')

            # switch to app://communications.gaiamobile.org/ftu/index.html#date_and_time
            next = client.find_element('css selector', '#forward')
            next.tap()
            time.sleep(short_time)

        # Set time in order to be the same at every screenshot
        set_time(client)

        # app://communications.gaiamobile.org/ftu/index.html#date_and_time
        file_name = 'date_and_time'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#date_and_time')

            # switch to app://communications.gaiamobile.org/ftu/index.html#geolocation
            next = client.find_element('css selector', '#forward')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#geolocation
        file_name = 'geolocation'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#geolocation')

            # switch to app://communications.gaiamobile.org/ftu/index.html#import_contacts
            next = client.find_element('css selector', '#forward')
            next.tap()
            time.sleep(middle_time)

        # app://communications.gaiamobile.org/ftu/index.html#import_contacts
        file_name = 'import_contacts'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry, '#import_contacts')

            # switch to app://communications.gaiamobile.org/ftu/index.html#welcome_browser
            next = client.find_element('css selector', '#forward')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#welcome_browser
        file_name = 'welcome_browser'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry)

            # switch to app://communications.gaiamobile.org/ftu/index.html#browser_privacy
            next = client.find_element('css selector', '#forward')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#browser_privacy
        file_name = 'browser_privacy'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry)

            # switch to app://communications.gaiamobile.org/ftu/index.html#step1 (first tutorial screen)
            next = client.find_element('css selector', '#forward')
            next.tap()
            time.sleep(long_time)

        # app://communications.gaiamobile.org/ftu/index.html#step1 (first tutorial screen)
        file_name = 'step1-first_tutorial_screen'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry)

            # switch to app://communications.gaiamobile.org/ftu/index.html#step1
            next = client.find_element('css selector', '#lets-go-button')
            next.tap()
            time.sleep(long_time)

        # app://communications.gaiamobile.org/ftu/index.html#step1
        file_name = 'step1'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry)

            # switch to app://communications.gaiamobile.org/ftu/index.html#step2
            next = client.find_element('css selector', '#forwardTutorial')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#step2
        file_name = 'step2'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry)

            # switch to app://communications.gaiamobile.org/ftu/index.html#step3
            next = client.find_element('css selector', '#forwardTutorial')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#step3
        file_name = 'step3'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry)

            # switch to app://communications.gaiamobile.org/ftu/index.html#step4
            next = client.find_element('css selector', '#forwardTutorial')
            next.tap()
            time.sleep(short_time)

        # app://communications.gaiamobile.org/ftu/index.html#step4
        file_name = 'step4'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry)

            # switch to app://communications.gaiamobile.org/ftu/index.html#step4 (last tutorial screen)
            next = client.find_element('css selector', '#forwardTutorial')
            next.tap()
            time.sleep(long_time)

        # app://communications.gaiamobile.org/ftu/index.html#step4 (last tutorial screen)
        file_name = 'step4-last_tutorial_screen'
        screenshot_entry = {
            "id": file_name,
            "script": app,
            "gaia": gaia_hash,
            "hg": hg_hash,
            "changed": False,
            "path": screenshot_path
        }
        test_flags = {}
        if check_flags(test_flags, device_flags):
            screenshot_entry.update(test_flags)
            if take_screenshot(locale, screenshot_path, client, file_name):
                screenshot_entry['changed'] = True
            log_displayed_l10n_strings(client, db, app, app_categ,
                                       screenshot_entry)

            # Close ftu frame
            next = client.find_element('css selector', '#tutorialFinished')
            next.tap()
            time.sleep(short_time)

        set_db(locale, db)

    else:
        #TO DO raise proper error
        print "switch to ftu frame failed"
Ejemplo n.º 8
0
#encoding=utf-8
from marionette import Marionette

client = Marionette('localhost', port=2828)
client.start_session()
client.navigate('http://finance.sina.com.cn/stock/s/20150714/070922678344.shtml')#访问当前访问的网址
elem = client.find_element('xpath',"//*[@id='wrapOuter']/div/div[4]/span")
print(elem.text)
Ejemplo n.º 9
0
 assert(m.window == 'window2')
 assert(m.close_window('window2'))
 assert(m.set_script_timeout(1000))
 assert(m.set_search_timeout(500))
 assert(m.get_url() == server.TEST_URL)
 assert(m.navigate(server.TEST_URL))
 assert(m.go_back())
 assert(m.go_forward())
 assert(m.refresh())
 assert(m.execute_script(server.TEST_EXECUTE_SCRIPT))
 assert(m.execute_js_script(server.TEST_EXECUTE_SCRIPT))
 assert(m.execute_js_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS))
 assert(m.execute_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS))
 assert(m.execute_async_script(server.TEST_EXECUTE_SCRIPT))
 assert(m.execute_async_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS))
 assert(str(m.find_element(HTMLElement.CLASS, 'heading')) == server.TEST_FIND_ELEMENT)
 assert([str(x) for x in m.find_elements(HTMLElement.TAG, 'p')] == server.TEST_FIND_ELEMENTS)
 assert(str(m.find_element(HTMLElement.CLASS, 'heading').find_element(HTMLElement.TAG, 'h1')) == server.TEST_FIND_ELEMENT)
 assert([str(x) for x in m.find_element(HTMLElement.ID, 'div1').find_elements(HTMLElement.SELECTOR, '.main')] == \
     server.TEST_FIND_ELEMENTS)
 assert(m.find_element(HTMLElement.ID, 'id1').click())
 assert(m.find_element(HTMLElement.ID, 'id2').text() == server.TEST_GET_TEXT)
 assert(m.find_element(HTMLElement.ID, 'id3').send_keys('Mozilla Firefox'))
 assert(m.find_element(HTMLElement.ID, 'id3').value() == server.TEST_GET_VALUE)
 assert(m.find_element(HTMLElement.ID, 'id3').clear())
 assert(m.find_element(HTMLElement.ID, 'id3').selected())
 assert(m.find_element(HTMLElement.ID, 'id1').equals(m.find_element(HTMLElement.TAG, 'p')))
 assert(m.find_element(HTMLElement.ID, 'id3').enabled())
 assert(m.find_element(HTMLElement.ID, 'id3').displayed())
 assert(m.find_element(HTMLElement.ID, 'id3').get_attribute('value') == server.TEST_GET_VALUE)
 assert(m.delete_session())
Ejemplo n.º 10
0
 assert m.window == "window2"
 assert m.close_window("window2")
 assert m.set_script_timeout(1000)
 assert m.set_search_timeout(500)
 assert m.get_url() == server.TEST_URL
 assert m.navigate(server.TEST_URL)
 assert m.go_back()
 assert m.go_forward()
 assert m.refresh()
 assert m.execute_script(server.TEST_EXECUTE_SCRIPT)
 assert m.execute_js_script(server.TEST_EXECUTE_SCRIPT)
 assert m.execute_js_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS)
 assert m.execute_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS)
 assert m.execute_async_script(server.TEST_EXECUTE_SCRIPT)
 assert m.execute_async_script(server.TEST_EXECUTE_SCRIPT, server.TEST_EXECUTE_SCRIPT_ARGS)
 assert str(m.find_element(HTMLElement.CLASS, "heading")) == server.TEST_FIND_ELEMENT
 assert [str(x) for x in m.find_elements(HTMLElement.TAG, "p")] == server.TEST_FIND_ELEMENTS
 assert (
     str(m.find_element(HTMLElement.CLASS, "heading").find_element(HTMLElement.TAG, "h1"))
     == server.TEST_FIND_ELEMENT
 )
 assert [
     str(x) for x in m.find_element(HTMLElement.ID, "div1").find_elements(HTMLElement.SELECTOR, ".main")
 ] == server.TEST_FIND_ELEMENTS
 assert m.find_element(HTMLElement.ID, "id1").click()
 assert m.find_element(HTMLElement.ID, "id2").text() == server.TEST_GET_TEXT
 assert m.find_element(HTMLElement.ID, "id3").send_keys("Mozilla Firefox")
 assert m.find_element(HTMLElement.ID, "id3").value() == server.TEST_GET_VALUE
 assert m.find_element(HTMLElement.ID, "id3").clear()
 assert m.find_element(HTMLElement.ID, "id3").selected()
 assert m.find_element(HTMLElement.ID, "id1").equals(m.find_element(HTMLElement.TAG, "p"))
Ejemplo n.º 11
0
class B2gExecutor(Executor):
    def __init__(self, app_name, app_id, device=False):
        self.device = device
        if self.device:
            call(['adb', 'forward', 'tcp:2828', 'tcp:2828'])
        self._app_name = app_name
        self._app_id = app_id
        self._marionette = Marionette()
        self._marionette.start_session()
        self._gaia_apps = GaiaApps(self._marionette)
        self._gaia_data = GaiaData(self._marionette)
        self._gaia_device = GaiaDevice(self._marionette)
        ''' Deprecated
        # https://github.com/mozilla-b2g/gaia/blob/b568b7ae8adb6ee3651bd75acbaaedff86a08912/tests/python/gaia-ui-tests/gaiatest/gaia_test.py
        js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_apps.js"))
        self._marionette.import_script(js)
        js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_data_layer.js"))
        self._marionette.set_context(self._marionette.CONTEXT_CHROME)
        self._marionette.import_script(js)
        self._marionette.set_context(self._marionette.CONTEXT_CONTENT)

        # C:\Users\Jun-Wei\Desktop\b2g\battery\manifest.webapp
        #app = GaiaApps(self._marionette).launch(self._app_name)
        #app = GaiaApps(self._marionette).launch('Battery', manifest_url='C:/Users/Jun-Wei/Desktop/b2g/battery/manifest.webapp', entry_point='/index.html')

        app = GaiaApps(self._marionette).launch('Battery')
        print app.frame
        print app.src
        print app.origin
        print app.name
        #print g_app.manifest_url

        #self._app_frame = g_app.frame
        self._app_frame_id = app.frame
        self._app_src = app.src
        self._app_origin = app.origin
        #self.app_manifest_url = g_app.manifest_url

        #self.gaia_apps = GaiaApps(self.__marionette)
        #print self.gaia_apps.displayed_app.name
        #print self.gaia_apps.installed_apps
        #print self.gaia_apps.running_apps()
        #js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_apps.js"))
        #self.__marionette.import_script(js)
        '''

    def fire_event(self, clickable):
        logger.info('fire_event: id: %s (xpath: %s)', clickable.get_id(),
                    clickable.get_xpath())
        try:
            # id staring with DomAnalyzer.serial_prefix is given by our monkey and should be ignored when locating
            if clickable.get_id() and not clickable.get_id().startswith(
                    DomAnalyzer.serial_prefix):
                self._marionette.find_element('id', clickable.get_id()).tap()
            elif clickable.get_xpath():
                self._marionette.find_element('xpath',
                                              clickable.get_xpath()).tap()
            else:
                logger.error(
                    'No id nor xpath for the clickable: id: %s (xpath: %s)',
                    clickable.get_id(), clickable.get_xpath())
                sys.exit()
        except (ElementNotVisibleException, InvalidElementStateException,
                NoSuchElementException):
            logger.info(
                'Element is not interactable in fire_event(): id: %s (xpath: %s)',
                clickable.get_id(), clickable.get_xpath())
        except Exception as e:
            logger.error(
                'Unknown Exception: %s in fire_event(): id: %s (xpath: %s)',
                str(e), clickable.get_id(), clickable.get_xpath())
            sys.exit()

    def fill_form(self, clickable):
        for f in clickable.get_forms():
            for input_field in f.get_inputs():
                try:
                    if input_field.get_id() and not input_field.get_id(
                    ).startswith(DomAnalyzer.serial_prefix):
                        self._marionette.find_element(
                            'id', input_field.get_id()).send_keys(
                                input_field.get_value())
                    elif input_field.get_xpath():
                        self._marionette.find_element(
                            'xpath', input_field.get_xpath()).send_keys(
                                input_field.get_value())
                    else:
                        logger.error(
                            'No id nor xpath for an input field in the form id: %s (xpath: %s)',
                            f.get_id(), f.get_xpath())
                        sys.exit()
                except (ElementNotVisibleException,
                        InvalidElementStateException, NoSuchElementException):
                    logger.info(
                        'Element is not interactable in fill_form(): id: %s (xpath: %s)',
                        f.get_id(), f.get_xpath())
                except Exception as e:
                    logger.error(
                        'Unknown Exception: %s in fill_form(): id: %s (xpath: %s)',
                        str(e), f.get_id(), f.get_xpath())
                    sys.exit()

    def empty_form(self, clickable):
        for f in clickable.get_forms():
            for input_field in f.get_inputs():
                try:
                    if input_field.get_id() and not input_field.get_id(
                    ).startswith(DomAnalyzer.serial_prefix):
                        self._marionette.find_element(
                            'id', input_field.get_id()).clear()
                    elif input_field.get_xpath():
                        self._marionette.find_element(
                            'xpath', input_field.get_xpath()).clear()
                    else:
                        logger.error(
                            'No id nor xpath for an input field in the form %s (%s)',
                            f.get_id(), f.get_xpath())
                        sys.exit()
                except (ElementNotVisibleException,
                        InvalidElementStateException, NoSuchElementException):
                    logger.info(
                        'Element is not interactable in empty_form(): id: %s (xpath: %s)',
                        f.get_id(), f.get_xpath())
                except Exception as e:
                    logger.error(
                        'Unknown Exception: %s in empty_form(): id: %s (xpath: %s)',
                        str(e), f.get_id(), f.get_xpath())
                    sys.exit()

    def get_source(self):
        return self._marionette.page_source.encode(sys.stdout.encoding,
                                                   'ignore')

    def get_screenshot(self, clickable=None):
        element = None
        if clickable:
            try:
                if clickable.get_id() and not clickable.get_id().startswith(
                        DomAnalyzer.serial_prefix):
                    element = self._marionette.find_element(
                        'id', clickable.get_id())
                elif clickable.get_xpath():
                    element = self._marionette.find_element(
                        'xpath', clickable.get_xpath())
                else:
                    logger.error(
                        'No id nor xpath for the clickable: id: %s (xpath: %s)',
                        clickable.get_id(), clickable.get_xpath())
                    sys.exit()
            except (ElementNotVisibleException, InvalidElementStateException,
                    NoSuchElementException):
                logger.info(
                    'Element is not interactable in get_screenshot(): id: %s (xpath: %s)',
                    clickable.get_id(), clickable.get_xpath())
            except Exception as e:
                logger.error(
                    'Unknown Exception: %s in get_screenshot(): id: %s (xpath: %s)',
                    str(e), clickable.get_id(), clickable.get_xpath())
                sys.exit()
        if not element:
            # set context to CHROME to capture whole screen
            # system frame e.g. FileNotFound cannot be captured without CONTEXT_CHROME (Don't know why)
            self._marionette.set_context(self._marionette.CONTEXT_CHROME)
        screenshot = self._marionette.screenshot(element)
        self._marionette.set_context(self._marionette.CONTEXT_CONTENT)
        return screenshot

    def switch_to_frame(self, by, frame_str):
        """
        :param by: options: "id", "xpath", "link text", "partial link text", "name",
        "tag name", "class name", "css selector", "anon attribute"
        """
        # self.switch_to_top_frame()
        frame = self._marionette.find_element(by, frame_str)
        self._marionette.switch_to_frame(frame)

    def switch_to_top_frame(self):
        self._marionette.switch_to_frame()  # switch to the top-level frame

    def restart_app(self):
        # remember to disable screen timeout and screen lock before testing
        # todo: open b2g simulator, install app,
        # unlock_screen
        # self._marionette.execute_script('window.wrappedJSObject.lockScreen.unlock();')

        self.kill_all_apps()
        # kill_all_apps() will also kill the 'homescreen app' on real device
        # so trigger a home event to restore homescreen
        if self.device:
            self._dispatch_home_button_event()
        self.clear_data()
        self.touch_home_button()

        # launch the app
        self._gaia_apps.launch(self._app_name)
        ''' Deprecated
        if self.device:
            icon = self._marionette.find_element('xpath', "//li[contains(@aria-label, '" + self._app_name + "')]")
        else:
            icon = self._marionette.find_element('xpath', "//div[contains(@class, 'icon')]//span[contains(text(),'" + self._app_name + "')]")
        icon.tap()
        '''
        time.sleep(5)  # wait for app screen
        self._marionette.switch_to_frame()
        # this wait seems not working, need to find another useful one
        Wait(self._marionette).until(lambda m: m.find_element(
            'css selector', "iframe[data-url*='" + self._app_id + "']").
                                     is_displayed())
        app_frame = self._marionette.find_element(
            'css selector', "iframe[data-url*='" + self._app_id + "']")
        self._marionette.switch_to_frame(app_frame)

    def touch_home_button(self):
        # ref: https://github.com/mozilla-b2g/gaia/blob/master/tests/python/gaia-ui-tests/gaiatest/gaia_test.py#L751
        apps = self._gaia_apps
        if apps.displayed_app.name.lower() != 'homescreen':
            # touching home button will return to homescreen
            self._dispatch_home_button_event()
            Wait(self._marionette).until(
                lambda m: apps.displayed_app.name.lower() == 'homescreen')
            apps.switch_to_displayed_app()
        else:
            apps.switch_to_displayed_app()
            mode = self._marionette.find_element(By.TAG_NAME,
                                                 'body').get_attribute('class')
            self._dispatch_home_button_event()
            apps.switch_to_displayed_app()
            if 'edit-mode' in mode:
                # touching home button will exit edit mode
                Wait(self._marionette).until(lambda m: m.find_element(
                    By.TAG_NAME, 'body').get_attribute('class') != mode)
            else:
                # touching home button inside homescreen will scroll it to the top
                Wait(self._marionette).until(lambda m: m.execute_script(
                    "return window.wrappedJSObject.scrollY") == 0)

    def _dispatch_home_button_event(self):
        self._gaia_device._dispatch_home_button_event()
        ''' Deprecated
        self._marionette.switch_to_frame()
        self._marionette.execute_script("window.wrappedJSObject.dispatchEvent(new Event('home'));")
        '''
        time.sleep(0.5)

    def clear_data(self):
        # for now, clear contact data
        # https://github.com/mozilla-b2g/gaia/blob/v2.2/tests/python/gaia-ui-tests/gaiatest/gaia_test.py#L208
        self._marionette.set_context(self._marionette.CONTEXT_CHROME)
        result = self._marionette.execute_async_script(
            'return GaiaDataLayer.removeAllContacts();')
        assert result, 'Unable to remove all contacts'
        self._marionette.set_context(self._marionette.CONTEXT_CONTENT)
        time.sleep(0.5)

    def kill_all_apps(self):
        self._marionette.switch_to_frame()
        self._marionette.execute_async_script("""
        // Kills all running apps, except the homescreen.
        function killAll() {
          let manager = window.wrappedJSObject.appWindowManager;

          let apps = manager.getApps();
          for (let id in apps) {
            let origin = apps[id].origin;
            if (origin.indexOf('verticalhome') == -1) {
              manager.kill(origin);
            }
          }
        };
        killAll();
        // return true so execute_async_script knows the script is complete
        marionetteScriptFinished(true);
        """)
        time.sleep(0.5)
Ejemplo n.º 12
0
def uninstall_app(app_name, adb_path="adb", script_timeout=5000, marionette=None, device_serial=None):
    """
    Uninstalls the given app.

    NOTE: if a marionette session is passed, this function switches to the top-most frame.
    """

    def check_uninstall(marionette):
        uninstall = marionette.execute_script("return window.wrappedJSObject.uninstall;")
        return uninstall != 'none'

    def check_click_uninstall(marionette):
        button = marionette.find_element('css selector', 'gaia-confirm .confirm')
        try:
            button.click()
            not_displayed = not button.is_displayed()
        except StaleElementException:
            not_displayed = True
        return not_displayed

    dm = mozdevice.DeviceManagerADB(adbPath=adb_path, deviceSerial=device_serial)
    installed_app_name = app_name.lower()
    installed_app_name = installed_app_name.replace(" ", "-")
    dm.forward("tcp:2828", "tcp:2828")

    print 'requesting uninstall of app', app_name
    if not marionette:
        m = Marionette()
        m.start_session()
    else:
        m = marionette
        m.switch_to_frame()

    m.set_context("chrome")
    m.execute_script("""
    Components.utils.import("resource://gre/modules/Services.jsm");
    window.wrappedJSObject.uninstall = 'none';
    Services.obs.addObserver(function observer(subject, topic) {
        Services.obs.removeObserver(observer, topic);
        window.wrappedJSObject.uninstall = 'ask';
        }, "webapps-ask-uninstall", false);
    Services.obs.addObserver(function observer(subject, topic) {
        Services.obs.removeObserver(observer, topic);
        window.wrappedJSObject.uninstall = 'uninstall';
        }, "webapps-uninstall", false);
        """)
    m.set_context("content")

    uninstall_app = """
    var uninstallWithName = function(name) {
        let apps = window.wrappedJSObject.applications || window.wrappedJSObject.Applications;
        let installedApps = apps.installedApps;
        for (let manifestURL in installedApps) {
          let app = installedApps[manifestURL];
          let origin = null;
          let entryPoints = app.manifest.entry_points;
          if (entryPoints) {
            for (let ep in entryPoints) {
              let currentEntryPoint = entryPoints[ep];
              let appName = currentEntryPoint.name;
              if (name == appName.toLowerCase()) {
                window.wrappedJSObject.navigator.mozApps.mgmt.uninstall(app);
                return true;
              }
            }
          } else {
            let appName = app.manifest.name;
            if (name == appName.toLowerCase()) {
              window.wrappedJSObject.navigator.mozApps.mgmt.uninstall(app);
              return true;
            }
          }
        }
        return false;
      };
    return uninstallWithName("%s");
    """
    m.set_script_timeout(script_timeout)
    result = m.execute_script(uninstall_app % app_name.lower())

    if result:
        m.set_context("chrome")
        Wait(m, 10).until(check_uninstall)
        uninstall = m.execute_script("return window.wrappedJSObject.uninstall;")
        m.set_context("content")
        if uninstall == 'ask':
            m.switch_to_frame()
            Wait(m, 20).until(element_displayed(m.find_element('css selector', 'gaia-confirm .confirm')))
            Wait(m, 20).until(check_click_uninstall)

    if not marionette:
        m.delete_session()
Ejemplo n.º 13
0
def ftu(locale, device_flags, hashes):

  db = get_db(locale)

  app = 'ftu'
  app_categ = 'communications'
  app_type = 'apps'
  gaia_hash = hashes[0]
  hg_hash = hashes[1]
  screenshot_path = app_type + '/' + app_categ + '/' + app

  create_screenshot_dir(locale, screenshot_path)

  client = Marionette('localhost', 2828)
  client.start_session()

  change_screen_timeout(client) 

  ftu_iframe = client.find_element('css selector',"iframe[src='app://communications.gaiamobile.org/ftu/index.html']")

  if client.switch_to_frame(ftu_iframe):

    time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#languages 
    file_name = 'languages'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#activation-screen')


      # switch to app://communications.gaiamobile.org/ftu/index.html#data_3g (unlock-sim-screen screen)
      next = client.find_element('css selector', '#forward')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim pin screen - unlock-sim-screen - 1st attempt)
    file_name = 'data_3g-unlock_sim_screen-pin_screen'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # invalid pin -> error about pin characters
      # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (unlock-sim-screen screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim pin screen - unlock-sim-screen - pin error)
    file_name = 'data_3g-unlock_sim_screen-pin_screen-invalid_pin'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # insert wrong pin (attempt 1 of 3)
      pin_input = client.find_element('css selector', '#pin-input')
      pin_input.send_keys(wrong_sim_pin)

      # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (unlock-sim-screen screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)
    
    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim pin screen - unlock-sim-screen - 2nd attempt)
    file_name = 'data_3g-unlock_sim_screen-pin_screen-wrong_pin-1st_time'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # insert wrong pin (attempt 2 of 3)
      pin_input = client.find_element('css selector', '#pin-input')
      pin_input.send_keys(wrong_sim_pin)

      # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (unlock-sim-screen screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim pin screen - unlock-sim-screen - 3rd attempt)
    file_name = 'data_3g-unlock_sim_screen-pin_screen-wrong_pin-2nd_time'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # insert wrong pin (atempt 3 of 3) - continues to puk screen
      pin_input = client.find_element('css selector', '#pin-input')
      pin_input.send_keys(wrong_sim_pin)

      # switch to app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

      # tap the header in order to hide keyboard and get full screenshot of the puk screen
      header = client.find_element('css selector', '#unlock-sim-header')
      header.tap()

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - 1st attempt)
    file_name = 'data_3g-unlock_sim_screen-puk_screen'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # invalid puk -> error about puk characters
      # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - puk error)
    file_name = 'data_3g-unlock_sim_screen-puk_screen-invalid_puk'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # insert wrong puk - invalid new pin -> error about pin characters
      puk_input = client.find_element('css selector', '#puk-input')
      puk_input.send_keys(wrong_sim_puk)

      # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - pin error)
    file_name = 'data_3g-unlock_sim_screen-puk_screen-invalid_new_pin'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # insert new pin without confirmed it -> error about pin confirmation (wrong puk is preserved at its input)
      newpin_input = client.find_element('css selector', '#newpin-input')
      newpin_input.send_keys(sim_pin)

      # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - pin error)
    file_name = 'data_3g-unlock_sim_screen-puk_screen-invalid_new_pin_confirmation'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # insert confirmation of the new pin (wrong puk and new pin are preserved at their inputs)
      newpin_input = client.find_element('css selector', '#confirm-newpin-input')
      newpin_input.send_keys(sim_pin)

      # wrong puk (attempt 1 of 9)
      # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - puk error)
    file_name = 'data_3g-unlock_sim_screen-puk_screen-wrong_puk-1st_time'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # insert wrong puk (attempt 2 of 9) (new pin and its confirmation are preserved at their inputs)
      puk_input = client.find_element('css selector', '#puk-input')
      puk_input.send_keys(wrong_sim_puk)

      # stay at app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen)
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g (sim puk screen - unlock-sim-screen - 2nd attempt)
    file_name = 'data_3g-unlock_sim_screen-puk_screen-wrong_puk-2nd_time'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#unlock-sim-screen')


      # insert right puk (attempt 2 of 9) (new pin and its confirmation are preserved at their inputs)
      puk_input = client.find_element('css selector', '#puk-input')
      puk_input.send_keys(sim_puk)

      # switch to app://communications.gaiamobile.org/ftu/index.html#data_3g
      next = client.find_element('css selector', '#unlock-sim-button')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#data_3g
    file_name = 'data_3g'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {
      "sim": True,
      "no-sim": False}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#activation-screen')


      # switch to app://communications.gaiamobile.org/ftu/index.html#wifi
      next = client.find_element('css selector', '#forward')
      next.tap()
      time.sleep(long_time)

      # enable overlay "scanningNetworks" spinner screen (loading-overlay)
      client.execute_script("window.wrappedJSObject.utils.overlay.show('scanningNetworks', 'spinner');")
      time.sleep(middle_time)
    
    # overlay "scanningNetworks" spinner screen
    file_name = 'wifi-loading_overlay-scanning_networks'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#loading-overlay')


      # disable overlay "scanningNetworks" spinner screen
      client.execute_script("window.wrappedJSObject.utils.overlay.hide('scanningNetworks', 'spinner');")
      time.sleep(middle_time)

    # app://communications.gaiamobile.org/ftu/index.html#wifi
    file_name = 'wifi'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#wifi')


      # switch to app://communications.gaiamobile.org/ftu/index.html#date_and_time
      next = client.find_element('css selector', '#forward')
      next.tap()
      time.sleep(short_time)

    # Set time in order to be the same at every screenshot
    set_time(client)

    # app://communications.gaiamobile.org/ftu/index.html#date_and_time
    file_name = 'date_and_time'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#date_and_time')


      # switch to app://communications.gaiamobile.org/ftu/index.html#geolocation
      next = client.find_element('css selector', '#forward')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#geolocation
    file_name = 'geolocation'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#geolocation')


      # switch to app://communications.gaiamobile.org/ftu/index.html#import_contacts
      next = client.find_element('css selector', '#forward')
      next.tap()
      time.sleep(middle_time)

    # app://communications.gaiamobile.org/ftu/index.html#import_contacts
    file_name = 'import_contacts'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry, '#import_contacts')


      # switch to app://communications.gaiamobile.org/ftu/index.html#welcome_browser
      next = client.find_element('css selector', '#forward')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#welcome_browser
    file_name = 'welcome_browser'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry)


      # switch to app://communications.gaiamobile.org/ftu/index.html#browser_privacy
      next = client.find_element('css selector', '#forward')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#browser_privacy
    file_name = 'browser_privacy'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry)


      # switch to app://communications.gaiamobile.org/ftu/index.html#step1 (first tutorial screen)
      next = client.find_element('css selector', '#forward')
      next.tap()
      time.sleep(long_time)

    # app://communications.gaiamobile.org/ftu/index.html#step1 (first tutorial screen)
    file_name = 'step1-first_tutorial_screen'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry)


      # switch to app://communications.gaiamobile.org/ftu/index.html#step1
      next = client.find_element('css selector', '#lets-go-button')
      next.tap()
      time.sleep(long_time)

    # app://communications.gaiamobile.org/ftu/index.html#step1
    file_name = 'step1'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry)


      # switch to app://communications.gaiamobile.org/ftu/index.html#step2
      next = client.find_element('css selector', '#forwardTutorial')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#step2
    file_name = 'step2'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry)


      # switch to app://communications.gaiamobile.org/ftu/index.html#step3
      next = client.find_element('css selector', '#forwardTutorial')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#step3
    file_name = 'step3'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry)


      # switch to app://communications.gaiamobile.org/ftu/index.html#step4
      next = client.find_element('css selector', '#forwardTutorial')
      next.tap()
      time.sleep(short_time)

    # app://communications.gaiamobile.org/ftu/index.html#step4
    file_name = 'step4'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry)


      # switch to app://communications.gaiamobile.org/ftu/index.html#step4 (last tutorial screen)
      next = client.find_element('css selector', '#forwardTutorial')
      next.tap()
      time.sleep(long_time)

    # app://communications.gaiamobile.org/ftu/index.html#step4 (last tutorial screen)
    file_name = 'step4-last_tutorial_screen'
    screenshot_entry = {
      "id" : file_name,
      "script" : app,
      "gaia" : gaia_hash,
      "hg" : hg_hash,
      "changed" : False,
      "path" : screenshot_path}
    test_flags = {}
    if check_flags(test_flags, device_flags):
      screenshot_entry.update(test_flags)
      if take_screenshot(locale, screenshot_path, client, file_name):
        screenshot_entry['changed'] = True
      log_displayed_l10n_strings(client, db, app, app_categ, screenshot_entry)


      # Close ftu frame
      next = client.find_element('css selector', '#tutorialFinished')
      next.tap()
      time.sleep(short_time)

    set_db(locale, db)

  else:
  #TO DO raise proper error
    print "switch to ftu frame failed"