Best Python code snippet using pyatom_python
AXClasses.py
Source:AXClasses.py  
...982        retelem = None983        args = (retelem, )984        return self.waitFor(timeout, notification, callback=callback,985                            args=args)986    def waitForWindowToAppear(self, winName, timeout=10):987        """Convenience method to wait for a window with the given name to988        appear.989        Returns: Boolean990        """991        return self.waitFor(timeout, 'AXWindowCreated', AXTitle=winName)992    def waitForWindowToDisappear(self, winName, timeout=10):993        """Convenience method to wait for a window with the given name to994        disappear.995        Returns: Boolean996        """997        callback = AXCallbacks.elemDisappearedCallback998        retelem = None999        args = (retelem, self)1000        # For some reason for the AXUIElementDestroyed notification to fire,...sikuli_utils.py
Source:sikuli_utils.py  
...167            time.sleep(0.1)168    uprint("Dialog still present at", repr(currDialog))169    return False170171def waitForWindowToAppear(**kw):172    return waitForDialogToAppear(dialogRatio=None, **kw)173174def waitForDialogToAppear(maxSeconds=10, dialogRatio=3):175    # For progress dialogs etc176    # Assume these are less than a third of the height of the screen177    currDialog = None178    for _ in range(maxSeconds * 10):179        currDialog = getWindow(dialogRatio)180        if currDialog is not None:181            return currDialog182        else:183            time.sleep(0.1)184185186def takeHighlightedScreenshot(fileName, highlightArea):187    # highlightArea.highlight()188    r = " (" + str(highlightArea.getX()) + "," + str(highlightArea.getY()) + " " + str(highlightArea.getW()) + "x" + str(highlightArea.getH()) + ")"189    shutil.move(capture(SCREEN), fileName + r + ".png")190    # highlightArea.highlight()191 192193def findRegionFromImages(label, imageFiles, searchArea, timeout=1, override_similarity=None, **kw):194    for imageFile in sorted(imageFiles):195        try:196            log("Searching for image " + label + " in " + repr(searchArea) + " timeout=" + repr(timeout))197            if override_similarity is None:198                region = searchArea.wait(imageFile, timeout)199            else:200                pattern = Pattern(imageFile).similar(override_similarity)201                region = searchArea.wait(pattern, timeout)202            log("Found image region for " + label + " = " + repr(region))203            # print "Text was", region.text().encode("utf-8")204            return region205        except (FindFailed, SikuliXception):206            pass207            208    takeHighlightedScreenshot("screenshot_Failed to find image region for " + label, searchArea)209    log("Failed to find image region for " + label + " in " + repr(searchArea))210211    212class BadHintsFile(RuntimeError):213    pass214215216def readHint(line):217    regex = re.compile("hint=([0-9]*)-([0-9]*) of ([0-9]*)")218    match = regex.search(line)219    if match is not None:220        pos1, pos2, size = [ int(match.group(i)) for i in range(1, 4)]221        return pos1, pos2 - pos1, size222    else:223        raise BadHintsFile, "Could not parse line in hints file: " + line224225226def getHintArea(hintsFile):227    f = open(hintsFile)228    try:229        xPos, width, oldWindowWidth = readHint(f.readline())230        yPos, height, oldWindowHeight = readHint(f.readline())231    finally:232        f.close()233    win = getWindow()234    if xPos > win.getW():235        xPos -= oldWindowWidth - win.getW()236    if yPos > win.getH():237        yPos -= oldWindowHeight - win.getH()238    xPos += win.getX()239    yPos += win.getY()240    if xPos < 0 or yPos < 0:241        raise BadHintsFile, "Window size too different, could not make sense of hints file"242    hintArea = Region(xPos, yPos, width, height)243    return hintArea244245def findHintAreas(hintsFile, boundingBox=None):246    boundingBox = boundingBox or getWindow()247    if boundingBox is None:248        app.focus()249        boundingBox = waitForWindowToAppear()250        if boundingBox is None:251            terminate_with_screenshot("Could not find any application window after waiting 10 seconds, something is seriously wrong!")252            253    areas = [ (boundingBox, boundingBox, False) ]254    if not os.path.isfile(hintsFile):255        return areas256    257    try:258        hintArea = getHintArea(hintsFile)259        searchArea = hintArea.nearby(20)260        areas.insert(0, (hintArea, searchArea, True))  # try this before the whole window261    except BadHintsFile, e:262        sys.stderr.write("ERROR: could not parse hints file at " + hintsFile + "\n" + str(e) + "\n")263    return areas
...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!!
