示例#1
0
 def get_marionette(self):
     if not self.m:
         self.m = Marionette(port=self.port)
         self.m.start_session()
         self.device = GaiaDevice(self.m)
         self.device.add_device_manager(self.dm)
         self.gaia_apps = GaiaApps(self.m)
     else:
         tries = 5
         while tries > 0:
             try:
                 self.m.get_url()
                 break
             except MarionetteException as e:
                 if "Please start a session" in str(e):
                     time.sleep(5)
                     self.m = Marionette(port=self.port)
                     self.m.start_session()
                     self.device = GaiaDevice(self.m)
                     self.device.add_device_manager(self.dm)
                     self.gaia_apps = GaiaApps(self.m)
                     tries -= 1
                 else:
                     raise e
         else:
             self.run_log.error("Can't connect to marionette, rebooting")
             self.restart_device()
     return self.m
示例#2
0
 def start_marionette(self):
     assert (self.baseurl is not None)
     if self.address:
         host, port = self.address.split(':')
         if self.emulator:
             self.marionette = Marionette(host=host,
                                          port=int(port),
                                          connectToRunningEmulator=True,
                                          homedir=self.homedir,
                                          baseurl=self.baseurl,
                                          logcat_dir=self.logcat_dir)
         if self.b2gbin:
             self.marionette = Marionette(host=host,
                                          port=int(port),
                                          b2gbin=self.b2gbin,
                                          baseurl=self.baseurl)
         else:
             self.marionette = Marionette(host=host,
                                          port=int(port),
                                          baseurl=self.baseurl)
     elif self.emulator:
         self.marionette = Marionette(emulator=self.emulator,
                                      emulatorBinary=self.emulatorBinary,
                                      homedir=self.homedir,
                                      baseurl=self.baseurl,
                                      noWindow=self.noWindow,
                                      logcat_dir=self.logcat_dir)
     else:
         raise Exception("must specify address or emulator")
 def get_marionette(self):
     if not self.m:
         self.m = Marionette(port=self.port)
         self.m.start_session()
         self.device = GaiaDevice(self.m)
         self.device.add_device_manager(self.dm)
         self.gaia_apps = GaiaApps(self.m)
     else:
         tries = 5
         while tries > 0:
             try:
                 self.m.get_url()
                 break
             except MarionetteException as e:
                 if "Please start a session" in str(e):
                     time.sleep(5)
                     self.m = Marionette(port=self.port)
                     self.m.start_session()
                     self.device = GaiaDevice(self.m)
                     self.device.add_device_manager(self.dm)
                     self.gaia_apps = GaiaApps(self.m)
                     tries -= 1
                 else:
                     raise e
         else:
             self.run_log.error("Can't connect to marionette, rebooting")
             self.restart_device()
     return self.m
 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")
示例#5
0
def cli():
    parser = OptionParser(usage='%prog gaia_atoms_path app_name [app_name] ...')

    options, args = parser.parse_args()

    if not args:
        parser.print_usage()
        parser.exit()

    if not os.path.isdir(args[0]):
        parser.print_usage()
        print 'must specify valid path for gaia atoms'
        parser.exit()

    if len(args) != 2:
        parser.print_usage()
        print 'must specify at one app name'
        parser.exit()

    marionette = Marionette(host='localhost', port=2828)  # TODO command line option for address
    marionette.start_session()
    launchApp(
        marionette,
        gaia_atoms=args[0],
        app_name=args[1])
示例#6
0
 def start_marionette(self):
     assert(self.baseurl is not None)
     if self.bin:
         if self.address:
             host, port = self.address.split(':')
         else:
             host = 'localhost'
             port = 2828
         self.marionette = Marionette(host=host, port=int(port),
                                      bin=self.bin, profile=self.profile,
                                      baseurl=self.baseurl)
     elif self.address:
         host, port = self.address.split(':')
         if self.emulator:
             self.marionette = Marionette(host=host, port=int(port),
                                          connectToRunningEmulator=True,
                                          homedir=self.homedir,
                                          baseurl=self.baseurl,
                                          logcat_dir=self.logcat_dir)
         else:
             self.marionette = Marionette(host=host,
                                          port=int(port),
                                          baseurl=self.baseurl)
     elif self.emulator:
         self.marionette = Marionette(emulator=self.emulator,
                                      emulatorBinary=self.emulatorBinary,
                                      emulatorImg=self.emulatorImg,
                                      emulator_res=self.emulator_res,
                                      homedir=self.homedir,
                                      baseurl=self.baseurl,
                                      noWindow=self.noWindow,
                                      logcat_dir=self.logcat_dir)
     else:
         raise Exception("must specify binary, address or emulator")
示例#7
0
 def run_marionette(self, dir):
     self.logger.info("Starting test run")
     # Start up marionette
     m = Marionette(emulator=True, homedir=dir)
     assert m.start_session()
     for test in self.testlist:
         run_test(test, m)
     m.delete_session()
 def get_new_emulator(self):
     _qemu  = Marionette(emulator=True,
                         homedir=self.marionette.homedir,
                         baseurl=self.marionette.baseurl,
                         noWindow=self.marionette.noWindow)
     _qemu.start_session()
     self._qemu.append(_qemu)
     return _qemu
示例#9
0
 def get_new_emulator(self):
     _qemu = Marionette(emulator=True,
                        homedir=self.marionette.homedir,
                        baseurl=self.marionette.baseurl,
                        noWindow=self.marionette.noWindow)
     _qemu.start_session()
     self._qemu.append(_qemu)
     return _qemu
