str(action_values)) if "initiator" in args.keys(): if args["initiator"].lower() in initiator_values: initiator = args["initiator"] else: raise Exception("Possible values for initiator: " + str(initiator_values)) if "iteration" in args.keys(): if args["iteration"] in iteration_values: iteration = args["iteration"] else: raise Exception("Possible values for iteration_values: " + str(iteration_values)) # Initialize version DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial, blocking=True)() DEV_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial_dev, blocking=True)() DUT_NAME = bluetooth_steps.GetBtMac(serial=serial, blocking=True)() PAIRING_DEV_NAME = bluetooth_steps.GetBtMac(serial=serial_dev, blocking=True)() try: # ########### Preconditions ############### # ######################################### bluetooth_steps.LogInfo("######## SETUP ########")() # DUT: turn on BT bluetooth_steps.StopPackage(serial=serial, blocking=True)() bluetooth_steps.PressHome(serial=serial, blocking=True)() bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True,
def pair_a2dp_device(serial, a2dp_device_name, event, timeout=10000, scan_max_attempts=2, scan_timeout=60000, q=None, **kwargs): result = [] # Initialize versions and names DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial, blocking=True)() try: # ########### Preconditions ############### # ######################################### bluetooth_steps.LogInfo("######## SETUP ########")() # DUT: turn on BT bluetooth_steps.StopPackage(serial=serial, blocking=True)() bluetooth_steps.PressHome(serial=serial, blocking=True)() bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True, version=DUT_VERSION, blocking=True)() bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON", version=DUT_VERSION, blocking=True)() # DUT: wait scanning, rename device and remove all paired devices bluetooth_steps.WaitBtScanning(serial=serial, scan_timeout=scan_timeout, version=DUT_VERSION, blocking=True)() bluetooth_steps.BtRemoveAllPairedDevices(serial=serial, version=DUT_VERSION, blocking=True)() bluetooth_steps.CheckBtVisibility(serial=serial, version=DUT_VERSION, blocking=True)() # ############ Actual Test ################ # ######################################### bluetooth_steps.LogInfo("##### ACTUAL TEST #####")() bluetooth_steps.PairDevice(serial=serial, dev_to_pair_name=a2dp_device_name, scan_timeout=scan_timeout, timeout=timeout, scan_max_attempts=scan_max_attempts)() event.set() result.append(True) except: event.set() log.error('ConnectA2dpDevice: Unexpected Error') log.error(traceback.format_exc()) result.append(False) finally: if total_actions > 1: event.wait(CONDITION_EVENT_TIMEOUT) event.clear() # ########### Postconditions ############## # ######################################### bluetooth_steps.LogInfo("####### CLEANUP #######")() # DUT: stop settings and turn on BT (if not already) bluetooth_steps.StopPackage(serial=serial, critical=False)() bluetooth_steps.PressHome(serial=serial, critical=False)() bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True, version=DUT_VERSION, critical=False)() bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON", version=DUT_VERSION, critical=False)() # DUT: remove all paired devices and turn off BT bluetooth_steps.WaitBtScanning(serial=serial, scan_timeout=scan_timeout, version=DUT_VERSION, critical=False)() bluetooth_steps.BtRemoveAllPairedDevices(serial=serial, version=DUT_VERSION, critical=False)() bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="OFF", version=DUT_VERSION, critical=False)() bluetooth_steps.StopPackage(serial=serial, critical=False)() bluetooth_steps.PressHome(serial=serial, critical=False)() if False in result: action_result = ["A2dpBtConnect", 'Fail'] else: action_result = ["A2dpBtDevice", 'Pass'] return action_result if q is None else q.put(action_result)
def opp_send_file(serial, serial_dev, condition, event, file_path="/storage/emulated/0/acs_files", file_name="10MB.txt", iteration=1, q=None): result = [] try: file_full_path = file_path + '/' + file_name # Initialize versions and names (we only need dev name) DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial, blocking=True)() DEV_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial_dev, blocking=True)() PAIRING_DUT_NAME = bluetooth_steps.GetBtMac(serial=serial, blocking=True)() PAIRING_DEV_NAME = bluetooth_steps.GetBtMac(serial=serial_dev, blocking=True)() # taking only the name and removing the extensions FILE_NAME = file_name.split(".")[0] bluetooth_steps.LogInfo("######## SETUP ########")() for _ in range(0, iteration): if initiator == "dev" and _ == 0: serial, serial_dev = serial_dev, serial DUT_VERSION, DEV_VERSION = DEV_VERSION, DUT_VERSION PAIRING_DUT_NAME, PAIRING_DEV_NAME = PAIRING_DEV_NAME, \ PAIRING_DUT_NAME if iteration > 1: log.info("Opp transfer: Iteration #{}".format(_ + 1)) if priority == 'bt' and _ == 0: # print e.is_set() # print 'bt 1st event wait' event.wait(CONDITION_EVENT_TIMEOUT) event.clear() elif not priority == "toggle": # print 'bt 1st event set' event.set() with condition: # print 'Before wifi' if priority == 'wifi' and _ == 0: condition.wait(CONDITION_EVENT_TIMEOUT) # print 'Started after notified from wifi' # DUT: clear all notifications etc bluetooth_steps.StopPackage(serial=serial, blocking=True)() bluetooth_steps.PressHome(serial=serial, blocking=True)() bluetooth_steps.ClearAllNotifications(serial=serial, version=DUT_VERSION, blocking=True)() bluetooth_steps.BtOppDismissEventualIncoming(serial=serial, version=DUT_VERSION, blocking=True)() bluetooth_steps.ClearRecentApps(serial=serial, version=DUT_VERSION, blocking=True)() # DEV: clear all notifications/opp files etc bluetooth_steps.StopPackage(serial=serial_dev, blocking=True)() bluetooth_steps.PressHome(serial=serial_dev, blocking=True)() bluetooth_steps.ClearAllNotifications(serial=serial_dev, version=DEV_VERSION, blocking=True)() bluetooth_steps.BtOppDismissEventualIncoming(serial=serial_dev, version=DEV_VERSION, blocking=True)() bluetooth_steps.ClearPath(serial=serial_dev, blocking=True)() if _ == 0: # DUT: turn on bt # already turned on during TC setup phase bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True, version=DUT_VERSION, blocking=True)() bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON", version=DUT_VERSION, blocking=True)() # DEV: turn on bt # already turned on during TC setup phase bluetooth_steps.OpenBluetoothSettings(serial=serial_dev, use_intent=True, version=DEV_VERSION, blocking=True)() bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev, state="ON", version=DEV_VERSION, blocking=True)() # DUT: wait scan and remove paired devices bluetooth_steps.WaitBtScanning(serial=serial, version=DUT_VERSION, blocking=True)() bluetooth_steps.BtChangeDeviceName(serial=serial, name=PAIRING_DUT_NAME, version=DUT_VERSION, blocking=True)() bluetooth_steps.BtRemoveAllPairedDevices(serial=serial, version=DUT_VERSION, blocking=True)() bluetooth_steps.CheckBtVisibility(serial=serial, version=DUT_VERSION, blocking=True)() # DEV: wait scan (should be already finished), rename and # remove paired devices bluetooth_steps.WaitBtScanning(serial=serial_dev, timeout_appear=0, version=DEV_VERSION, blocking=True)() bluetooth_steps.BtChangeDeviceName(serial=serial_dev, name=PAIRING_DEV_NAME, version=DEV_VERSION, blocking=True)() bluetooth_steps.BtRemoveAllPairedDevices(serial=serial_dev, version=DEV_VERSION, blocking=True)() bluetooth_steps.CheckBtVisibility(serial=serial_dev, version=DEV_VERSION, blocking=True)() if priority == 'bt' and _ == 0: condition.notify() if _ == 0 and bt_pair_device: if not pair_device(serial, serial_dev, PAIRING_DUT_NAME, PAIRING_DEV_NAME, DUT_VERSION, DEV_VERSION): raise if priority == 'bt' and _ == 0: # print e.is_set() # print 'bt 2nd event wait' event.wait(CONDITION_EVENT_TIMEOUT) event.clear() elif not priority == 'toggle': # print 'bt 2nd event set' event.set() with condition: if priority == 'wifi' and _ == 0: condition.wait(CONDITION_EVENT_TIMEOUT) bt_opp_receive_obj = None bluetooth_steps.BrowseFileInSettingsStorage(serial=serial, file_full_path=file_full_path)() bluetooth_steps.BtOppShareFile(serial=serial, server_dut=str(PAIRING_DEV_NAME), bt_already_opened=True, version=DUT_VERSION, blocking=True)() bt_opp_receive_obj = bluetooth_steps.BtOppReceiveFile( serial=serial_dev, action='Accept', filename_starting_string=FILE_NAME, version=DEV_VERSION, check_file_received=False) bt_opp_receive_obj() if priority == 'bt' and _ == 0: condition.notify() # this condition will notify the 'toggle_wifi' to proceed to # toggle state if priority == 'toggle': event.set() # This waits for Wifi to start downloas as both collides when # start together if initiator == "dev" and priority == "bt" and _ == 0: event.wait(CONDITION_EVENT_TIMEOUT) event.clear() # Below verification of OPP received file is separated from # above BtOppReceiveFile because parallelly when file is receiving # toggling WIFI should happen try: # open notification menu and click on incoming file notification if not bluetooth_steps.OpenNotificationsMenu(serial=serial_dev, version=DEV_VERSION, critical=False, no_log=True)(): raise Exception("Notifications menu not opened") if not bluetooth_steps.BtCheckNotificationAppear(serial=serial_dev, text_contains="Bluetooth share: Receiving", click_on_notification=True, time_to_appear=VIEW_TIMEOUT, version=DEV_VERSION, critical=False, no_log=True)(): if not bluetooth_steps.BtCheckNotificationAppear(serial=serial_dev, text_contains="Bluetooth share: Received", click_on_notification=True, time_to_appear=VIEW_TIMEOUT, version=DEV_VERSION, critical=False, no_log=True)(): raise Exception("Receiving file notification click failed") else: if not bt_opp_receive_obj.uidevice( textContains=FILE_NAME).wait.exists(timeout=VIEW_TIMEOUT): raise Exception("Receiving file not found in " "Inbound transfers window") if not bt_opp_receive_obj.uidevice( textContains="Received complete"): raise Exception("File not received completely") bt_opp_receive_obj.uidevice.press.back() else: if not bt_opp_receive_obj.uidevice( resourceId="android:id/alertTitle", text="File transfer").wait.exists(timeout=VIEW_TIMEOUT): raise Exception("File transfer progress window not " "shown after click on receiving file notification") # check the filename in the window (if not empty) if FILE_NAME != "": filename_obj = bt_opp_receive_obj.uidevice( textContains="File:") if not filename_obj.wait.exists(timeout=VIEW_TIMEOUT): raise Exception( "Receiving File Name not found in the file " "transfer window") filename_text = str(filename_obj.text) if FILE_NAME not in filename_text: raise Exception("Not expected string contained in the " "file transfer window, exp " + str( FILE_NAME) + " but found " + filename_text) # wait till the file is received if not bt_opp_receive_obj.uidevice( text="File received").wait.exists( timeout=TRANSFER_TIMEOUT): if bt_opp_receive_obj.uidevice(textContains="OK", className="android.widget.Button").exists: bt_opp_receive_obj.uidevice.press.back() #bt_opp_receive_obj.uidevice(textContains="OK", # # className="android.widget.Button").click.wait() raise Exception("Timeout reached, file transfer not finished") # return to the previous window bt_opp_receive_obj.uidevice.press.back() if not bt_opp_receive_obj.uidevice( resourceId="android:id/alertTitle", text="File transfer").wait.gone(timeout=VIEW_TIMEOUT): #if bt_opp_receive_obj.uidevice(textContains="OK", # className="android.widget.Button").exists: # bt_opp_receive_obj.uidevice.press.back() #bt_opp_receive_obj.uidevice(textContains="OK", # className="android.widget.Button").click() # this will help avoid the "File transfer" window # appear in next opp transfer bt_opp_receive_obj.uidevice.press.back() raise Exception("File transfer progress window not closed") log.info("File received successfully") result.append(True) except Exception, e: log.error(e.message) log.error(traceback.format_exc()) log.error("Exception raised, File not received successfully") result.append(False) except: log.error('OppTransferFile: Unexpected Error') log.error(traceback.format_exc()) result.append(False) finally: bluetooth_steps.LogInfo("####### CLEANUP #######")() # DUT: close inbounds transfers, turn off bt, clear all opp notifications/files bluetooth_steps.DismissTransferList(serial=serial, version=DUT_VERSION, critical=False)() bluetooth_steps.StopPackage(serial=serial, critical=False)() bluetooth_steps.ClearAllNotifications(serial=serial, version=DUT_VERSION, critical=False)() bluetooth_steps.PressHome(serial=serial, critical=False)() # DEV: turn off bt, clear all opp notifications/files bluetooth_steps.ClearAllNotifications(serial=serial_dev, version=DEV_VERSION, critical=False)() bluetooth_steps.StopPackage(serial=serial_dev, critical=False)() bluetooth_steps.PressHome(serial=serial_dev, critical=False)() if False in result: q.put(['OppTransferFile', 'Fail', result]) else: q.put(['OppTransferFile', 'Pass']) # Teardown log.info("BT Opp transfer completed")
####################################################################### # @description: Modify the default Bluetooth name of DUT by no character # @author: [email protected] ####################################################################### from testlib.base.base_utils import parse_args from testlib.scripts.wireless.bluetooth import bluetooth_steps bluetooth_steps.LogInfo("##### INITIALIZE ######")() # ############# Get parameters ############ args = parse_args() # Initialize version DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=args["serial"], blocking=True)() try: # ########### Preconditions ############### # ######################################### bluetooth_steps.LogInfo("######## SETUP ########")() bluetooth_steps.StopPackage(serial=args["serial"], blocking=True)() bluetooth_steps.PressHome(serial=args["serial"], blocking=True)() # ############ Actual Test ################ # ######################################### bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()