Best Python code snippet using fMBT_python
eyenfinger.py
Source:eyenfinger.py
...530 _log('found "' + word + '": (' + str(bbox[0]) + ', ' + str(bbox[1]) + ')')531 if capture:532 drawWords(_g_origImage, capture, _g_words, _g_words)533 return sorted(_g_words.keys())534def iVerifyWord(word, match=0.33, appearance=1, capture=None):535 """536 DEPRECATED - use fmbtx11.Screen.verifyOcrText instead.537 Verify that word can be found from previously iRead() image.538 Parameters:539 word word that should be checked540 appearance if word appears many times, appearance to541 be clicked. Defaults to the first one.542 match minimum matching score543 capture save image with verified word highlighted544 to this file. Default: None (nothing is saved).545 Returns pair: ((score, matchingWord), (left, top, right, bottom)), where546 score score of found match (1.0 for perfect match)547 matchingWord corresponding word detected by OCR548 (left, top, right, bottom)549 bounding box of the word in read image550 Throws BadMatch error if word is not found.551 Throws NoOCRResults error if there are OCR results available552 on the current screen.553 """554 if _g_words == None:555 raise NoOCRResults('iRead has not been called with ocr=True')556 score, matching_word = findWord(word)557 if capture:558 drawWords(_g_origImage, capture, [word], _g_words)559 if score < match:560 raise BadMatch('No matching word for "%s". The best candidate "%s" with score %.2f, required %.2f' %561 (word, matching_word, score, match))562 return ((score, matching_word), _g_words[matching_word][appearance-1][2])563def iVerifyText(text, match=0.33, capture=None):564 """565 DEPRECATED - use fmbtx11.Screen.verifyOcrText instead.566 Verify that text can be found from previously iRead() image.567 Parameters:568 text multiple words that should be checked569 match minimum matching score570 capture save image with verified text highlighted571 to this file. Default: None (nothing is saved).572 Returns pair:573 ((score, matchingText), (left, top, right, bottom)), where574 score score of found match (1.0 for perfect match)575 matchingText corresponding text detected by OCR576 (left, top, right, bottom)577 bounding box of the text in read image578 Throws BadMatch error if text is not found.579 Throws NoOCRResults error if there are OCR results available580 on the current screen.581 """582 if _g_words == None:583 raise NoOCRResults('iRead has not been called with ocr=True')584 score_text_bbox_list = findText(text, match)585 if len(score_text_bbox_list) == 0:586 raise BadMatch('No match >= %s for text "%s"' % (score, text))587 score, text, bbox = score_text_box_list[0]588 if capture:589 drawBbox(_g_origImage, capture, bbox, "%.2f %s" % (score, text))590 return ((score, matching_text), bbox)591def iVerifyIcon(iconFilename, match=None, colorMatch=None, opacityLimit=None, capture=None, area=(0.0, 0.0, 1.0, 1.0), _origin="iVerifyIcon"):592 """593 DEPRECATED - use fmbtx11.Screen.verifyBitmap instead.594 Verify that icon can be found from previously iRead() image.595 Parameters:596 iconFilename name of the icon file to be searched for597 match minimum matching score between 0 and 1.0,598 1.0 is perfect match (default)599 colorMatch 1.0 (default) requires exact color match. Value600 below 1.0 defines maximum allowed color601 difference. See iSetDefaultIconColorMatch.602 opacityLimit 0.0 (default) requires exact color values603 independently of opacity. If lower than 1.0,604 pixel less opaque than given value are skipped605 in pixel perfect comparisons.606 capture save image with verified icon highlighted607 to this file. Default: None (nothing is saved).608 area rectangle (left, top, right, bottom). Search609 icon inside this rectangle only. Values can be610 absolute coordinates, or floats in range [0.0,611 1.0] that will be scaled to image dimensions.612 The default is (0.0, 0.0, 1.0, 1.0), that is613 full rectangle.614 Returns pair: (score, (left, top, right, bottom)), where615 score score of found match (1.0 for perfect match)616 (left, top, right, bottom)617 bounding box of found icon618 Throws BadMatch error if icon is not found.619 """620 if not eye4graphics:621 _log('ERROR: %s("%s") called, but eye4graphics not loaded.' % (_origin, iconFilename))622 raise EyenfingerError("eye4graphics not available")623 if not _g_origImage:624 _log('ERROR %s("%s") called, but source not defined (iRead not called).' % (_origin, iconFilename))625 raise BadSourceImage("Source image not defined, cannot search for an icon.")626 if not (os.path.isfile(iconFilename) and os.access(iconFilename, os.R_OK)):627 _log('ERROR %s("%s") called, but the icon file is not readable.' % (_origin, iconFilename))628 raise BadIconImage('Icon "%s" is not readable.' % (iconFilename,))629 if match == None:630 match = _g_defaultIconMatch631 if match > 1.0:632 _log('ERROR %s("%s"): invalid match value, must be below 1.0. ' % (_origin, iconFilename,))633 raise ValueError("invalid match value: %s, should be 0 <= match <= 1.0" % (match,))634 if colorMatch == None:635 colorMatch = _g_defaultIconColorMatch636 if not 0.0 <= colorMatch <= 1.0:637 _log('ERROR %s("%s"): invalid colorMatch value, must be between 0 and 1. ' % (_origin, iconFilename,))638 raise ValueError("invalid colorMatch value: %s, should be 0 <= colorMatch <= 1.0" % (colorMatch,))639 if opacityLimit == None:640 opacityLimit = _g_defaultIconOpacityLimit641 if not 0.0 <= opacityLimit <= 1.0:642 _log('ERROR %s("%s"): invalid opacityLimit value, must be between 0 and 1. ' % (_origin, iconFilename,))643 raise ValueError("invalid opacityLimit value: %s, should be 0 <= opacityLimit <= 1.0" % (opacityLimit,))644 if area[0] > area[2] or area[1] >= area[3]:645 raise ValueError("invalid area: %s, should be rectangle (left, top, right, bottom)" % (area,))646 leftTopRightBottomZero = (_coordsToInt((area[0], area[1]), windowSize()) +647 _coordsToInt((area[2], area[3]), windowSize()) +648 (0,))649 struct_area_bbox = Bbox(*leftTopRightBottomZero)650 struct_bbox = Bbox(0,0,0,0,0)651 threshold = int((1.0-match)*20)652 err = eye4graphics.findSingleIcon(ctypes.byref(struct_bbox),653 _g_origImage, iconFilename, threshold,654 ctypes.c_double(colorMatch),655 ctypes.c_double(opacityLimit),656 ctypes.byref(struct_area_bbox))657 bbox = (int(struct_bbox.left), int(struct_bbox.top),658 int(struct_bbox.right), int(struct_bbox.bottom))659 if err == -1 or err == -2:660 msg = '%s: "%s" not found, match=%.2f, threshold=%s, closest threshold %s.' % (661 _origin, iconFilename, match, threshold, int(struct_bbox.error))662 if capture:663 drawIcon(_g_origImage, capture, iconFilename, bbox, 'red')664 _log(msg)665 raise BadMatch(msg)666 elif err != 0:667 _log("%s: findSingleIcon returned %s" % (_origin, err,))668 raise BadMatch("%s not found, findSingleIcon returned %s." % (iconFilename, err))669 if threshold > 0:670 score = (threshold - int(struct_bbox.error)) / float(threshold)671 else:672 score = 1.0673 if capture:674 drawIcon(_g_origImage, capture, iconFilename, bbox, area=leftTopRightBottomZero[:4])675 return (score, bbox)676def iClickIcon(iconFilename, clickPos=(0.5,0.5), match=None,677 colorMatch=None, opacityLimit=None,678 mouseButton=1, mouseEvent=MOUSEEVENT_CLICK, dryRun=None, capture=None):679 """680 DEPRECATED - use fmbtx11.Screen.tapBitmap instead.681 Click coordinates relative to the given icon in previously iRead() image.682 Parameters:683 iconFilename read icon from this file684 clickPos position to be clicked,685 relative to word top-left corner of the bounding686 box around the word. X and Y units are relative687 to width and height of the box. (0,0) is the688 top-left corner, (1,1) is bottom-right corner,689 (0.5, 0.5) is the middle point (default).690 Values below 0 or greater than 1 click outside691 the bounding box.692 match 1.0 (default) requires exact match. Value below 1.0693 defines minimum required score for fuzzy matching694 (EXPERIMENTAL). See iSetDefaultIconMatch.695 colorMatch 1.0 (default) requires exact color match. Value696 below 1.0 defines maximum allowed color697 difference. See iSetDefaultIconColorMatch.698 opacityLimit 0.0 (default) requires exact color values699 independently of opacity. If lower than 1.0,700 pixel less opaque than given value are skipped701 in pixel perfect comparisons.702 mouseButton mouse button to be synthesized on the event, default is 1.703 mouseEvent event to be synthesized, the default is MOUSEEVENT_CLICK,704 others: MOUSEEVENT_MOVE, MOUSEEVENT_DOWN, MOUSEEVENT_UP.705 dryRun if True, does not synthesize events. Still returns706 coordinates of the clicked position and illustrates707 the clicked position on the capture image if708 given.709 capture name of file where image of highlighted icon and710 clicked point are saved.711 Returns pair (score, (clickedX, clickedY)), where712 score score of found match (1.0 for perfect match)713 (clickedX, clickedY)714 X and Y coordinates of clicked position on the715 screen.716 Throws BadMatch error if could not find a matching word.717 """718 _DEPRECATED()719 score, bbox = iVerifyIcon(iconFilename, match=match,720 colorMatch=colorMatch, opacityLimit=opacityLimit,721 capture=capture, _origin="iClickIcon")722 clickedXY = iClickBox(bbox, clickPos, mouseButton, mouseEvent, dryRun,723 capture, _captureText = iconFilename)724 return (score, clickedXY)725def iClickWord(word, appearance=1, clickPos=(0.5,0.5), match=0.33,726 mouseButton=1, mouseEvent=1, dryRun=None, capture=None):727 """728 DEPRECATED - use fmbtx11.Screen.tapOcrText instead.729 Click coordinates relative to the given word in previously iRead() image.730 Parameters:731 word word that should be clicked732 appearance if word appears many times, appearance to733 be clicked. Defaults to the first one.734 clickPos position to be clicked,735 relative to word top-left corner of the bounding736 box around the word. X and Y units are relative737 to width and height of the box. (0,0) is the738 top-left corner, (1,1) is bottom-right corner,739 (0.5, 0.5) is the middle point (default).740 Values below 0 or greater than 1 click outside741 the bounding box.742 capture name of file where image of highlighted word and743 clicked point are saved.744 Returns pair: ((score, matchingWord), (clickedX, clickedY)), where745 score score of found match (1.0 for perfect match)746 matchingWord corresponding word detected by OCR747 (clickedX, clickedY)748 X and Y coordinates of clicked position on the749 screen.750 Throws BadMatch error if could not find a matching word.751 Throws NoOCRResults error if there are OCR results available752 on the current screen.753 """754 _DEPRECATED()755 (score, matching_word), bbox = iVerifyWord(word, appearance=appearance, match=match, capture=False)756 clickedX, clickedY = iClickBox(bbox, clickPos, mouseButton, mouseEvent, dryRun, capture=False)757 windowId = _g_lastWindow758 _log('iClickWord("%s"): word "%s", match %.2f, bbox %s, window offset %s, click %s' %759 (word, matching_word, score,760 bbox, _g_windowOffsets[windowId],761 (clickedX, clickedY)))762 if capture:763 drawWords(_g_origImage, capture, [word], _g_words)764 drawClickedPoint(capture, capture, (clickedX, clickedY))765 return ((score, matching_word), (clickedX, clickedY))766def iClickBox((left, top, right, bottom), clickPos=(0.5, 0.5),767 mouseButton=1, mouseEvent=1, dryRun=None,768 capture=None, _captureText=None):769 """...
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!!