How to use _notifyOirEngine method in fMBT

Best Python code snippet using fMBT_python

fmbtgti.py

Source:fmbtgti.py Github

copy

Full Screen

...2325 self._ocrEngine.addScreenshot(self)2326 self._ocrEngineNotified = True2327 if id(self._ocrEngine) == id(self._oirEngine):2328 self._oirEngineNotified = True2329 def _notifyOirEngine(self):2330 if self._oirEngine and not self._oirEngineNotified:2331 self._oirEngine.addScreenshot(self)2332 self._oirEngineNotified = True2333 if id(self._oirEngine) == id(self._ocrEngine):2334 self._ocrEngineNotified = True2335 def dumpHcr(self, filename, **hcrArgs):2336 """2337 Visualize high contrast regions, write image to given file.2338 Experimental.2339 """2340 items = self.findItemsByHcr(**hcrArgs)2341 eyenfinger.drawBboxes(self.filename(), filename,2342 [i.bbox() for i in items])2343 def dumpOcr(self, **kwargs):2344 """2345 Return what OCR engine recognizes on this screenshot.2346 Not all OCR engines provide this functionality.2347 """2348 self._notifyOcrEngine()2349 return self._ocrEngine.dumpOcr(self, **kwargs)2350 def dumpOcrWords(self, **kwargs):2351 """2352 Deprecated, use dumpOcr().2353 """2354 return self.dumpOcr(**kwargs)2355 def filename(self):2356 return self._filename2357 def _findFirstMatchingBitmapCandidate(self, bitmap, **oirArgs):2358 for candidate in self._paths.abspaths(bitmap):2359 found = self._oirEngine.findBitmap(self, candidate, **oirArgs)2360 if found:2361 return found2362 return []2363 def findItemsByBitmap(self, bitmap, **oirFindArgs):2364 if self._oirEngine != None:2365 self._notifyOirEngine()2366 oirArgsList = self._paths.oirArgsList(bitmap)2367 results = []2368 if oirArgsList:2369 for oirArgs in oirArgsList:2370 oirArgs, _ = _takeOirArgs(self._oirEngine, oirArgs.copy())2371 oirArgs.update(oirFindArgs)2372 results.extend(self._findFirstMatchingBitmapCandidate(2373 bitmap, **oirArgs))2374 if results: break2375 else:2376 oirArgs = oirFindArgs2377 results.extend(self._findFirstMatchingBitmapCandidate(2378 bitmap, **oirArgs))2379 return results2380 else:2381 raise RuntimeError('Trying to use OIR on "%s" without OIR engine.' % (self.filename(),))2382 def findItemsByDiff(self, image, colorMatch=1.0, limit=1, area=None):2383 """2384 Return list of items that differ in this and the reference images2385 Parameters:2386 image (string):2387 filename of reference image.2388 colorMatch (optional, float):2389 required color matching accuracy. The default is 1.02390 (exact match)2391 limit (optional, integer):2392 max number of matching items to be returned.2393 The default is 1.2394 """2395 foundItems = []2396 closeImageA = False2397 closeImageB = False2398 self._notifyOirEngine()2399 try:2400 # Open imageA and imageB for comparison2401 if (self.filename() in getattr(self._oirEngine, "_openedImages", {})):2402 # if possible, use already opened image object2403 imageA = self._oirEngine._openedImages[self.filename()]2404 else:2405 imageA = _e4gOpenImage(self.filename())2406 closeImageA = True2407 imageB = _e4gOpenImage(image)2408 closeImageB = True2409 # Find differing pixels2410 bbox = _Bbox(-1, 0, 0, 0, 0)2411 while limit != 0:2412 found = eye4graphics.findNextDiff(2413 ctypes.byref(bbox),2414 ctypes.c_void_p(imageA),2415 ctypes.c_void_p(imageB),2416 ctypes.c_double(colorMatch),2417 ctypes.c_double(1.0), # opacityLimit2418 None, # searchAreaA2419 None, # searchAreaB2420 1)2421 if found != 1:2422 break2423 rgbDiff = (bbox.error >> 16 & 0xff,2424 bbox.error >> 8 & 0xff,2425 bbox.error & 0xff)2426 foundItems.append(2427 GUIItem("DIFF %s" %2428 (rgbDiff,),2429 (bbox.left, bbox.top, bbox.right, bbox.bottom),2430 self))2431 limit -= 12432 finally:2433 if closeImageA:2434 eye4graphics.closeImage(imageA)2435 if closeImageB:2436 eye4graphics.closeImage(imageB)2437 return foundItems2438 def findItemsByColor(self, rgb888, colorMatch=1.0, limit=1, area=None,2439 invertMatch=False, group=""):2440 """2441 Return list of items that match given color.2442 Parameters:2443 rgb888 (integer triplet (red, green, blue)):2444 color to be searched for.2445 colorMatch (optional, float):2446 required color matching accuracy. The default is 1.02447 (exact match).2448 limit (optional, integer):2449 max number of matching items to be returned.2450 The default is 1.2451 area ((left, top, right, bottom), optional):2452 subregion in the screenshot from which items will be2453 searched for. The default is (0.0, 0.0, 1.0, 1.0), that2454 is whole screen.2455 invertMatch (optional, boolean):2456 if True, search for items *not* matching the color.2457 The default is False.2458 group (optional, string):2459 group matching pixels to large items. Accepted2460 values are "adjacent" (group pixels that are next to2461 each other) and "" (no grouping). The default is "".2462 """2463 self._notifyOirEngine()2464 if (self.filename() in getattr(self._oirEngine, "_openedImages", {})):2465 # if possible, use already opened image object2466 image = self._oirEngine._openedImages[self.filename()]2467 closeImage = False2468 else:2469 image = _e4gOpenImage(self.filename())2470 closeImage = True2471 bbox = _Bbox(-1, 0, 0, 0, 0)2472 color = _Rgb888(*rgb888)2473 ssSize = self.size()2474 if area == None:2475 area = (0.0, 0.0, 1.0, 1.0)2476 leftTopRightBottomZero = (_intCoords((area[0], area[1]), ssSize) +2477 _intCoords((area[2], area[3]), ssSize) +2478 (0,))2479 areaBbox = _Bbox(*leftTopRightBottomZero)2480 foundItems = []2481 coord2item = {} # (x, y) -> viewItem2482 try:2483 while limit != 0:2484 found = eye4graphics.findNextColor(2485 ctypes.byref(bbox),2486 ctypes.c_void_p(image),2487 ctypes.byref(color),2488 ctypes.c_double(colorMatch),2489 ctypes.c_double(1.0), # opacityLimit2490 ctypes.c_int(invertMatch),2491 ctypes.byref(areaBbox))2492 if found != 1:2493 break2494 foundColor = int(bbox.error)2495 foundRgb = (foundColor >> 16 & 0xff,2496 foundColor >> 8 & 0xff,2497 foundColor & 0xff)2498 if invertMatch:2499 comp = "!="2500 else:2501 comp = "=="2502 if not group:2503 foundItems.append(2504 GUIItem("RGB#%.2x%.2x%.2x%s%.2x%.2x%.2x (%s)" %2505 (rgb888 + (comp,) + foundRgb + (colorMatch,)),2506 (bbox.left, bbox.top, bbox.right, bbox.bottom),2507 self))2508 limit -= 12509 elif group == "adjacent":2510 x = bbox.left2511 y = bbox.top2512 itemA = None2513 itemB = None2514 if (x-1, y) in coord2item:2515 # AAAx2516 itemA = coord2item[(x-1, y)]2517 if itemA._bbox[2] < x: # right < x2518 itemA._bbox = (itemA._bbox[0], itemA._bbox[1], x, itemA._bbox[3])2519 coord2item[(x, y)] = itemA2520 if (x, y-1) in coord2item:2521 # BBB2522 # x2523 itemB = coord2item[(x, y-1)]2524 if itemB._bbox[3] < y: # bottom < y2525 itemB._bbox = (itemB._bbox[0], itemB._bbox[1], itemB._bbox[2], y)2526 coord2item[(x, y)] = itemB2527 if itemA:2528 # BBB2529 # AAAx2530 if itemB != itemA:2531 itemB._bbox = (min(itemA._bbox[0], itemB._bbox[0]),2532 min(itemA._bbox[1], itemB._bbox[1]),2533 max(itemA._bbox[2], itemB._bbox[2]),2534 max(itemA._bbox[3], itemB._bbox[3]))2535 for ax in xrange(itemA._bbox[0], itemA._bbox[2]+1):2536 for ay in xrange(itemA._bbox[1], itemA._bbox[3]+1):2537 if coord2item.get((ax, ay), None) == itemA:2538 coord2item[(ax, ay)] = itemB2539 foundItems.remove(itemA)2540 limit += 12541 if not itemA and not itemB:2542 itemA = GUIItem("RGB#%.2x%.2x%.2x%s%.2x%.2x%.2x (%s)" %2543 (rgb888 + (comp,) + foundRgb + (colorMatch,)),2544 (bbox.left, bbox.top, bbox.right, bbox.bottom),2545 self)2546 limit -= 12547 foundItems.append(itemA)2548 coord2item[(x, y)] = itemA2549 finally:2550 if closeImage:2551 eye4graphics.closeImage(image)2552 return foundItems2553 def findItemsByOcr(self, text, **ocrEngineArgs):2554 if self._ocrEngine != None:2555 self._notifyOcrEngine()2556 return self._ocrEngine.findText(self, text, **ocrEngineArgs)2557 else:2558 raise RuntimeError('Trying to use OCR on "%s" without OCR engine.' % (self.filename(),))2559 def findItemsByHcr(self, xRes=24, yRes=24, threshold=0.1):2560 """2561 Return "high contrast regions" in the screenshot.2562 Experimental. See if it finds regions that could be2563 interacted with.2564 """2565 ppFilename = "%s-hcrpp.png" % (self.filename(),)2566 _convert(self.filename(),2567 ["-colorspace", "gray", "-depth", "3"],2568 ppFilename)2569 bbox = _Bbox(0, 0, 0, 0, 0)2570 foundItems = []2571 try:2572 image = _e4gOpenImage(ppFilename)2573 while True:2574 if eye4graphics.findNextHighErrorBlock(ctypes.byref(bbox), image, xRes, yRes, threshold, 0) == 0:2575 break2576 foundItems.append(GUIItem(2577 "%sx%s/%s" % (bbox.left/xRes, bbox.top/yRes, bbox.error),2578 (bbox.left, bbox.top, bbox.right, bbox.bottom),2579 self))2580 finally:2581 eye4graphics.closeImage(image)2582 return foundItems2583 def getColor(self, (x, y)):2584 """2585 Return pixel color at coordinates2586 Parameters:2587 (x, y) (pair of integers or floats):2588 coordinates in the image.2589 Returns tuple of integers: (red, green, blue).2590 """2591 self._notifyOirEngine()2592 xsize, ysize = self.size()2593 x, y = _intCoords((x, y), (xsize, ysize))2594 if not (0 <= x < xsize and 0 <= y < ysize):2595 raise ValueError("invalid coordinates (%s, %s)" % (x, y))2596 if (self.filename() in getattr(self._oirEngine, "_openedImages", {})):2597 # if possible, use already opened image object2598 image = self._oirEngine._openedImages[self.filename()]2599 closeImage = False2600 else:2601 image = _e4gOpenImage(self.filename())2602 closeImage = True2603 try:2604 color = _Rgb888(0, 0, 0)2605 v = eye4graphics.rgb888at(ctypes.byref(color),...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful