How to use listSerialNumbers method in fMBT

Best Python code snippet using fMBT_python

fmbtandroid.py

Source:fmbtandroid.py Github

copy

Full Screen

...260 "VOLUME_UP", "W", "WINDOW", "X", "Y", "YEN", "Z",261 "ZENKAKU_HANKAKU", "ZOOM_IN", "ZOOM_OUT"))262sortItems = fmbtgti.sortItems263_g_listDevicesCommand = [_g_adbExecutable, "devices"]264def listSerialNumbers(adbPort=None):265 """266 Returns list of serial numbers of Android devices.267 Equivalent for "adb devices".268 """269 if adbPort:270 command = [_g_adbExecutable, "-P", str(adbPort), "devices"]271 else:272 command = _g_listDevicesCommand273 status, output, err = _run(command, expectedExitStatus = [0, 127])274 if status == 127:275 raise FMBTAndroidError('adb not found in PATH. Check your Android SDK installation.')276 outputLines = [l.strip() for l in output.splitlines()]277 try: deviceLines = outputLines[outputLines.index("List of devices attached")+1:]278 except: deviceLines = []279 deviceLines = [l for l in deviceLines280 if l.strip() != "" and not l.startswith("*")]281 potentialDevices = [line.split()[0] for line in deviceLines]282 return potentialDevices283class Device(fmbtgti.GUITestInterface):284 """285 The Device class provides286 - keywords as its methods287 - device properties from device's INI file288 - view() returns the most recently refreshed View, that contains289 items parsed from window dump.290 - screenshot() returns the most recently refreshed Screenshot,291 bitmaps can be searched from this.292 """293 _PARSE_VIEW_RETRY_LIMIT = 10294 def __init__(self, deviceName=None, iniFile=None, connect=True,295 monkeyOptions=[], adbPort=None, adbForwardPort=None,296 uiautomatorDump=False,297 **kwargs):298 """299 Connect to given device, or the first not-connected Android300 device in the "adb devices" list, if nothing is defined.301 Parameters:302 deviceName (string, optional):303 If deviceName is a device serial number (an item in304 the left most column in "adb devices"), connect to305 that device. Device information is read from306 $FMBTANDROIDHOME/etc/SERIALNUMBER.ini, if it exists.307 If deviceName is a nick name, device information is308 looked for from $FMBTANDROIDHOME/etc/deviceName.ini,309 and the connection is established to the device with310 the serial number given in the ini file.311 The default is None. The first disconnected device312 in the "adb devices" list is connected to. Device313 information is read from314 $FMBTANDROIDHOME/etc/SERIALNUMBER.ini, if it exists.315 iniFile (file object, optional):316 A file object that contains device information317 ini. Connect to the device with a serial number318 given in this file. The default is None.319 connect (boolean, optional):320 Immediately establish connection to the device. The321 default is True. Example on using without connection:322 d = fmbtandroid.Device(connect=False)323 d.refreshView("screenshots/20141127-emulator-5554.view")324 print d.view().dumpTree()325 adbPort (integer, optional):326 Find and connect to devices via the ADB server that327 listens to adbPort. If not given, adb is executed328 without the port parameter (-P).329 adbForwardPort (integer, optional):330 Connect to services needed on the device via331 forwarded ports starting from adbForwardPort. The332 default is FMBTANDROID_ADB_FORWARD_PORT, or333 random ports if undefined.334 monkeyOptions (list of strings, optional):335 Extra command line options to be passed to Android336 monkey on the device.337 rotateScreenshot (integer or "auto", optional)338 rotate new screenshots by rotateScreenshot degrees.339 Example: rotateScreenshot=-90. The default is "auto".340 If "auto" is given, rotate automatically to compensate341 current display rotation.342 uiautomatorDump (boolean, optional)343 If True, use "uiautomator dump" as refreshView() backend.344 Otherwise window service dump is used.345 Set uiautomatorDump=True to test devices that are not rooted.346 The default is False.347 """348 if kwargs.get("rotateScreenshot", "auto") == "auto":349 # the base class does not understand "auto" rotate screenshot350 if "rotateScreenshot" in kwargs:351 del kwargs["rotateScreenshot"]352 self._autoRotateScreenshot = True353 else:354 self._autoRotateScreenshot = False355 adbPortArgs = {}356 if adbPort != None:357 adbPortArgs["adbPort"] = adbPort358 if adbForwardPort != None:359 adbPortArgs["adbForwardPort"] = adbForwardPort360 fmbtgti.GUITestInterface.__init__(self, **kwargs)361 self._fmbtAndroidHomeDir = os.getenv("FMBTANDROIDHOME", os.getcwd())362 self._lastView = None363 self._supportsView = None364 self._monkeyOptions = monkeyOptions365 self._lastConnectionSettings = {}366 self._uiautomatorDump = uiautomatorDump367 self._conf = Ini()368 self._loadDeviceAndTestINIs(self._fmbtAndroidHomeDir, deviceName, iniFile)369 if deviceName == None:370 deviceName = self._conf.value("general", "serial", "")371 if connect == False and deviceName == "":372 deviceName = "nodevice"373 self.serialNumber = self._conf.value("general", "serial", deviceName)374 self.setConnection(None)375 elif deviceName == "":376 # Connect to an unspecified device.377 # Go through devices in "adb devices".378 potentialDevices = listSerialNumbers(adbPort=adbPort)379 if potentialDevices == []:380 raise AndroidDeviceNotFound('No devices found with "%s"' % (_g_listDevicesCommand,))381 errorMessages = []382 for deviceName in potentialDevices:383 try:384 self.setConnection(_AndroidDeviceConnection(385 deviceName, monkeyOptions=self._monkeyOptions, **adbPortArgs))386 self._conf.set("general", "serial", self.serialNumber)387 break388 except AndroidConnectionError, e:389 errorMessages.append(str(e))390 continue391 else:392 raise AndroidConnectionError("Could not connect to device(s): %s. (%s)" % (...