示例#10
0
 def unplug_and_instruct(self, message):
     self.instruct(
         "Unplug the phone.\n%s\nPlug the phone back in after you are "
         "done, and unlock the screen if necessary.\n" % message)
     dm = mozdevice.DeviceManagerADB()
     dm.forward("tcp:2828", "tcp:2828")
     self.marionette = Marionette()
     self.marionette.start_session()
     self.use_cert_app()
示例#11
0
    def run_marionette_script(self):
        self.marionette = Marionette(**self.marionette_args)
        assert (self.marionette.wait_for_port())
        self.marionette.start_session()
        self.marionette.set_context(self.marionette.CONTEXT_CHROME)

        if os.path.isfile(self.test_script):
            f = open(self.test_script, 'r')
            self.test_script = f.read()
            f.close()
        self.marionette.execute_script(self.test_script)
示例#12
0
    def create_marionette():
        """Creates a new Marionette session if one does not exist."""

        m = TestCase.stored.marionette

        if not m:
            m = Marionette()
            m.start_session()
            TestCase.stored.marionette = m

        return TestCase.stored.marionette
示例#13
0
    def __init__(self, **kwargs):
        # Added parser
        parser = OptionParser()
        parser.add_option(
            '-a',
            '--address',
            action='store',
            type='string',
            dest='address',
            default='localhost',
            help='The host address of b2g instance. Default=localhost')
        parser.add_option('-p',
                          '--port',
                          action='store',
                          type='int',
                          dest='port',
                          default=2828,
                          help='The port of b2g instance.')
        parser.add_option('-l',
                          '--list',
                          action='store_true',
                          dest='enable_list',
                          default='False',
                          help='List all apps of b2g instance. Default=False')
        parser.add_option('-c', '--connect',
                          action='store', type='string', dest='connect',
                          default=None,
                          help='Connect to the App iframe.' \
                               'Use # ID or App URL to connect.')

        (options, args) = parser.parse_args()
        self.connect = options.connect

        # start marionette session
        self.m = Marionette(options.address, options.port)
        self.m.start_session()

        # list all iframes
        if options.enable_list:
            self.list_all_iframes()
        # list active iframes
        elif self.connect == None:
            self.list_active_iframes()

        # connect to App
        if self.connect == None:
            exit(0)
        else:
            # connect App
            print 'Start...'
            if self.open_app(self.connect):
                self.start_js()
            else:
                exit(-1)
示例#14
0
 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
示例#15
0
 def get_new_emulator(self):
     self.extra_emulator_index += 1
     if len(self.marionette.extra_emulators) == self.extra_emulator_index:
         qemu  = Marionette(emulator=self.marionette.emulator.arch,
                            homedir=self.marionette.homedir,
                            baseurl=self.marionette.baseurl,
                            noWindow=self.marionette.noWindow)
         qemu.start_session()
         self.marionette.extra_emulators.append(qemu)
     else:
         qemu = self.marionette.extra_emulators[self.extra_emulator_index]
     return qemu
示例#16
0
def get_marionette(args):
    mc = Marionette('localhost', args.adb_port)
    for i in range(3):
        try:
            mc.start_session()
            break
        # Catching SystemExit because tracebacks are suppressed.
        # This won't be necessary after
        # https://bugzilla.mozilla.org/show_bug.cgi?id=863377
        except (socket.error, SystemExit):
            sh('adb forward tcp:%s tcp:%s' % (args.adb_port, args.adb_port))
    return mc
示例#17
0
    def start_marionette(self):
        assert(self.baseurl is not None)
        if self.bin:
            if self.address:
                host, port = self.address.split(':')
            else:
                host = 'localhost'
                port = 2828
            self.marionette = Marionette(host=host,
                                         port=int(port),
                                         app=self.app,
                                         bin=self.bin,
                                         profile=self.profile,
                                         baseurl=self.baseurl,
                                         timeout=self.timeout)
        elif self.address:
            host, port = self.address.split(':')
            try:
                #establish a telnet connection so we can vertify the data come back
                tlconnection = Telnet(host, port)
            except:
                raise Exception("could not connect to given marionette host/port")

            if self.emulator:
                self.marionette = Marionette.getMarionetteOrExit(
                                             host=host, port=int(port),
                                             connectToRunningEmulator=True,
                                             homedir=self.homedir,
                                             baseurl=self.baseurl,
                                             logcat_dir=self.logcat_dir,
                                             gecko_path=self.gecko_path,
                                             symbols_path=self.symbols_path,
                                             timeout=self.timeout)
            else:
                self.marionette = Marionette(host=host,
                                             port=int(port),
                                             baseurl=self.baseurl,
                                             timeout=self.timeout)
        elif self.emulator:
            self.marionette = Marionette.getMarionetteOrExit(
                                         emulator=self.emulator,
                                         emulatorBinary=self.emulatorBinary,
                                         emulatorImg=self.emulatorImg,
                                         emulator_res=self.emulator_res,
                                         homedir=self.homedir,
                                         baseurl=self.baseurl,
                                         noWindow=self.noWindow,
                                         logcat_dir=self.logcat_dir,
                                         gecko_path=self.gecko_path,
                                         symbols_path=self.symbols_path,
                                         timeout=self.timeout)
        else:
            raise Exception("must specify binary, address or emulator")
