Best Python code snippet using fMBT_python
fmbtchromiumos.py
Source:fmbtchromiumos.py  
...97        fmbtgti.GUITestConnection.__init__(self)98        self._loginCommand = loginCommand99        self._loginTuple = tuple(shlex.split(self._loginCommand))100        self.open()101    def sendFilesInTar(self, localDir, files, destDir):102        package = StringIO.StringIO()103        t = tarfile.TarFile(mode="w", fileobj=package)104        for filename in files:105            t.add(os.path.join(localDir, filename), arcname=filename)106        t.close()107        package.seek(0)108        _run(self._loginTuple +109             ("mkdir -p %s; tar x -C %s" % (destDir, destDir),),110             package.read())111    def agentExec(self, pythonCode):112        self._agent.exec_in(self._agent_ns, pythonCode)113    def agentEval(self, pythonExpression):114        return self._agent.eval_in(self._agent_ns, pythonExpression)115    def open(self):116        myDir = os.path.dirname(os.path.abspath(117            inspect.getfile(inspect.currentframe())))118        self.sendFilesInTar(myDir,119                            ("fmbtx11_conn.py",120                             "fmbtpng.py",121                             "fmbtuinput.py"),122                            "/tmp/fmbtchromiumos")123        if os.access(os.path.join(myDir, "pythonshare", "__init__.py"), os.R_OK):124            pythonshareDir = myDir125        elif os.access(os.path.join(myDir, "..", "pythonshare", "pythonshare",126                                    "__init__.py"), os.R_OK):127            pythonshareDir = os.path.join(myDir, "..", "pythonshare")128        self.sendFilesInTar(pythonshareDir,129                            ("pythonshare/__init__.py",130                             "pythonshare/server.py",131                             "pythonshare/client.py",132                             "pythonshare/messages.py"),133                            "/tmp/fmbtchromiumos")134        if os.name != "nt":135            pythonshareServer = distutils.spawn.find_executable("pythonshare-server")136        else:137            pythonshareServer = os.path.join(138                os.path.dirname(__file__), "..", "Scripts", "pythonshare-server")139        if not pythonshareServer or not os.access(pythonshareServer, os.R_OK):140            raise FMBTChromiumOsError("cannot find pythonshare-server executable")141        self.sendFilesInTar(os.path.dirname(pythonshareServer),142                            ("pythonshare-server",),143                            "/tmp/fmbtchromiumos")144        agentCmd = (self._loginCommand +145                    " sudo DISPLAY=:0 XAUTHORITY=/home/chronos/.Xauthority" +146                    " LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:/usr/lib:/usr/lib64" +147                    " python /tmp/fmbtchromiumos/pythonshare-server -p stdin")148        self._agent = pythonshare.connection("shell://" + agentCmd)149        self._agent_ns = "fmbtchromiumos-agent"150        try:151            self.agentExec("import fmbtx11_conn")152        except pythonshare.PythonShareError, e:153            raise FMBTChromiumOsError(154                "Cannot connect to pythonshare-server on device (%s): %s" %155                (e, agentCmd))...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
