Best Python code snippet using pyatom_python
AXClasses.py
Source:AXClasses.py  
...29    3. __getattribute__ call for invoking actions.30    4. waitFor utility based upon AX notifications.31    """32    @classmethod33    def _getRunningApps(cls):34        """Get a list of the running applications."""35        def runLoopAndExit():36            AppHelper.stopEventLoop()37        AppHelper.callLater(1, runLoopAndExit)38        AppHelper.runConsoleEventLoop()39        # Get a list of running applications40        ws = AppKit.NSWorkspace.sharedWorkspace()41        apps = ws.runningApplications()42        return apps43    @classmethod44    def getAppRefByPid(cls, pid):45        """Get the top level element for the application specified by pid."""46        return _a11y.getAppRefByPid(cls, pid)47    @classmethod48    def getAppRefByBundleId(cls, bundleId):49        """50        Get the top level element for the application with the specified51        bundle ID, such as com.vmware.fusion.52        """53        ra = AppKit.NSRunningApplication54        # return value (apps) is always an array. if there is a match it will55        # have an item, otherwise it won't.56        apps = ra.runningApplicationsWithBundleIdentifier_(bundleId)57        if len(apps) == 0:58            raise ValueError(('Specified bundle ID not found in '59                              'running apps: %s' % bundleId))60        pid = apps[0].processIdentifier()61        return cls.getAppRefByPid(pid)62    @classmethod63    def getAppRefByLocalizedName(cls, name):64        """Get the top level element for the application with the specified65        localized name, such as VMware Fusion.66        Wildcards are also allowed.67        """68        # Refresh the runningApplications list69        apps = cls._getRunningApps()70        for app in apps:71            if fnmatch.fnmatch(app.localizedName(), name):72                pid = app.processIdentifier()73                return cls.getAppRefByPid(pid)74        raise ValueError('Specified application not found in running apps.')75    @classmethod76    def getFrontmostApp(cls):77        """Get the current frontmost application.78        Raise a ValueError exception if no GUI applications are found.79        """80        # Refresh the runningApplications list81        apps = cls._getRunningApps()82        for app in apps:83            pid = app.processIdentifier()84            ref = cls.getAppRefByPid(pid)85            try:86                if ref.AXFrontmost:87                    return ref88            except (_a11y.ErrorUnsupported,89                    _a11y.ErrorCannotComplete,90                    _a11y.ErrorAPIDisabled,91                    _a11y.ErrorNotImplemented):92                # Some applications do not have an explicit GUI93                # and so will not have an AXFrontmost attribute94                # Trying to read attributes from Google Chrome Helper returns95                # ErrorAPIDisabled for some reason - opened radar bug 1283799596                pass97        raise ValueError('No GUI application found.')98    @classmethod99    def getAnyAppWithWindow(cls):100        """Get a random app that has windows.101        Raise a ValueError exception if no GUI applications are found.102        """103        # Refresh the runningApplications list104        apps = cls._getRunningApps()105        for app in apps:106            pid = app.processIdentifier()107            ref = cls.getAppRefByPid(pid)108            if hasattr(ref, 'windows') and len(ref.windows()) > 0:109                return ref110        raise ValueError('No GUI application found.')111    @classmethod112    def getSystemObject(cls):113        """Get the top level system accessibility object."""114        return _a11y.getSystemObject(cls)115    @classmethod116    def setSystemWideTimeout(cls, timeout=0.0):117        """Set the system-wide accessibility timeout.118        Optional: timeout (non-negative float; defaults to 0)...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!!