示例#18
0
def get_marionette(args):
    mc = Marionette('localhost', args.adb_port)
    for i in range(3):
        try:
            mc.start_session()
            break
        # Catching SystemExit because tracebacks are suppressed.
        # This won't be necessary after
        # https://bugzilla.mozilla.org/show_bug.cgi?id=863377
        except (socket.error, SystemExit):
            sh('adb forward tcp:%s tcp:%s' % (args.adb_port, args.adb_port))
    return mc
示例#19
0
def ftu_toggler(skip_ftu=True):
    dm = mozdevice.DeviceManagerADB(runAdbAsRoot=True)
    dm.forward("tcp:2828", "tcp:2828")

    m = Marionette()
    m.start_session()
    data_layer = GaiaData(m)
    url = "null" if skip_ftu else "app://ftu.gaiamobile.org/manifest.webapp"
    data_layer.set_setting('ftu.manifestURL', url)
    m.close()

    # restart b2g to enable
    dm.reboot()
def startMarionette():
    # FW port for ADB via USB
    return_code = subprocess.call(["adb root"], shell=True)
    if return_code:
        raise Exception("Failed to start adb in root mode. Ensure device is attached to USB.")
    return_code = subprocess.call(["adb forward tcp:2828 tcp:2828"], shell=True)
    if return_code:
        raise Exception("Failed to connect to device via ADB; ensure device is attached to USB.")
    # Start Marionette
    marionette = Marionette(host='localhost', port=2828)
    marionette.start_session()
    marionette.set_script_timeout(60000)
    return marionette
示例#21
0
 def get_new_emulator(self):
     self.extra_emulator_index += 1
     if len(self.marionette.extra_emulators) == self.extra_emulator_index:
         qemu = Marionette(emulator=self.marionette.emulator.arch,
                           emulatorBinary=self.marionette.emulator.binary,
                           homedir=self.marionette.homedir,
                           baseurl=self.marionette.baseurl,
                           noWindow=self.marionette.noWindow)
         qemu.start_session()
         self.marionette.extra_emulators.append(qemu)
     else:
         qemu = self.marionette.extra_emulators[self.extra_emulator_index]
     return qemu
 def execute(self):
     self.marionette.cleanup()
     self.marionette = Marionette(device_serial=self.serial, port=self.port)
     self.marionette.wait_for_port()
     # run test runner here
     self.remove_settings_opt()
     self.kwargs = {}
     if self.port:
         self.kwargs['address'] = "localhost:" + str(self.port)
     logger.info("Using address[localhost:" + str(self.port) + "]")
     self.start_monitoring()
     self.mtbf_daily()
     self.run_mtbf()
     self.stop_monitoring()
示例#23
0
    def run_marionette_script(self):
        self.marionette = Marionette(**self.marionette_args)
        assert (self.marionette.wait_for_port())
        self.marionette.start_session()
        if self.build_type == "mulet":
            self._wait_for_homescreen(timeout=15)
            self._unlockScreen()
        self.marionette.set_context(self.marionette.CONTEXT_CHROME)

        if os.path.isfile(self.test_script):
            f = open(self.test_script, 'r')
            self.test_script = f.read()
            f.close()
        self.marionette.execute_script(self.test_script)
示例#24
0
    def create_marionette():
        """Returns current Marionette session, or creates one if
        one does not exist.

        """

        m = TestCase.stored.marionette
        if m is None:
            m = Marionette()
            m.wait_for_port()
            m.start_session()
            TestCase.stored.marionette = m

        return TestCase.stored.marionette
示例#25
0
    def restart_b2g(self):
        #restart b2g so we start with a clean slate
        self.dm.checkCmd(['shell', 'stop', 'b2g'])
        # Wait for a bit to make sure B2G has completely shut down.
        time.sleep(10)
        self.dm.checkCmd(['shell', 'start', 'b2g'])

        #wait for marionette port to come up
        if not self.wait_for_port(30000):
            raise Exception(
                "Could not communicate with Marionette port after restarting B2G"
            )
        self.marionette = Marionette(self.marionette_host,
                                     self.marionette_port)
示例#26
0
 def setupMarionette(self):
     """
     Start a marionette session.
     If no host is given, then this will get the ip
     of the device, and set up networking if needed.
     """
     if not self.marionetteHost:
         self.setupDHCP()
         self.marionetteHost = self.getIP()
     if not self.marionette:
         self.marionette = Marionette(self.marionetteHost,
                                      self.marionettePort)
     if not self.marionette.session:
         self.waitForPort(30)
         self.marionette.start_session()
示例#27
0
def run_desktop_mochitests(parser, options):
    automation = B2GDesktopAutomation()

    # create our Marionette instance
    kwargs = {}
    if options.marionette:
        host, port = options.marionette.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
    marionette = Marionette.getMarionetteOrExit(**kwargs)
    automation.marionette = marionette

    mochitest = B2GDesktopMochitest(automation)

    # b2g desktop builds don't always have a b2g-bin file
    if options.app[-4:] == '-bin':
        options.app = options.app[:-4]

    options = MochitestOptions.verifyOptions(parser, options, mochitest)
    if options == None:
        sys.exit(1)

    if options.desktop and not options.profile:
        raise Exception("must specify --profile when specifying --desktop")

    automation.setServerInfo(options.webServer,
                             options.httpPort,
                             options.sslPort,
                             options.webSocketPort)
    sys.exit(mochitest.runTests(options,
                                onLaunch=mochitest.startTests))
