How to use refreshScreenshot method in fMBT

Best Python code snippet using fMBT_python

ivi_apps.py

Source:ivi_apps.py Github

copy

Full Screen

...99 time.sleep(1)100 return ret101 def refAndTapBitmap(self, png, wait_time=1):102 print "++ refresh screen and tapBitmap " + png103 ret = self.refreshScreenshot() and self.tapBitmap(png)104 time.sleep(wait_time)105 return ret106 def refAndVerifyBitmap(self, png, wait_time=1):107 print "++ refresh screen and verify bitmap " + png108 ret = self.refreshScreenshot() and self.verifyBitmap(png)109 time.sleep(wait_time)110 return ret111 112 def refAndWaitAllBitmap(self, picture_list):113 print "++ refresh screen and wait all bitmap: " \114 + ', '.join(picture_list)115 self.refreshScreenshot()116 ret = True117 for p in picture_list:118 if not self.waitBitmap(p):119 print "++ %s not found" % p120 ret = False121 return ret122 def findPid(self, process_name):123 cmd = "pgrep -f '%s'" % process_name124 (r, so, se ) = self.shellSOE(cmd)125 pids = []126 if r == 0:127 pids = [string.atoi(n) for n in filter(lambda l: len(l)>0, so.split("\n"))]128 return r, pids129 def verifyAllProcess(self, process_list):130 print "++ check process: " + ', '.join(process_list)131 ret = True132 for p in process_list:133 if len(self.findPid(p)[1]) == 0:134 print "++ %s not found" % p135 ret = False136 else:137 print "++ found %s" % p138 return ret139 def _hoover(self, x, y):140 self.drag((x, y), (x, y), delayBeforeMoves=-1, delayAfterMoves=-1, movePoints=1)141 def refreshScreenshot(self):142 ret = False143 if self.move_cursor == True:144 if self.maxX != 0:145 print "++ move cursor to %d, %d" % (self.maxX, self.maxY)146 self._hoover(self.maxX, self.maxY)147 ret = fmbttizen.Device.refreshScreenshot(self)148 if self.maxX != 0:149 print "++ move cursor to 0, 0"150 self._hoover(0, 0)151 else:152 ret = fmbttizen.Device.refreshScreenshot(self)153 return ret154 155 def check_call(self, cmd):156 (ret, so, se) = self.shellSOE(cmd)157 if ret != 0:158 print "++ fail to run cmd `%s'" % (cmd)159 print "++ standard output: " + so 160 print "++ standard error:" + se161 raise TizenError("cmd_issue", "fail to run cmd `%s'" % (cmd))162 return so163class cl_app():164 def __init__(self, name, process, controller):165 self.name = name166 self.process = process167 self.controllerImp = controller168class NightModeController():169 def __init__(self, controller):170 self.controllerImp = controller171 self.theme = ""172 173 def refNightMode(self):174 self.theme = ""175 (ret, so, se) = self.controllerImp.shellSOE("amb-get NightMode")176 if ret == 0:177 if '"NightMode": 1' in so:178 self.theme = "night"179 elif '"NightMode": 0' in so:180 self.theme = "day"181 if self.theme:182 print "++ get NightMode successfully, the theme is " + self.theme183 else:184 self.theme = "day"185 print "++ fail to get NightMode, use default theme `%s'" % self.theme186 theme_str = app_icons_str.replace("%theme%", self.theme)187 exec(theme_str)188 print "++ app_icons: %s" % app_icons189 def setNightMode(self, night_mode=True):190 if night_mode:191 pass192 else:193 pass194 self.refNightMode()195class WestonDesktop(cl_app):196 def __init__(self, controller):197 cl_app.__init__(self, "WestonDesktop", "", controller)198 self.night_mode_ctrl = NightModeController(controller)199 def wrt_launch(self, app_name):200 out = self.controllerImp.check_call("wrt-launcher -l")201 for l in out.splitlines():202 if l.find(app_name) != -1:203 app_id = l.split()[-1]204 if app_id.find(".%s" % app_name) == -1:205 print "++ app_id format is not correct `%s'" % (app_id)206 return False207 print "++ found app_id `%s'" % (app_id)208 break209 else:210 print "++ not found app_id for %s" % (app_name)211 return False212 self.controllerImp.type("wrt-launcher -s %s\n" % app_id)213 def cmd_launch(self, app_name):214 self.controllerImp.type("%s\n" % app_name)215 def launch_app(self, app_name):216 self.controllerImp.type("launch_app %s\n" % app_name)217 def launch(self, app_name, picture_list=[], process_list=[]):218 if self.controllerImp.refAndTapBitmap("term.icon.png") or \219 self.controllerImp.refAndTapBitmap("term.icon.png"):220 print "++ sucessfully tap western term icon"221 else:222 return False223 # to fetch focus, tricky !!224 self.controllerImp._hoover(self.controllerImp.maxX, self.controllerImp.maxY)225 print "++ proper launch app"226 if app_name in ["saythis", "Settings", "GhostCluster", "MediaPlayer"]:227 self.wrt_launch(app_name)228 elif app_name in ["org.tizen.dialer"]:229 self.launch_app(app_name)230 else:231 self.cmd_launch(app_name)232 print "++ try to refresh screenshot"233 self.controllerImp.refreshScreenshot()234 time.sleep(2)235 if process_list:236 print "++ verify started process..."237 if not self.controllerImp.verifyAllProcess(process_list):238 print "++ expected process not found"239 return False240 if picture_list:241 print "++ verify expected bitmap..."242 if not self.controllerImp.refAndWaitAllBitmap(picture_list):243 print "++ fail to verify bitmap"244 return False245 print "++ launch %s successfully" % (app_name)246 time.sleep(2)247 return True248 def refNightMode(self):249 self.night_mode_ctrl.refNightMode()250class ICOHomeScreen(cl_app):251 def __init__(self, controller):252 cl_app.__init__(self, "homescreen", "", controller)253 self.current_page = 0254 self.app_status = {}255 self.max_page = 3256 self.night_mode_ctrl = NightModeController(controller)257 self.apps = []258 def registerApp(self, app):259 self.apps.append(app)260 def clickApplist(self):261 return self.controllerImp.refAndTapBitmap(app_icons["applist"])262 263 def swipeToWest(self):264 ret = self.controllerImp.swipeToWest()265 if self.current_page < self.max_page - 1:266 self.current_page += 1267 print "++ current page: %d" % self.current_page268 assert(self.current_page < self.max_page)269 return ret270 def swipeToEast(self):271 ret = self.controllerImp.swipeToEast()272 if self.current_page > 0:273 self.current_page -= 1274 print "++ current page: %d" % self.current_page275 assert(self.current_page >= 0)276 return ret277 def swipePages(self, start, end):278 assert start >= 0, "wrong start page %d" % start279 assert end < self.max_page, "wrong end page %d" % end280 print "++ current_page: %d, start page: %d, end page: %d" \281 % (self.current_page, start, end)282 if start > end:283 for i in range(start - end):284 if not self.swipeToEast():285 return False286 else:287 for i in range(end - start):288 if not self.swipeToWest():289 return False290 return True291 def swipeToPage(self, end):292 return self.swipePages(self.current_page, end)293 def swipeToLeftmost(self):294 return self.swipePages(self.current_page, 0)295 def launch(self, app_name, app_icon, picture_list=[], process_list=[]):296 print "++ click applist button"297 if not self.clickApplist():298 print "++ fail to click applist button!"299 return False300 301 first_launch = False302 icon = app_icon303 print "++ try to launch %s" % app_name304 if app_name in self.app_status.keys():305 print "++ %s is already launched" % app_name306 app_page = self.app_status[app_name][0]307 print "++ swipe to app page %d" % app_page308 if not self.swipeToPage(app_page):309 print "++ fail to swipe to the specified page! cur page: %d" \310 % self.current_page311 return False312 print "++ try to tap the old item"313 if not self.controllerImp.tapItem((self.app_status[app_name])[1]):314 print "++ fail to tap item!"315 return False316 else: # first launch317 print "++ %s is the first launch" % app_name318 first_launch = True319 print "++ swipe to the left most side"320 if not self.swipeToLeftmost():321 print "++ fail to swipe to the left most side!"322 return False323 for i in range(self.max_page):324 print "++ check app page %d" % i325 if self.controllerImp.refreshScreenshot() == None:326 print "++ fail to refresh screenshot!"327 return False328 if self.controllerImp.tapBitmap(icon) == True:329 print "++ found icon " + icon330 app_item = self.controllerImp._lastScreenshot.findItemsByBitmap(icon)[0]331 break332 else:333 print "++ swipe to the next page"334 if not self.swipeToWest():335 print "++ fail to swipe to next page!"336 return False337 else:338 print "++ not found app icon %s" % icon339 if not self.clickApplist():...