Full Screen

Full Screen

bot.py

Source:bot.py Github

copy

Full Screen

...25 26 if _userText == "!cs":27 self.createSerialNumber(event)28 elif _userText == "!ls":29 self.listSerialNumbers(event)30 elif _userText =="!play":31 self.playGame(event)32 elif _userText.startswith("!start"):33 serial_number = tools.checkSerialInput(_userText)34 if serial_number is not None:35 self.openGame(event,serial_number)36 else:37 self.linebotapi.reply_message(38 event.reply_token,39 TextSendMessage(text="序號輸入格式有問題")40 )41 elif _userText =="!圖文":42 self.linebotapi.reply_message(43 event.reply_token,44 FlexSendMessage("圖文選單",contents=FlexMessageReply.SimpleFlexMessage())45 )46 elif _userText =="!快速":47 self.linebotapi.reply_message(48 event.reply_token,49 TextSendMessage(text="快速回覆 需使用手機",quick_reply=QuickReply(items=[50 QuickReplyButton(action=MessageAction(label="按我測試",text="按了快速回覆1")),51 QuickReplyButton(action=MessageAction(label="按我測試2",text="按了快速回覆2")),52 ]))53 )54 def createSerialNumber(self,event):55 print("產生新序號")56 _life_time_seconds = 3600 #序號有效時間57 _randomSerial = tools.random_str(5)58 current_time = datetime.now()59 final_time = current_time+timedelta(seconds=_life_time_seconds)60 final_time = (final_time.strftime("%m/%d/%Y %H:%M:%S"))61 _toDatabase = self.database.addSerialNumber(_randomSerial,final_time)62 if _toDatabase is True:63 self.linebotapi.reply_message(64 event.reply_token,65 TextSendMessage(text="成功產生序號:"+_randomSerial+"\n到期時間:"+final_time)66 )67 else:68 self.linebotapi.reply_message(69 event.reply_token,70 TextSendMessage(text="產生序號發生問題 請聯絡管理員")71 )72 73 74 def listSerialNumbers(self,event):75 print("列出序號&過期時間")76 _all_serial = self.database.getSerialNumberList()77 _reply = "序號資料:\n"78 for serial in _all_serial:79 _serialinfo ="序號:"+serial["serail_number"]+"\n"+"過期時間"+serial["expiration_time"]+"\n"80 #過期的序號設置false符號81 if self.checkSerialNumberIsLegal(serial["serail_number"]) is False:82 self.database.SetSerialNumberValid(serial["serail_number"],False)83 else:84 _reply+=_serialinfo85 self.linebotapi.reply_message(86 event.reply_token,87 TextSendMessage(text=_reply)88 )...

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