示例#28
0
 def restart_device(self, restart_tries=0):
     self.run_log.info("rebooting")
     # TODO restarting b2g doesn't seem to work... reboot then
     while restart_tries < 3:
         restart_tries += 1
         self.dm.reboot(wait=True)
         self.run_log.info("forwarding")
         if not self.forward_port():
             self.run_log.error("couldn't forward port in time, rebooting")
             continue
         self.m = Marionette(port=self.port)
         if not self.m.wait_for_port(180):
             self.run_log.error("couldn't contact marionette in time, rebooting")
             continue
         time.sleep(1)
         self.m.start_session()
         try:
             Wait(self.m, timeout=240).until(lambda m: m.find_element("id", "lockscreen-container").is_displayed())
             # It retuns a little early
             time.sleep(2)
             self.device = GaiaDevice(self.m)
             self.device.add_device_manager(self.dm)
             self.device.unlock()
             self.gaia_apps = GaiaApps(self.m)
         except (MarionetteException, IOError, socket.error) as e:
             self.run_log.error("got exception: %s, going to retry" % e)
             try:
                 self.m.delete_session()
             except:
                 # at least attempt to clear the session if possible
                 pass
             continue
         break
     else:
         raise Exception("Couldn't restart the device in time, even after 3 tries")
示例#29
0
def run_desktop_mochitests(parser, options):
    # create our Marionette instance
    kwargs = {}
    if options.marionette:
        host, port = options.marionette.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
    marionette = Marionette.getMarionetteOrExit(**kwargs)
    mochitest = B2GDesktopMochitest(marionette, options.profile_data_dir)

    # add a -bin suffix if b2g-bin exists, but just b2g was specified
    if options.app[-4:] != '-bin':
        if os.path.isfile("%s-bin" % options.app):
            options.app = "%s-bin" % options.app

    options = MochitestOptions.verifyOptions(parser, options, mochitest)
    if options == None:
        sys.exit(1)

    if options.desktop and not options.profile:
        raise Exception("must specify --profile when specifying --desktop")

    options.browserArgs += ['-marionette']

    sys.exit(mochitest.runTests(options, onLaunch=mochitest.startTests))
示例#30
0
def run_desktop_mochitests(parser, options):
    automation = B2GDesktopAutomation()

    # create our Marionette instance
    kwargs = {}
    if options.marionette:
        host, port = options.marionette.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
    marionette = Marionette.getMarionetteOrExit(**kwargs)
    automation.marionette = marionette

    mochitest = B2GDesktopMochitest(automation, options)

    # b2g desktop builds don't always have a b2g-bin file
    if options.app[-4:] == '-bin':
        options.app = options.app[:-4]

    options = MochitestOptions.verifyOptions(parser, options, mochitest)
    if options == None:
        sys.exit(1)

    if options.desktop and not options.profile:
        raise Exception("must specify --profile when specifying --desktop")

    automation.setServerInfo(options.webServer, options.httpPort,
                             options.sslPort, options.webSocketPort)
    sys.exit(mochitest.runTests(options, onLaunch=mochitest.startTests))
 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")
示例#32
0
文件: b2g.py 项目: KurSh/peach
    def _StartProcess(self):
        if not self.isEmulatorInitialized:
            print("Starting Emulator ...")
            self.emulatorProcess = subprocess.Popen(
                [self.emulatorStartScript], cwd=os.path.dirname(self.emulatorStartScript), shell=True)

            # adb shell setprop net.dns1 10.0.2.3

            self._isBootFinished()
            self.monitoringProcessId = self.adb.getPID(self.monitoredProcessName)

            print("Forwarding TCP port %d ..." % self.forwardedPortADB)
            self.adb.command(["forward", "tcp:%d" % self.forwardedPortADB, "tcp:%d" % self.forwardedPortADB])

            self.isEmulatorInitialized = True

        time.sleep(20)

        if self.crashSuccess:
            print("Restarting %s ..." % self.monitoredProcessName)
            self.adb.killProcess(self.monitoredProcessName, True)
            time.sleep(40)
            self.monitoringProcessId = self.adb.getPID(self.monitoredProcessName)
            self.crashSuccess = False
            self.debugLogData = str()
            self.adb.checkCmd(["logcat", "-c"])

        print("Starting Marionette session ...")
        marionette = Marionette('localhost', self.forwardedPortADB)
        print(marionette.status())
        marionette.start_session()
        marionette.set_script_timeout(self.scriptTimeout)
        marionette.switch_to_frame()

        lock = gaia.LockScreen(marionette)
        lock.unlock()

        apps = gaia.GaiaApps(marionette)
        print(apps.runningApps())

        print("Launching Browser application")
        apps.launch(self.appName, switch_to_frame=True)

        print("Navigating to %s ..." % self.publisherURL)
        marionette.execute_script("return window.wrappedJSObject.Browser.navigate('%s')" % self.publisherURL)

        self.isMonitorInitialized = True
