How to use _takePinchArgs method in fMBT

Best Python code snippet using fMBT_python

fmbttizen.py

Source:fmbttizen.py Github

copy

Full Screen

...59fmbtgti._OCRPREPROCESS = [60 '-sharpen 5 -filter Mitchell %(zoom)s -sharpen 5 -level 60%%,60%%,3.0 -sharpen 5',61 '-sharpen 5 -level 90%%,100%%,3.0 -filter Mitchell -sharpen 5'62 ]63def _takePinchArgs(d):64 return fmbtgti._takeArgs(("finger1Dir", "finger2Dir", "duration",65 "movePoints", "sleepBeforeMove",66 "sleepAfterMove"), d)67def _adapterLog(msg):68 fmbt.adapterlog("fmbttizen: %s" % (msg,))69def _run(command, expectedExitStatus=None):70 if type(command) == str: shell=True71 else: shell=False72 try:73 p = subprocess.Popen(command, shell=shell,74 stdout=subprocess.PIPE,75 stderr=subprocess.PIPE,76 close_fds=True)77 if expectedExitStatus != None:78 out, err = p.communicate()79 else:80 out, err = ('', None)81 except Exception, e:82 class fakeProcess(object): pass83 p = fakeProcess84 p.returncode = 12785 out, err = ('', e)86 exitStatus = p.returncode87 if (expectedExitStatus != None and88 exitStatus != expectedExitStatus and89 exitStatus not in expectedExitStatus):90 msg = "Executing %s failed. Exit status: %s, expected %s" % (command, exitStatus, expectedExitStatus)91 fmbt.adapterlog("%s\n stdout: %s\n stderr: %s\n" % (msg, out, err))92 raise FMBTTizenError(msg)93 return exitStatus, out, err94def _fileToQueue(f, outQueue):95 line = f.readline()96 while line != "":97 outQueue.put(line)98 line = f.readline()99 f.close()100class Device(fmbtgti.GUITestInterface):101 def __init__(self, serialNumber=None, loginCommand=None, debugAgentFile=None, **kwargs):102 """Parameters:103 serialNumber (string, optional)104 the serial number of the device to be connected.105 The default is the first device in "sdb devices"106 list.107 loginCommand (string, optional)108 Shell command for establishing SSH connection to the109 device. Example:110 loginCommand = "/usr/bin/ssh tizen@192.168.99.20"111 If loginCommand is given, sdb will not be used.112 debugAgentFile (file-like object, optional)113 record communication with the fMBT Tizen agent to114 given file. The default is None: communication is115 not recorded.116 rotateScreenshot (integer, optional)117 rotate new screenshots by rotateScreenshot degrees.118 Example: rotateScreenshot=-90. The default is 0 (no119 rotation).120 """121 fmbtgti.GUITestInterface.__init__(self, **kwargs)122 c = TizenDeviceConnection(serialNumber=serialNumber,123 loginCommand=loginCommand,124 debugAgentFile=debugAgentFile)125 self.setConnection(c)126 if "rotateScreenshot" in kwargs:127 c.sendScreenshotRotation(kwargs["rotateScreenshot"])128 c._gti = self129 self._serialNumber = self._conn._serialNumber130 def close(self):131 fmbtgti.GUITestInterface.close(self)132 if hasattr(self, "_conn"):133 self._conn.close()134 def connect(self):135 """136 Connect to the Tizen device.137 """138 if hasattr(self, "_conn"):139 self._conn.open()140 return True141 else:142 return False143 def disconnect(self):144 """145 Close the current connection to Tizen device.146 Returns True on success, otherwise False.147 """148 if hasattr(self, "_conn"):149 self._conn.close()150 return True151 else:152 return False153 def displayStatus(self):154 """155 Returns status of device display, "On" or "Off".156 """157 return self._conn.recvDisplayStatus()158 def pinch(self, (x, y), startDistance, endDistance,159 finger1Dir=90, finger2Dir=270, duration=1.0, movePoints=20,160 sleepBeforeMove=0, sleepAfterMove=0):161 """162 Pinch (open or close) on coordinates (x, y).163 Parameters:164 x, y (integer):165 the central point of the gesture. Values in range166 [0.0, 1.0] are scaled to full screen width and167 height.168 startDistance, endDistance (float):169 distance from both finger tips to the central point170 of the gesture, at the start and at the end of the171 gesture. Values in range [0.0, 1.0] are scaled up to172 the distance from the coordinates to the edge of the173 screen. Both finger tips will reach an edge if174 distance is 1.0.175 finger1Dir, finger2Dir (integer, optional):176 directions for finger tip movements, in range [0,177 360]. 0 is to the east, 90 to the north, etc. The178 defaults are 90 and 270.179 duration (float, optional):180 duration of the movement in seconds. The default is181 1.0.182 movePoints (integer, optional):183 number of points to which finger tips are moved184 after laying them to the initial positions. The185 default is 20.186 sleepBeforeMove, sleepAfterMove (float, optional):187 seconds to be slept after laying finger tips on the188 display 1) before the first move, and 2) after the189 last move before raising finger tips. The defaults190 are 0.0.191 """192 screenWidth, screenHeight = self.screenSize()193 screenDiagonal = math.sqrt(screenWidth**2 + screenHeight**2)194 if x == None: x = 0.5195 if y == None: y = 0.5196 x, y = self.intCoords((x, y))197 if type(startDistance) == float and 0.0 <= startDistance <= 1.0:198 startDistanceInPixels = (startDistance *199 max(fmbtgti._edgeDistanceInDirection((x, y), self.screenSize(), finger1Dir),200 fmbtgti._edgeDistanceInDirection((x, y), self.screenSize(), finger2Dir)))201 else: startDistanceInPixels = int(startDistance)202 if type(endDistance) == float and 0.0 <= endDistance <= 1.0:203 endDistanceInPixels = (endDistance *204 max(fmbtgti._edgeDistanceInDirection((x, y), self.screenSize(), finger1Dir),205 fmbtgti._edgeDistanceInDirection((x, y), self.screenSize(), finger2Dir)))206 else: endDistanceInPixels = int(endDistance)207 finger1startX = int(x + math.cos(math.radians(finger1Dir)) * startDistanceInPixels)208 finger1startY = int(y + math.sin(math.radians(finger1Dir)) * startDistanceInPixels)209 finger1endX = int(x + math.cos(math.radians(finger1Dir)) * endDistanceInPixels)210 finger1endY = int(y + math.sin(math.radians(finger1Dir)) * endDistanceInPixels)211 finger2startX = int(x + math.cos(math.radians(finger2Dir)) * startDistanceInPixels)212 finger2startY = int(y + math.sin(math.radians(finger2Dir)) * startDistanceInPixels)213 finger2endX = int(x + math.cos(math.radians(finger2Dir)) * endDistanceInPixels)214 finger2endY = int(y + math.sin(math.radians(finger2Dir)) * endDistanceInPixels)215 return self._conn.sendMtLinearGesture(216 [[(finger1startX, finger1startY), (finger1endX, finger1endY)],217 [(finger2startX, finger2startY), (finger2endX, finger2endY)]],218 duration, movePoints, sleepBeforeMove, sleepAfterMove)219 def pinchBitmap(self, bitmap, startDistance, endDistance,220 **pinchAndOirArgs):221 """222 Make the pinch gesture using the bitmap as central point.223 Parameters:224 bitmap (string):225 filename of the bitmap to be pinched.226 startDistance, endDistance (float):227 distance from both finger tips to the central point228 of the gesture, at the start and at the end of the229 gesture. Values in range [0.0, 1.0] are scaled up to230 the distance from the bitmap to screen edge. Both231 finger tips will reach an edge if distance is 1.0.232 optical image recognition arguments (optional)233 refer to help(obj.oirEngine()).234 rest of the parameters: refer to pinch documentation.235 Returns True if successful, otherwise False.236 """237 assert self._lastScreenshot != None, "Screenshot required."238 pinchArgs, rest = _takePinchArgs(pinchAndOirArgs)239 oirArgs, _ = fmbtgti._takeOirArgs(self._lastScreenshot, rest, thatsAll=True)240 oirArgs["limit"] = 1241 items = self._lastScreenshot.findItemsByBitmap(bitmap, **oirArgs)242 if len(items) == 0:243 return False244 return self.pinchItem(items[0], startDistance, endDistance, **pinchArgs)245 def pinchClose(self, (x, y) = (0.5, 0.5), startDistance=0.5, endDistance=0.1, **pinchKwArgs):246 """247 Make the close pinch gesture.248 Parameters:249 x, y (integer, optional):250 the central point of the gesture, the default is in251 the middle of the screen.252 startDistance, endDistance (float, optional):...

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