Full Screen

Full Screen

testservice.py

Source:testservice.py Github

copy

Full Screen

...29 self.first_call = True30 self.useFMBTDevice = True31 try:32 self.d = fmbtandroid.Device()33 self.d.refreshScreenshot().save(SCREENSHOT)34 self.screensize = self.__getimgsize(SCREENSHOT)35 self.d.setScreenshotLimit(10)36 self.d.setScreenshotArchiveMethod("remove")37 except:38 self.useFMBTDevice = False39 # When asking server to match the template being selected set to true40 self.livematching = False41 self.templates = ['template 1', 'template 2', 'template 3', 'template 4']42 self.id = 043 self.img = self.__loadimage("./screenshot1.png", True)44 self.img2 = self.__loadimage("./screenshot2.png", True)45 self.resultimg = self.__loadimage("./machinevision-result.png", True)46 self.position = RobotCoord(x=152,y=385,z=0.9,alfa=0)47 def __getimgsize(self, filename):48 pil = pilimage.open(filename)49 if self.useFMBTDevice and self.d._screenSize == None:50 self.d._screenSize = pil.size51 return pil.size52 def __loadimage(self, filename, resolvesize=False):53 img = Image()54 img.id = self.id55 with open(filename, "rb") as imgfile:56 img.imagedata = imgfile.read()57 if resolvesize:58 size = self.__getimgsize(filename)59 img.width = size[0]60 img.height = size[1]61 else:62 img.width = self.screensize[0]63 img.height = self.screensize[1]64 return img65 def locked(self):66 if self.first_call:67 self.first_call = False68 return True69 else:70 return False71 def getvisualfeeds(self):72 img = None73 if self.useFMBTDevice:74 self.d.refreshScreenshot().save(SCREENSHOT)75 img = self.__loadimage(SCREENSHOT)76 else: # change images for visual feed updates77 if self.id % 2 == 0:78 img = self.img79 else:80 img = self.img281 sleep(0.5)82 self.id += 183 feed1 = visualfeed()84 feed1.content = img85 feed1.updated = True86 feed1.message = str(datetime.now())87 if self.livematching:88 feed2 = visualfeed()89 feed2.content = self.resultimg90 feed2.updated = True91 feed2.message = str(datetime.now())92 return [feed1, feed2]93 else:94 return [feed1]95 def setpreviewmatchingmode(self, args):96 print "Set preview matching mode to {}".format(args.enabled)97 self.livematching = args.enabled98 return True99 def gettempls(self):100 return self.templates101 def setfindtempl(self, template):102 if template == None:103 print "Stop matching template"104 self.livematching = False105 else:106 print "Start matching template {}".format(template)107 self.livematching = True108 return True109 def savetempl(self, idx, topleft, bottomright, name):110 print "Save ({},{}) -> ({},{}) from frame {} as template {}".format(topleft.x, topleft.y, bottomright.x, bottomright.y, idx, name)111 self.templates.append(name)112 sleep(0.2)113 return True114 def savereference(self, idx, name):115 print "Save frame {} as reference {}".format(idx, name)116 sleep(0.2)117 return True118 def setVisualDataSource(self, req):119 if req.source_type == VisualSource.CAMTHREAD:120 print "Setting visual data source to CAMTHREAD"121 else:122 print "Setting visual data source to something"123 return True124 def handleEvent(self, event):125 if event.type == EventType.KEYPRESS:126 print "Keycode: {}".format(event.keypress.keyCode)127 if self.useFMBTDevice and event.keypress.character == "h":128 self.d.pressHome()129 elif self.useFMBTDevice and event.keypress.character == "b":130 self.d.pressBack()131 elif self.useFMBTDevice and event.keypress.character == "m":132 self.d.pressMenu()133 elif self.useFMBTDevice and event.keypress.character == "s":134 self.d.pressAppSwitch()135 elif self.useFMBTDevice and event.keypress.character == "u":136 self.d.pressPower()137 self.d.refreshScreenshot()138 sleep(0.2)139 self.d.swipe((0.5, 0.7), "east")140 elif self.useFMBTDevice and event.keypress.keyCode == 39:141 self.d.swipe((0.5, 0.5), "east")142 elif self.useFMBTDevice and event.keypress.keyCode == 37:143 self.d.swipe((0.5, 0.5), "west")144 elif self.useFMBTDevice and event.keypress.keyCode == 40:145 self.d.swipe((0.5, 0.0), "south")146 elif self.useFMBTDevice and event.keypress.keyCode == 38:147 self.d.swipe((0.5, 1.0), "north")148 elif event.type == EventType.MOUSECLICK:149 print "Click: ({}, {})".format(event.click.x, event.click.y)150 if self.useFMBTDevice:151 self.d._conn.sendTap(event.click.x, event.click.y)...

Full Screen

Full Screen

pages.py

Source:pages.py Github

copy

Full Screen

...9s = fmbtx11.Screen(OPNRO)10s.setBitmapPath('kuvat')11class PagesTest(unittest.TestCase):12 def setUp(self):13 s.refreshScreenshot()14 def tearDown(self):15 s.tapBitmap("seur.png", colorMatch=0.5)16 sleep(DELAY)17 s.refreshScreenshot()18 def test_moveToPage2(self):19 s.tapBitmap("input-username.png", colorMatch=0.9)20 sleep(DELAY)21 s.refreshScreenshot()22 found = s.verifyBitmap("kuvas6.png", colorMatch=0.9)23 self.assertTrue(found, "Header2 not found")24if __name__ == '__main__':...

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