示例#33
0
def main():
    parser = B2GOptions()
    options, args = parser.parse_args()
    options = parser.verifyRemoteOptions(options)

    # Create the Marionette instance
    kwargs = {}
    if options.emulator:
        kwargs['emulator'] = options.emulator
        if options.no_window:
            kwargs['noWindow'] = True
        if options.geckoPath:
            kwargs['gecko_path'] = options.geckoPath
        if options.logcat_dir:
            kwargs['logcat_dir'] = options.logcat_dir
        if options.busybox:
            kwargs['busybox'] = options.busybox
        if options.symbolsPath:
            kwargs['symbols_path'] = options.symbolsPath
    if options.b2g_path:
        kwargs['homedir'] = options.emu_path or options.b2g_path
    if options.address:
        host, port = options.address.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
        kwargs['baseurl'] = 'http://%s:%d/' % (host, int(port))
        if options.emulator:
            kwargs['connectToRunningEmulator'] = True
    marionette = Marionette(**kwargs)

    if options.emulator:
        dm = marionette.emulator.dm
    else:
        # Create the DeviceManager instance
        kwargs = {'adbPath': options.adb_path}
        if options.deviceIP:
            kwargs['host'] = options.deviceIP
            kwargs['port'] = options.devicePort
        kwargs['deviceRoot'] = options.remoteTestRoot
        dm = devicemanagerADB.DeviceManagerADB(**kwargs)

    if not options.remoteTestRoot:
        options.remoteTestRoot = dm.getDeviceRoot()
    xpcsh = B2GXPCShellRemote(dm, options, args)

    # we don't run concurrent tests on mobile
    options.sequential = True

    try:
        if not xpcsh.runTests(xpcshell='xpcshell',
                              testdirs=args[0:],
                              testClass=B2GXPCShellTestThread,
                              mobileArgs=xpcsh.mobileArgs,
                              **options.__dict__):
            sys.exit(1)
    except:
        print "Automation Error: Exception caught while running tests"
        traceback.print_exc()
        sys.exit(1)
示例#34
0
    def setupMarionette(self, scriptTimeout=60000):
        """
        Starts a marionette session.
        If no host was given at init, the ip of the device will be retrieved
        and networking will be established.
        """
        if not self.marionetteHost:
            self.setupDHCP()
            self.marionetteHost = self.getIP()
        if not self.marionette:
            self.marionette = Marionette(self.marionetteHost,
                                         self.marionettePort)
        if not self.marionette.session:
            self.waitForPort(30)
            self.marionette.start_session()

        self.marionette.set_script_timeout(scriptTimeout)
示例#35
0
def init():
    ret = subprocess.check_output("adb devices", shell=True)
    print(ret)
    ## TODO: find more error handling if available

    import socket
    s = socket.socket()
    try:
        s.bind(("localhost", 2828))
        s.close()
        ret = subprocess.check_output("adb forward tcp:2828 tcp:2828",
                                      shell=True)
    except socket.error:
        print("address already in use")
    mar = Marionette()
    mar.start_session()
    return mar
示例#36
0
def main():
    scriptdir = os.path.abspath(os.path.realpath(os.path.dirname(__file__)))
    auto = B2GRemoteAutomation(None, "fennec")
    parser = B2GOptions(auto, scriptdir)
    options, args = parser.parse_args()

    # create our Marionette instance
    kwargs = {'emulator': options.emulator}
    if options.b2gPath:
        kwargs['homedir'] = options.b2gPath
    if options.marionette:
        host,port = options.marionette.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
    marionette = Marionette(**kwargs)

    auto.marionette = marionette

    # create the DeviceManager
    kwargs = {'adbPath': options.adbPath}
    if options.deviceIP:
        kwargs.update({'host': options.deviceIP,
                       'port': options.devicePort})
    dm = devicemanagerADB.DeviceManagerADB(**kwargs)

    auto.setDeviceManager(dm)
    options = parser.verifyRemoteOptions(options, auto)
    if (options == None):
        print "ERROR: Invalid options specified, use --help for a list of valid options"
        sys.exit(1)

    auto.setProduct("b2g")

    mochitest = B2GMochitest(auto, dm, options)

    options = parser.verifyOptions(options, mochitest)
    if (options == None):
        sys.exit(1)

    logParent = os.path.dirname(options.remoteLogFile)
    dm.mkDir(logParent);
    auto.setRemoteLog(options.remoteLogFile)
    auto.setServerInfo(options.webServer, options.httpPort, options.sslPort)

    retVal = 1
    try:
        retVal = mochitest.runTests(options)
    except:
        print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running tests." % sys.exc_info()[1]
        mochitest.stopWebServer(options)
        mochitest.stopWebSocketServer(options)
        try:
            mochitest.cleanup(None, options)
        except:
            pass
            sys.exit(1)

    sys.exit(retVal)
示例#37
0
 def start_marionette(self):
     assert (self.baseurl is not None)
     if self.bin:
         if self.address:
             host, port = self.address.split(':')
         else:
             host = 'localhost'
             port = 2828
         self.marionette = Marionette(host=host,
                                      port=int(port),
                                      app=self.app,
                                      app_args=self.app_args,
                                      bin=self.bin,
                                      profile=self.profile,
                                      baseurl=self.baseurl,
                                      timeout=self.timeout,
                                      device_serial=self.device_serial)
     elif self.address:
         host, port = self.address.split(':')
         try:
             #establish a socket connection so we can vertify the data come back
             connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             connection.connect((host, int(port)))
             connection.close()
         except Exception, e:
             raise Exception(
                 "Could not connect to given marionette host:port: %s" % e)
         if self.emulator:
             self.marionette = Marionette.getMarionetteOrExit(
                 host=host,
                 port=int(port),
                 connectToRunningEmulator=True,
                 homedir=self.homedir,
                 baseurl=self.baseurl,
                 logcat_dir=self.logcat_dir,
                 gecko_path=self.gecko_path,
                 symbols_path=self.symbols_path,
                 timeout=self.timeout,
                 device_serial=self.device_serial)
         else:
             self.marionette = Marionette(host=host,
                                          port=int(port),
                                          baseurl=self.baseurl,
                                          timeout=self.timeout,
                                          device_serial=self.device_serial)
示例#38
0
def init():
    ret = subprocess.check_output("adb devices", shell=True)
    if("unagi" in ret):
        print(ret)
    else:
        print("No unagi connected")
        sys.exit(1)
    import socket
    s = socket.socket()
    try:
        s.bind(("localhost", 2828))
        s.close()
        ret = subprocess.check_output("adb forward tcp:2828 tcp:2828", shell=True)
    except socket.error:
        print("address already in use")
    mar = Marionette()
    mar.start_session()
    return mar
示例#39
0
文件: gcli.py 项目: bjacob/gaia
    def run(self, args=sys.argv[1:]):
        args = self.parser.parse_args()

        host, port = args.address.split(':')
        self.marionette = Marionette(host=host, port=int(port))
        self.marionette.start_session()

        self.apps = gaiatest.GaiaApps(self.marionette)
        self.data_layer = gaiatest.GaiaData(self.marionette)
        self.lock_screen = gaiatest.LockScreen(self.marionette)

        ret = args.func(args)
        if ret is None:
            ret = 0

        self.marionette.delete_session()

        sys.exit(ret)
    def setup(self):
        if not self.serial or not self.port:
            logger.error("Fail to get device")
            raise DMError
        self.config_raptor()

        self.marionette and self.marionette.session and self.marionette.cleanup(
        )
        self.dm = mozdevice.DeviceManagerADB(deviceSerial=self.serial,
                                             port=self.port)
        self.marionette = Marionette(device_serial=self.serial, port=self.port)
        self.marionette.wait_for_port()
        self.marionette.start_session()
        self.device = GaiaDevice(marionette=self.marionette, manager=self.dm)
        self.apps = GaiaApps(self.marionette)
        self.data_layer = GaiaData(self.marionette)
        if self.flashed:
            self.device.wait_for_b2g_ready()
示例#41
0
 def startTests(self):
     # This is run in a separate thread because otherwise, the app's
     # stdout buffer gets filled (which gets drained only after this
     # function returns, by waitForFinish), which causes the app to hang.
     self.marionette = Marionette(**self.marionette_args)
     thread = threading.Thread(target=self.runMarionetteScript,
                               args=(self.marionette, self.test_script,
                                     self.test_script_args))
     thread.start()
示例#42
0
def init():
    ret = subprocess.check_output("adb devices", shell=True)
#    if("unagi" in ret):
#        print(ret)
#    else:
#        print("No unagi connected")
#        sys.exit(1)
    import socket
    s = socket.socket()
    try:
        s.bind(("localhost", 2828))
        s.close()
        ret = subprocess.check_output("adb forward tcp:2828 tcp:2828", shell=True)
    except socket.error:
        print("address already in use")
    mar = Marionette()
    mar.start_session()
    return mar
示例#43
0
 def unplug_and_instruct(self, message):
     self.instruct(
         "Unplug the phone.\n%s\nPlug the phone back in after you are "
         "done, and unlock the screen if necessary.\n" % message)
     dm = mozdevice.DeviceManagerADB()
     dm.forward("tcp:2828", "tcp:2828")
     self.marionette = Marionette()
     self.marionette.start_session()
     self.use_cert_app()
示例#44
0
 def start_marionette(self):
     assert(self.baseurl is not None)
     if self.bin:
         if self.address:
             host, port = self.address.split(':')
         else:
             host = 'localhost'
             port = 2828
         self.marionette = Marionette(host=host,
                                      port=int(port),
                                      app=self.app,
                                      bin=self.bin,
                                      profile=self.profile,
                                      baseurl=self.baseurl)
     elif self.address:
         host, port = self.address.split(':')
         if self.emulator:
             self.marionette = Marionette.getMarionetteOrExit(
                                          host=host, port=int(port),
                                          connectToRunningEmulator=True,
                                          homedir=self.homedir,
                                          baseurl=self.baseurl,
                                          logcat_dir=self.logcat_dir,
                                          gecko_path=self.gecko_path,
                                          symbols_path=self.symbols_path)
         else:
             self.marionette = Marionette(host=host,
                                          port=int(port),
                                          baseurl=self.baseurl)
     elif self.emulator:
         self.marionette = Marionette.getMarionetteOrExit(
                                      emulator=self.emulator,
                                      emulatorBinary=self.emulatorBinary,
                                      emulatorImg=self.emulatorImg,
                                      emulator_res=self.emulator_res,
                                      homedir=self.homedir,
                                      baseurl=self.baseurl,
                                      noWindow=self.noWindow,
                                      logcat_dir=self.logcat_dir,
                                      gecko_path=self.gecko_path,
                                      symbols_path=self.symbols_path)
     else:
         raise Exception("must specify binary, address or emulator")
示例#45
0
def init():
    ret = subprocess.check_output("adb devices", shell=True)
    print(ret)
    ## TODO: find more error handling if available

    import socket
    s = socket.socket()
    try:
        s.bind(("localhost", 2828))
        s.close()
        ret = subprocess.check_output(
            "adb forward tcp:2828 tcp:2828",
            shell=True
            )
    except socket.error:
        print("address already in use")
    mar = Marionette()
    mar.start_session()
    return mar
