Best Python code snippet using fMBT_python
fmbtwindows.py
Source:fmbtwindows.py  
...1001                if specified, no widgets will be dumped / reported, regarding1002                of all other dump options.1003                It's used to only cache the widgets in the server. All widgets1004                will be traversed and cached (if a cache option is defined).1005        See also setRefreshViewDefaults().1006        Returns View object.1007        """1008        if window == None:1009            window = self._refreshViewDefaults.get("window", None)1010        if forcedView == None:1011            forcedView = self._refreshViewDefaults.get("forcedView", None)1012        if viewSource == None:1013            viewSource = self.viewSource()1014        if not viewSource in _g_viewSources:1015            raise ValueError('invalid view source "%s"' % (viewSource,))1016        if items == None:1017            items = self._refreshViewDefaults.get("items", [])1018        if properties == None:1019            properties = self._refreshViewDefaults.get("properties", None)1020        if area == None:1021            area = self._refreshViewDefaults.get("area", None)1022        if forcedView != None:1023            retryCount = 01024            startTime = time.time()1025            lastStartTime = startTime1026            viewFilename = forcedView1027            if isinstance(forcedView, View):1028                self._lastView = forcedView1029            elif type(forcedView) in [str, unicode]:1030                try:1031                    self._lastView = View(1032                        forcedView, ast.literal_eval(file(viewFilename).read()),1033                        device=self, freeDumps=dumpChildClass or dumpChildName or doNotDump)1034                except Exception:1035                    self._lastView = None1036            endTime = time.time()1037        else:1038            viewFilename = self.getDumpFilename("view")1039            retryCount = 01040            startTime = time.time()1041            lastStartTime = startTime1042            while True:1043                try:1044                    topWindowBbox = self.topWindowProperties()['bbox']1045                except TypeError:1046                    topWindowBbox = None # top window unavailable1047                if area:1048                    leftTopRightBottom = (1049                        self.intCoords((area[0], area[1])) +1050                        self.intCoords((area[2], area[3])))1051                else:1052                    leftTopRightBottom = None1053                if viewSource == "enumchildwindows":1054                    viewData = self._conn.recvViewData(window)1055                else:1056                    if "/" in viewSource:1057                        walker = viewSource.split("/")[1]1058                    else:1059                        walker = "raw"1060                    if properties != None:1061                        if properties == "all":1062                            viewItemProperties = None1063                        elif properties == "fast":1064                            viewItemProperties = ["AutomationId",1065                                                   "BoundingRectangle",1066                                                   "ClassName",1067                                                   "HelpText",1068                                                   "ToggleState",1069                                                   "Value",1070                                                   "Minimum",1071                                                   "Maximum",1072                                                   "Name"]1073                        elif isinstance(properties, list) or isinstance(properties, tuple):1074                            viewItemProperties = list(properties)1075                        else:1076                            raise ValueError('invalid properties argument, expected "all", '1077                                             '"fast" or a list')1078                    else:1079                        viewItemProperties = properties1080                    viewData = self._conn.recvViewUIAutomation(1081                        window, items, viewItemProperties, leftTopRightBottom, walker,1082                        filterType, filterCondition, dumpChildClass, dumpChildName, doNotDump)1083                file(viewFilename, "w").write(repr(viewData))1084                try:1085                    self._lastView = View(1086                        viewFilename, viewData,1087                        itemOnScreen=lambda i: self.itemOnScreen(i, topWindowBbox=topWindowBbox),1088                        device=self, freeDumps=dumpChildClass or dumpChildName or doNotDump)1089                    break1090                except Exception, e:1091                    self._lastView = None1092                    _adapterLog(1093                        "refreshView %s failed (%s), source=%s topWindow=%s" %1094                        (retryCount, e, repr(viewSource), self.topWindow()))1095                    retryCount += 11096                    if retryCount < self._refreshViewRetryLimit:1097                        time.sleep(0.2)1098                    else:1099                        break1100                lastStartTime = time.time()1101            endTime = time.time()1102        itemCount = -11103        if self._lastView:1104            itemCount = len(self._lastView._viewItems)1105        self._lastViewStats = {1106            "retries": retryCount,1107            "timestamp": endTime,1108            "total time": endTime - startTime,1109            "last time": endTime - lastStartTime,1110            "filename": viewFilename,1111            "source": viewSource,1112            "forced": (forcedView != None),1113            "window": window,1114            "view": str(self._lastView),1115            "item count": itemCount}1116        return self._lastView1117    def refreshViewDefaults(self):1118        """Returns default arguments for refreshView() calls.1119        See also setRefreshViewDefaults().1120        """1121        return dict(self._refreshViewDefaults)1122    def setClipboard(self, data):1123        """1124        Set text on clipboard1125        Parameters:1126          data (string):1127                  data to be set on the clipboard.1128        Note: any type of data on clipboard will be emptied.1129        See also: getClipboard()1130        """1131        return self.existingConnection().evalPython(1132            "setClipboardText(%s)" % (repr(data),))1133    def setErrorReporting(self, settings):1134        """1135        Modify Windows error reporting settings (WER)1136        Parameters:1137          settings (dictionary):1138                  WER settings and values to be set.1139        Example: disable showing interactive crash dialogs1140          setErrorReporting({"DontShowUI": 1})1141        See also: errorReporting(),1142                  MSDN WER Settings.1143        """1144        for setting in settings:1145            self.setRegistry(1146                r"HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting",1147                setting, settings[setting])1148        return True1149    def setDisplaySize(self, size):1150        """1151        Transform coordinates of synthesized events (like a tap) from1152        screenshot resolution to display input area size. By default1153        events are synthesized directly to screenshot coordinates.1154        Parameters:1155          size (pair of integers: (width, height)):1156                  width and height of display in pixels. If not given,1157                  values from EnumDisplayMonitors are used.1158        Returns None.1159        """1160        width, height = size1161        screenWidth, screenHeight = self.screenSize()1162        self._conn.setScreenToDisplayCoords(1163            lambda x, y: (x * width / screenWidth,1164                          y * height / screenHeight))1165        self._conn.setDisplayToScreenCoords(1166            lambda x, y: (x * screenWidth / width,1167                          y * screenHeight / height))1168    def setForegroundWindow(self, window):1169        """1170        Set a window with the title as a foreground window1171        Parameters:1172          window (title (string) or hwnd (integer):1173                  title or handle of the window to be raised1174                  foreground.1175        Returns True if the window was brought to the foreground,1176        otherwise False.1177        Notes: calls SetForegroundWindow in user32.dll.1178        """1179        return self.existingConnection().sendSetForegroundWindow(window)1180    def setRefreshViewDefaults(self, **kwargs):1181        """Set new default arguments for refreshView() calls1182        Parameters:1183          **kwargs (keyword arguments)1184                  new default values for optional refreshView() parameters.1185        Note: default arguments are overridden by arguments given1186        directly in refreshView calls.1187        Note: setViewSource() can change the default arguments.1188        Example:1189          setRefreshViewDefaults(window="My app title",1190                                 viewSource="uiautomation/content")1191        """1192        self._refreshViewDefaults = kwargs1193    def findRegistry(self, rootKey, key=None, valueName=None, limit=1):1194        """Search for key and/or valueName from the registry.1195        Returns a list of matching (fullKeyPath, valueName) pairs1196        found under the rootKey. The list has at most limit items, the1197        default is 1.1198        Parameters:1199          rootKey (string):1200                  root key path for the search. Example:1201                  "HKEY_LOCAL_MACHINE".1202          key (string, optional):1203                  key name to be searched for under the rootKey....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!!
