Best Python code snippet using fMBT_python
fmbtgti.py
Source:fmbtgti.py  
...2069                .funccalls { display: none }2070            </style>2071            </head><body>2072            ''')2073    def doCallLogException(self, origMethod, args, kwargs):2074        try: return origMethod(*args, **kwargs)2075        except:2076            self.logException()2077            raise2078    def genericLogger(loggerSelf, origMethod):2079        def origMethodWRAP(*args, **kwargs):2080            loggerSelf.logCall()2081            retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2082            loggerSelf.logReturn(retval, tip=origMethod.func_name)2083            return retval2084        loggerSelf.changeCodeName(origMethodWRAP, origMethod.func_code.co_name + "WRAP")2085        return origMethodWRAP2086    def messageLogger(loggerSelf, origMethod):2087        def origMethodWRAP(*args, **kwargs):2088            loggerSelf.logMessage(" ".join([str(a) for a in args]))2089            return True2090        loggerSelf.changeCodeName(origMethodWRAP, origMethod.func_code.co_name + "WRAP")2091        return origMethodWRAP2092    def dragLogger(loggerSelf, origMethod):2093        def dragWRAP(*args, **kwargs):2094            loggerSelf.logCall()2095            x1, y1 = args[0]2096            x2, y2 = args[1]2097            retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2098            try:2099                screenshotFilename = loggerSelf._device.screenshot().filename()2100                highlightFilename = loggerSelf.highlightFilename(screenshotFilename)2101                iC = loggerSelf._device.intCoords2102                eyenfinger.drawLines(screenshotFilename, highlightFilename, [], [iC((x1, y1)), iC((x2, y2))])2103                loggerSelf.logReturn(retval, img=highlightFilename, width=loggerSelf._screenshotWidth, tip=origMethod.func_name)2104            except:2105                loggerSelf.logReturn(str(retval) + " (no screenshot available)", tip=origMethod.func_name)2106            return retval2107        return dragWRAP2108    def refreshScreenshotLogger(loggerSelf, origMethod):2109        def refreshScreenshotWRAP(*args, **kwargs):2110            loggerSelf._highlightCounter = 02111            logCallReturnValue = loggerSelf.logCall()2112            retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2113            retval._logCallReturnValue = logCallReturnValue2114            loggerSelf.logReturn(retval, img=retval, tip=origMethod.func_name)2115            retval.findItemsByBitmap = loggerSelf.findItemsByBitmapLogger(retval.findItemsByBitmap, retval)2116            retval.findItemsByOcr = loggerSelf.findItemsByOcrLogger(retval.findItemsByOcr, retval)2117            return retval2118        return refreshScreenshotWRAP2119    def tapLogger(loggerSelf, origMethod):2120        def tapWRAP(*args, **kwargs):2121            loggerSelf.logCall()2122            retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2123            try:2124                screenshotFilename = loggerSelf._device.screenshot().filename()2125                highlightFilename = loggerSelf.highlightFilename(screenshotFilename)2126                eyenfinger.drawClickedPoint(screenshotFilename, highlightFilename, loggerSelf._device.intCoords(args[0]))2127                loggerSelf.logReturn(retval, img=highlightFilename, width=loggerSelf._screenshotWidth, tip=origMethod.func_name, imgTip=loggerSelf._device.screenshot()._logCallReturnValue)2128            except:2129                loggerSelf.logReturn(str(retval) + " (no screenshot available)", tip=origMethod.func_name)2130            return retval2131        return tapWRAP2132    def findItemsByBitmapLogger(loggerSelf, origMethod, screenshotObj):2133        def findItemsByBitmapWRAP(*args, **kwargs):2134            bitmap = args[0]2135            absPathBitmap = screenshotObj._paths.abspath(bitmap)2136            if loggerSelf._copyBitmapsToScreenshotDir:2137                screenshotDirBitmap = os.path.join(2138                    os.path.dirname(screenshotObj.filename()),2139                    "bitmaps",2140                    bitmap.lstrip(os.sep))2141                if not os.access(screenshotDirBitmap, os.R_OK):2142                    # bitmap is not yet copied under screenshotDir2143                    destDir = os.path.dirname(screenshotDirBitmap)2144                    if not os.access(destDir, os.W_OK):2145                        try:2146                            os.makedirs(destDir)2147                        except IOError:2148                            pass # cannot make dir / dir not writable2149                    try:2150                        shutil.copy(absPathBitmap, destDir)2151                        absPathBitmap = screenshotDirBitmap2152                    except IOError:2153                        pass # cannot copy bitmap2154                else:2155                    absPathBitmap = screenshotDirBitmap2156            loggerSelf.logCall(img=absPathBitmap)2157            retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2158            if len(retval) == 0:2159                loggerSelf.logReturn("not found in", img=screenshotObj, tip=origMethod.func_name)2160            else:2161                foundItems = retval2162                screenshotFilename = screenshotObj.filename()2163                highlightFilename = loggerSelf.highlightFilename(screenshotFilename)2164                eyenfinger.drawIcon(screenshotFilename, highlightFilename, bitmap, [i.bbox() for i in foundItems])2165                loggerSelf.logReturn([str(quiItem) for quiItem in retval], img=highlightFilename, width=loggerSelf._screenshotWidth, tip=origMethod.func_name, imgTip=screenshotObj._logCallReturnValue)2166            return retval2167        return findItemsByBitmapWRAP2168    def findItemsByOcrLogger(loggerSelf, origMethod, screenshotObj):2169        def findItemsByOcrWRAP(*args, **kwargs):2170            loggerSelf.logCall()2171            retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2172            if len(retval) == 0:2173                loggerSelf.logReturn("not found in words " + str(screenshotObj.dumpOcrWords()),2174                                     img=screenshotObj, tip=origMethod.func_name)2175            else:2176                foundItem = retval[0]2177                screenshotFilename = screenshotObj.filename()2178                highlightFilename = loggerSelf.highlightFilename(screenshotFilename)2179                eyenfinger.drawIcon(screenshotFilename, highlightFilename, args[0], foundItem.bbox())2180                for appearance, foundItem in enumerate(retval[1:42]):2181                    eyenfinger.drawIcon(highlightFilename, highlightFilename, str(appearance+1) + ": " + args[0], foundItem.bbox())2182                loggerSelf.logReturn([str(retval[0])], img=highlightFilename, width=loggerSelf._screenshotWidth, tip=origMethod.func_name, imgTip=screenshotObj._logCallReturnValue)2183            return retval2184        return findItemsByOcrWRAP2185    def relFilePath(self, fileOrDirName, fileLikeObj):...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!!