示例#46
0
 def restart_b2g(self):
     #restart b2g so we start with a clean slate
     self.dm.checkCmd(['shell', 'stop', 'b2g'])
     # Wait for a bit to make sure B2G has completely shut down.
     time.sleep(10)
     self.dm.checkCmd(['shell', 'start', 'b2g'])
     
     #wait for marionette port to come up
     if not self.wait_for_port(30000):
         raise Exception("Could not communicate with Marionette port after restarting B2G")
     self.marionette = Marionette(self.marionette_host, self.marionette_port)
示例#47
0
    def run_marionette_script(self):
        self.marionette = Marionette(**self.marionette_args)
        assert(self.marionette.wait_for_port())
        self.marionette.start_session()
        self.marionette.set_context(self.marionette.CONTEXT_CHROME)

        if os.path.isfile(self.test_script):
            f = open(self.test_script, 'r')
            self.test_script = f.read()
            f.close()
        self.marionette.execute_script(self.test_script)
示例#48
0
 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
示例#49
0
 def execute(self):
     self.marionette.cleanup()
     self.marionette = Marionette(device_serial=self.serial, port=self.port)
     self.marionette.wait_for_port()
     # run test runner here
     self.remove_settings_opt()
     self.kwargs = {}
     if self.port:
         self.kwargs['address'] = "localhost:" + str(self.port)
     logger.info("Using address[localhost:" + str(self.port) + "]")
     self.mtbf_daily()
     self.run_mtbf()
示例#50
0
 def setup(self):
     if not self.serial or not self.port:
         logger.error("Fail to get device")
         raise DMError
     self.marionette and self.marionette.session and self.marionette.cleanup()
     self.dm = mozdevice.DeviceManagerADB(deviceSerial=self.serial, port=self.port)
     self.marionette = Marionette(device_serial=self.serial, port=self.port)
     self.marionette.start_session()
     self.device = GaiaDevice(marionette=self.marionette, manager=self.dm)
     self.apps = GaiaApps(self.marionette)
     self.data_layer = GaiaData(self.marionette)
     self.device.wait_for_b2g_ready()
示例#51
0
文件: b2g.py 项目: KurSh/peach
    def _StartProcess(self):
        if not self.isDeviceInitialized:
            print("Starting ...")
            self.monitoringProcessId = self.adb.getPID(self.monitoredProcessName)
            print("Forwarding TCP port %d ..." % self.forwardedPortADB)
            self.adb.command(["forward", "tcp:%d" % self.forwardedPortADB, "tcp:%d" % self.forwardedPortADB])
            self.isDeviceInitialized = True

        print("Sleeping ...")
        time.sleep(20)

        if self.crashSuccess:
            print("Restarting %s" % self.monitoredProcessName)
            self.adb.killProcess(self.monitoredProcessName, True)
            time.sleep(40)
            self.monitoringProcessId = self.adb.getPID(self.monitoredProcessName)
            self.crashSuccess = False
            self.debugLogData = str()
            self.adb.checkCmd(["logcat", "-c"])

        print("Starting Marionette session")
        marionette = Marionette('localhost', self.forwardedPortADB)
        print(marionette.status())
        marionette.start_session()
        marionette.set_script_timeout(self.scriptTimeout)
        marionette.switch_to_frame()

        lock = gaia.LockScreen(marionette)
        assert(lock.unlock())

        apps = gaia.GaiaApps(marionette)
        print(apps.runningApps())

        print("Launching Browser application")
        apps.launch(self.appName, switch_to_frame=True)

        print("Navigating to %s ..." % self.publisherURL)
        marionette.execute_script("return window.wrappedJSObject.Browser.navigate('%s')" % self.publisherURL)

        self.isMonitorInitialized = True
示例#52
0
    def start(self):
        '''
        This method starts MATS.
        '''
        
        print 'Using ' + MatsController.__name__ + ' as controller.'
        print 'Loading config from "' + self.config_file + '"...',
        self.config = get_config(self.config_file)   #get_config makes sure that the config makes sense. More details in get_config.py
        self.marionette_port = self.config['Marionette']['port'] 
        print 'OK'
        
        print 'Starting Firefox/Nightly from "' + self.config['Firefox']['binary'] + '" with Marionette on port ' + str(self.marionette_port) + '.'        
        self.FirefoxThread = FirefoxThread(self.config['Firefox']['binary'], self.marionette_port)
        self.FirefoxThread.start()
        
        print 'Creating controller'
        pid = self.FirefoxThread.getPID() # this function blocks until PID is available from FirefoxThread
        self.controller = MatsController(pid)
        
        print 'Starting controller'
        self.controller.start()
        self.controller.wait_for_ready()
        
        print 'Waiting for Marionette port to open (' + str(self.marionette_port) + ')'
        portReady = self.FirefoxThread.waitForMarionettePortOpenReady(self.config['Marionette']['port_timeout'])
        if portReady:
            print 'Marionette port open'
        else:
            print 'Error: timeout, shutting down MATS'
            self.controller.stop()
            self.FirefoxThread.stop()
            return
        
        #TODO: remove line below once https://bugzilla.mozilla.org/show_bug.cgi?id=753273 is fixed
        #sleep(10)
        
        try:
            print 'Starting Marionette'
            self.marionette = Marionette('localhost', self.marionette_port)
            #TODO: move starting session and navigation to separate methods
            print 'Starting session'
            sleep(5) #TODO temporary workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=757078
            self.marionette_session = self.marionette.start_session()
            print 'Navigating to ' + self.url
            print self.marionette.navigate(self.url)
        except Exception as e:
            print 'Error starting Marionette'
            fall(e)
            self.controller.stop()
            self.FirefoxThread.stop()

        print 'MATS up and running. Waiting until Firefox/Nightly stops.'
