Best Python code snippet using fMBT_python
fmbtgti.py
Source:fmbtgti.py
...824 GUIItem("bitmap", bbox, ssFilename, bitmap=bitmap))825 matchCount += 1826 eye4graphics.closeImage(e4gIcon)827 return self._findBitmapCache[ssFilename][cacheKey]828def _defaultOirEngine():829 if _g_defaultOirEngine:830 return _g_defaultOirEngine831 else:832 _Eye4GraphicsOirEngine().register(defaultOir=True)833 return _g_defaultOirEngine834class _OirRc(object):835 """Optical image recognition settings for a directory.836 Currently loaded from file .fmbtoirc in the directory.837 There is once _OirRc instance per directory.838 """839 _filename = ".fmbtoirrc"840 _cache = {}841 @classmethod842 def load(cls, directory):843 if directory in cls._cache:844 pass845 elif os.access(os.path.join(directory, cls._filename), os.R_OK):846 cls._cache[directory] = cls(directory)847 else:848 cls._cache[directory] = None849 return cls._cache[directory]850 def __init__(self, directory):851 self._key2value = {}852 curdir = "."853 self._dir2oirArgsList = {curdir: [{}]}854 for line in file(os.path.join(directory, _OirRc._filename)):855 line = line.strip()856 if line == "" or line[0] in "#;":857 continue858 elif line == "alternative":859 self._dir2oirArgsList[curdir].append({}) # new set of args860 self._key2value = {}861 elif "=" in line:862 key, value_str = line.split("=", 1)863 value_str = value_str.strip()864 if key.strip().lower() == "includedir":865 curdir = value_str866 self._dir2oirArgsList[curdir] = [{}]867 else:868 try: value = int(value_str)869 except ValueError:870 try: value = float(value_str)871 except ValueError:872 if value_str[0] in "([\"'": # tuple, list, string873 value = eval(value_str)874 else:875 value = value_str876 self._dir2oirArgsList[curdir][-1][key.strip()] = value877 def searchDirs(self):878 return self._dir2oirArgsList.keys()879 def oirArgsList(self, searchDir):880 return self._dir2oirArgsList[searchDir]881class _Paths(object):882 def __init__(self, bitmapPath, relativeRoot):883 self.bitmapPath = bitmapPath884 self.relativeRoot = relativeRoot885 self._oirAL = {} # OIR parameters for bitmaps886 self._abspath = {} # bitmap to abspath887 def abspath(self, bitmap, checkReadable=True):888 if bitmap in self._abspath:889 return self._abspath[bitmap]890 if bitmap.startswith("/"):891 path = [os.path.dirname(bitmap)]892 bitmap = os.path.basename(bitmap)893 else:894 path = []895 for singleDir in self.bitmapPath.split(":"):896 if not singleDir.startswith("/"):897 path.append(os.path.join(self.relativeRoot, singleDir))898 else:899 path.append(singleDir)900 for singleDir in path:901 retval = os.path.join(singleDir, bitmap)902 if not checkReadable or os.access(retval, os.R_OK):903 oirRc = _OirRc.load(singleDir)904 if oirRc:905 self._oirAL[retval] = oirRc.oirArgsList(".")906 else:907 self._oirAL[retval] = [{}]908 self._oirAL[bitmap] = self._oirAL[retval]909 break910 else:911 # bitmap is not in singleDir, but there might be .fmbtoirrc912 oirRc = _OirRc.load(singleDir)913 if oirRc:914 for d in oirRc.searchDirs():915 if d.startswith("/"):916 candidate = os.path.join(d, bitmap)917 else:918 candidate = os.path.join(singleDir, d, bitmap)919 if os.access(candidate, os.R_OK):920 self._oirAL[candidate] = oirRc.oirArgsList(d)921 self._oirAL[bitmap] = self._oirAL[candidate]922 retval = candidate923 break924 if checkReadable and not os.access(retval, os.R_OK):925 raise ValueError('Bitmap "%s" not readable in bitmapPath %s' % (bitmap, ':'.join(path)))926 self._abspath[bitmap] = retval927 return retval928 def oirArgsList(self, bitmap):929 """Returns list of alternative OIR parameters associated to the bitmap930 by appropriate .fmbtoirrc file931 """932 if bitmap in self._oirAL:933 return self._oirAL[bitmap]934 else:935 absBitmap = self.abspath(bitmap)936 if absBitmap in self._oirAL:937 return self._oirAL[absBitmap]938 else:939 return None940class GUITestInterface(object):941 def __init__(self, ocrEngine=None, oirEngine=None, rotateScreenshot=None):942 self._paths = _Paths("", "")943 self._conn = None944 self._lastScreenshot = None945 self._longPressHoldTime = 2.0946 self._longTapHoldTime = 2.0947 self._ocrEngine = None948 self._oirEngine = None949 self._rotateScreenshot = rotateScreenshot950 self._screenshotLimit = None951 self._screenshotRefCount = {} # filename -> Screenshot object ref count952 self._screenshotArchiveMethod = "resize"953 if ocrEngine == None:954 self.setOcrEngine(_defaultOcrEngine())955 else:956 if type(ocrEngine) == int:957 self.setOcrEngine(_g_ocrEngines[ocrEngine])958 else:959 self.setOcrEngine(ocrEngine)960 if oirEngine == None:961 self.setOirEngine(_defaultOirEngine())962 else:963 if type(oirEngine) == int:964 self.setOirEngine(_g_oirEngines[oirEngine])965 else:966 self.setOirEngine(oirEngine)967 self._screenshotDir = None968 self._screenshotDirDefault = "screenshots"969 self._screenshotSubdir = None970 self._screenshotSubdirDefault = ""971 self._screenSize = None972 self._visualLog = None973 self._visualLogFileObj = None974 self._visualLogFilenames = set()975 def bitmapPath(self):...
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!!