示例#53
0
def main():
    parser = B2GOptions()
    options, args = parser.parse_args()

    if options.objdir is None:
        try:
            options.objdir = os.path.join(options.b2g_path, 'objdir-gecko')
        except:
            print >> sys.stderr, "Need to specify a --b2gpath"
            sys.exit(1)

    # Create the Marionette instance
    kwargs = {}
    if options.emulator:
        kwargs['emulator'] = options.emulator
        if options.no_window:
            kwargs['noWindow'] = True
    if options.b2g_path:
        kwargs['homedir'] = options.emu_path or options.b2g_path
    if options.address:
        host, port = options.address.split(':')
        kwargs['host'] = host
        kwargs['port'] = int(port)
        kwargs['baseurl'] = 'http://%s:%d/' % (host, int(port))
        if options.emulator:
            kwargs['connectToRunningEmulator'] = True
    marionette = Marionette(**kwargs)

    # Create the DeviceManager instance
    kwargs = {'adbPath': options.adb_path}
    if options.deviceIP:
        kwargs['host'] = options.deviceIP
        kwargs['port'] = options.devicePort
    kwargs['deviceRoot'] = DEVICE_TEST_ROOT
    dm = devicemanagerADB.DeviceManagerADB(**kwargs)

    options.remoteTestRoot = dm.getDeviceRoot()

    xpcsh = B2GXPCShellRemote(dm, options, args)

    try:
        success = xpcsh.runTests(xpcshell='xpcshell',
                                 testdirs=args[0:],
                                 **options.__dict__)
    except:
        print "TEST-UNEXPECTED-FAIL | %s | Exception caught while running tests." % sys.exc_info(
        )[1]
        traceback.print_exc()
        sys.exit(1)

    sys.exit(int(success))
 def restart_device(self, restart_tries=0):
     self.run_log.info("rebooting")
     # TODO restarting b2g doesn't seem to work... reboot then
     while restart_tries < 3:
         restart_tries += 1
         self.dm.reboot(wait=True)
         self.run_log.info("forwarding")
         if not self.forward_port():
             self.run_log.error("couldn't forward port in time, rebooting")
             continue
         self.m = Marionette(port=self.port)
         if not self.m.wait_for_port(180):
             self.run_log.error(
                 "couldn't contact marionette in time, rebooting")
             continue
         time.sleep(1)
         self.m.start_session()
         try:
             Wait(self.m, timeout=240).until(lambda m: m.find_element(
                 "id", "lockscreen-container").is_displayed())
             # It retuns a little early
             time.sleep(2)
             self.device = GaiaDevice(self.m)
             self.device.add_device_manager(self.dm)
             self.device.unlock()
             self.gaia_apps = GaiaApps(self.m)
         except (MarionetteException, IOError, socket.error) as e:
             self.run_log.error("got exception: %s, going to retry" % e)
             try:
                 self.m.delete_session()
             except:
                 # at least attempt to clear the session if possible
                 pass
             continue
         break
     else:
         raise Exception(
             "Couldn't restart the device in time, even after 3 tries")
示例#55
0
文件: b2gmixin.py 项目: dmose/mozbase
 def setupMarionette(self):
     """
     Starts a marionette session.
     If no host was given at init, the ip of the device will be retrieved
     and networking will be established.
     """
     if not self.marionetteHost:
         self.setupDHCP()
         self.marionetteHost = self.getIP()
     if not self.marionette:
         self.marionette = Marionette(self.marionetteHost, self.marionettePort)
     if not self.marionette.session:
         self.waitForPort(30)
         self.marionette.start_session()
示例#56
0
 def setupMarionette(self):
     """
     Start a marionette session.
     If no host is given, then this will get the ip
     of the device, and set up networking if needed.
     """
     if not self.marionetteHost:
         self.setupDHCP()
         self.marionetteHost = self.getIP()
     if not self.marionette:
         self.marionette = Marionette(self.marionetteHost, self.marionettePort)
     if not self.marionette.session:
         self.waitForPort(30)
         self.marionette.start_session()
示例#57
0
def runemulator(homedir=None, url=None, pidfile=None, arch='x86'):
    qemu = Emulator(homedir=homedir, arch=arch)
    qemu.start()
    port = qemu.setup_port_forwarding(2828)
    assert (qemu.wait_for_port())
    if pidfile:
        f = open(pidfile, 'w')
        f.write("%d" % qemu.proc.pid)
        f.close()
    print 'emulator launched, pid:', qemu.proc.pid

    if url:
        marionette = Marionette(port=port)
        marionette.start_session()
        marionette.navigate(url)
        marionette.delete_session()
示例#58
0
    def run_marionette_script(self):
        self.marionette = Marionette(**self.marionette_args)
        assert(self.marionette.wait_for_port())
        self.marionette.start_session()
        if self.build_type == "mulet":
            self._wait_for_homescreen(timeout=15)
            self._unlockScreen()
        self.marionette.set_context(self.marionette.CONTEXT_CHROME)

        if os.path.isfile(self.test_script):
            f = open(self.test_script, 'r')
            self.test_script = f.read()
            f.close()
        self.marionette.execute_script(self.test_script)