Best Python code snippet using fMBT_python
Bluetooth_GeneralTest_Pair_tests.py
Source:Bluetooth_GeneralTest_Pair_tests.py  
1# !/usr/bin/env python2"""3Copyright (C) 2018 Intel Corporation4?5Licensed under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at8?9http://www.apache.org/licenses/LICENSE-2.010?11Unless required by applicable law or agreed to in writing,12software distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions15and limitations under the License.16?17SPDX-License-Identifier: Apache-2.018"""19#######################################################################20#  @description: Pair tests scenarios for 2 devices21#  @usage:       python Bluetooth_GeneralTest_Pair_tests.py -s 0000AAAA22#                --script-args serial2=1111BBBB action_dut=Pair23#                 action_dev=Pair initiator=dev action_initiator_first=true24#                scan_timeout=60000 scan_max_attempts=1 timeout_time=6000025#  @author:      narasimha.rao.rayala@intel.com26#######################################################################27from testlib.base.base_utils import parse_args28from testlib.scripts.wireless.bluetooth import bluetooth_steps29from testlib.scripts.wireless.bluetooth import bt_utils30bluetooth_steps.LogInfo("##### INITIALIZE ######")()31#  ############# Get parameters ############32args = parse_args()33serial_dev = args["script_args"]["serial2"]34#  ### optional parameters ###35#  default values36action_dut = "Pair"37action_dev = "Pair"38initiator = "DUT"39action_initiator_first = True40scan_timeout = 6000041scan_max_attempts = 142timeout_time = 6000043#  possible values for optional parameters44action_values = ["Pair", "Cancel", "Timeout"]45initiator_values = ["dut", "dev"]46true_values = ["true", "t", "1", "yes", "y"]47script_args = args["script_args"]48#  parse optional parameters49if "action_dut" in script_args.keys():50    if script_args["action_dut"] in action_values:51        action_dut = script_args["action_dut"]52    else:53        raise Exception("Possible values for action_dut: " + str(action_values))54if "action_dev" in script_args.keys():55    if script_args["action_dev"] in action_values:56        action_dev = script_args["action_dev"]57    else:58        raise Exception("Possible values for action_dev: " + str(action_values))59if "initiator" in script_args.keys():60    if script_args["initiator"].lower() in initiator_values:61        initiator = script_args["initiator"]62    else:63        raise Exception("Possible values for initiator: " + str(initiator_values))64if "action_initiator_first" in script_args.keys():65    if script_args["action_initiator_first"].lower() in true_values:66        action_initiator_first = True67    else:68        action_initiator_first = False69if "scan_timeout" in script_args.keys():70    scan_timeout = int(script_args["scan_timeout"])71if "scan_max_attempts" in script_args.keys():72    scan_max_attempts = int(script_args["scan_max_attempts"])73if "timeout_time" in script_args.keys():74    timeout_time = int(script_args["timeout_time"])75#  Initialize versions and names76DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=args["serial"], blocking=True)()77DEV_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial_dev, blocking=True)()78DUT_NAME = bluetooth_steps.GetBtMac(serial=args["serial"], blocking=True)()79PAIRING_DEV_NAME = bluetooth_steps.GetBtMac(serial=serial_dev, blocking=True)()80try:81    #  ########### Preconditions ###############82    #  #########################################83    bluetooth_steps.LogInfo("######## SETUP ########")()84    #  DUT: turn on BT85    bluetooth_steps.StopPackage(serial=args["serial"], blocking=True)()86    bluetooth_steps.PressHome(serial=args["serial"], blocking=True)()87    bluetooth_steps.OpenBluetoothSettings(serial=args["serial"], use_intent=True, version=DUT_VERSION, blocking=True)()88    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"], state="ON", version=DUT_VERSION, blocking=True)()89    #  DEV: turn on BT90    bluetooth_steps.StopPackage(serial=serial_dev, blocking=True)()91    bluetooth_steps.PressHome(serial=serial_dev, blocking=True)()92    bluetooth_steps.OpenBluetoothSettings(serial=serial_dev, use_intent=True, version=DEV_VERSION, blocking=True)()93    bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev, state="ON", version=DEV_VERSION, blocking=True)()94    #  DUT: wait scanning, rename device and remove all paired devices95    bluetooth_steps.WaitBtScanning(serial=args["serial"], scan_timeout=scan_timeout,96                                   version=DUT_VERSION, blocking=True)()97    bluetooth_steps.BtChangeDeviceName(serial=args["serial"],98                                       name=DUT_NAME, version=DUT_VERSION, blocking=True)()99    bluetooth_steps.BtRemoveAllPairedDevices(serial=args["serial"], version=DUT_VERSION, blocking=True)()100    bluetooth_steps.CheckBtVisibility(serial=args["serial"], version=DUT_VERSION, blocking=True)()101    #  DEV: wait scanning(should be already finished), rename device and remove all paired devices102    bluetooth_steps.WaitBtScanning(serial=serial_dev, timeout_appear=0, scan_timeout=scan_timeout, version=DEV_VERSION,103                                   blocking=True)()104    bluetooth_steps.BtChangeDeviceName(serial=serial_dev,105                                       name=PAIRING_DEV_NAME, version=DEV_VERSION, blocking=True)()106    bluetooth_steps.BtRemoveAllPairedDevices(serial=serial_dev, version=DEV_VERSION, blocking=True)()107    bluetooth_steps.CheckBtVisibility(serial=serial_dev, version=DEV_VERSION, blocking=True)()108    #  ############ Actual Test ################109    #  #########################################110    bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()111    bt_utils.bt_pair_devices(serial=args["serial"], dev=serial_dev,112                             dut_name=DUT_NAME,113                             dev_name=PAIRING_DEV_NAME,114                             action_dut=action_dut,115                             action_dev=action_dev,116                             perform_action_first_on_initiator=action_initiator_first,117                             pair_request_initiator=initiator,118                             scan_timeout=scan_timeout,119                             scan_max_attempts=scan_max_attempts,120                             time_to_wait_timeout_action=timeout_time,121                             version_dut=DUT_VERSION,122                             version_dev=DEV_VERSION)123finally:124    #  ########### Postconditions ##############125    #  #########################################126    bluetooth_steps.LogInfo("####### CLEANUP #######")()127    #  DUT: stop settings and turn on BT (if not already)128    bluetooth_steps.StopPackage(serial=args["serial"], critical=False)()129    bluetooth_steps.PressHome(serial=args["serial"], critical=False)()130    bluetooth_steps.OpenBluetoothSettings(serial=args["serial"], use_intent=True, version=DUT_VERSION, critical=False)()131    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"], state="ON", version=DUT_VERSION, critical=False)()132    #  DEV: stop settings and turn on BT (if not already)133    bluetooth_steps.StopPackage(serial=serial_dev, critical=False)()134    bluetooth_steps.PressHome(serial=serial_dev, critical=False)()135    bluetooth_steps.OpenBluetoothSettings(serial=serial_dev, use_intent=True, version=DEV_VERSION, critical=False)()136    bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev, state="ON", version=DEV_VERSION, critical=False)()137    #  DUT: remove all paired devices and turn off BT138    bluetooth_steps.WaitBtScanning(serial=args["serial"], scan_timeout=scan_timeout, version=DUT_VERSION,139                                   critical=False)()140    bluetooth_steps.BtRemoveAllPairedDevices(serial=args["serial"], version=DUT_VERSION, critical=False)()141    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"], state="OFF", version=DUT_VERSION, critical=False)()142    bluetooth_steps.StopPackage(serial=args["serial"], critical=False)()143    bluetooth_steps.PressHome(serial=args["serial"], critical=False)()144    #  DEV: remove all paired devices and turn off BT145    bluetooth_steps.WaitBtScanning(serial=serial_dev, timeout_appear=0, scan_timeout=scan_timeout, version=DEV_VERSION,146                                   critical=False)()147    bluetooth_steps.BtRemoveAllPairedDevices(serial=serial_dev, version=DEV_VERSION, critical=False)()148    bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev, state="OFF", version=DEV_VERSION, critical=False)()149    bluetooth_steps.StopPackage(serial=serial_dev, critical=False)()...Bluetooth_GeneralTest_Unpair_with_a_device.py
Source:Bluetooth_GeneralTest_Unpair_with_a_device.py  
1# !/usr/bin/env python2"""3Copyright (C) 2018 Intel Corporation4?5Licensed under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at8?9http://www.apache.org/licenses/LICENSE-2.010?11Unless required by applicable law or agreed to in writing,12software distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions15and limitations under the License.16?17SPDX-License-Identifier: Apache-2.018"""19#######################################################################20#  @description: Pair request initiated by DUT , devices will Pair and21#                than UNPair22#  @author:      narasimha.rao.rayala@intel.com23#######################################################################24from testlib.base.base_utils import parse_args25from testlib.scripts.wireless.bluetooth import bluetooth_steps, bt_utils26bluetooth_steps.LogInfo("##### INITIALIZE ######")()27#  ############# Get parameters ############28args = parse_args()29script_args = args["script_args"]30#  mandatory param31if "serial2" not in script_args.keys():32    raise Exception("serial2 parameter is mandatory")33serial_dev = args["script_args"]["serial2"]34#  ### optional parameters ###35#  default values36action_dut = "Pair"37action_dev = "Pair"38initiator = "DUT"39action_initiator_first = True40scan_timeout = 6000041scan_max_attempts = 142timeout_time = 6000043#  Initialize versions and names44DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=args["serial"], blocking=True)()45DEV_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial_dev, blocking=True)()46DUT_NAME = bluetooth_steps.GetBtMac(serial=args["serial"], blocking=True)()47PAIRING_DEV_NAME = bluetooth_steps.GetBtMac(serial=serial_dev, blocking=True)()48try:49    #  ########### Preconditions ###############50    #  #########################################51    bluetooth_steps.LogInfo("######## SETUP ########")()52    #  DUT: turn on BT53    bluetooth_steps.StopPackage(serial=args["serial"], blocking=True)()54    bluetooth_steps.PressHome(serial=args["serial"], blocking=True)()55    bluetooth_steps.OpenBluetoothSettings(serial=args["serial"], use_intent=True, version=DUT_VERSION, blocking=True)()56    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"], state="ON", version=DUT_VERSION, blocking=True)()57    #  DEV: turn on BT58    bluetooth_steps.StopPackage(serial=serial_dev, blocking=True)()59    bluetooth_steps.PressHome(serial=serial_dev, blocking=True)()60    bluetooth_steps.OpenBluetoothSettings(serial=serial_dev, use_intent=True, version=DEV_VERSION, blocking=True)()61    bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev, state="ON", version=DEV_VERSION, blocking=True)()62    #  DUT: wait scan, rename device and remove all paired devices63    bluetooth_steps.WaitBtScanning(serial=args["serial"], version=DUT_VERSION, blocking=True)()64    bluetooth_steps.BtChangeDeviceName(serial=args["serial"],65                                       name=DUT_NAME, version=DUT_VERSION, blocking=True)()66    bluetooth_steps.BtRemoveAllPairedDevices(serial=args["serial"], version=DUT_VERSION, blocking=True)()67    bluetooth_steps.CheckBtVisibility(serial=args["serial"], version=DUT_VERSION, blocking=True)()68    #  DEV: wait scan (should be already finished), rename device and remove all paired devices69    bluetooth_steps.WaitBtScanning(serial=serial_dev, timeout_appear=0, version=DEV_VERSION, blocking=True)()70    bluetooth_steps.BtChangeDeviceName(serial=serial_dev,71                                       name=PAIRING_DEV_NAME, version=DEV_VERSION, blocking=True)()72    bluetooth_steps.BtRemoveAllPairedDevices(serial=serial_dev, version=DEV_VERSION, blocking=True)()73    bluetooth_steps.CheckBtVisibility(serial=serial_dev, version=DEV_VERSION, blocking=True)()74    #  pair devices75    bt_utils.bt_pair_devices(serial=args["serial"],76                             dev=serial_dev,77                             dut_name=DUT_NAME,78                             dev_name=PAIRING_DEV_NAME,79                             action_dut=action_dut,80                             action_dev=action_dev,81                             perform_action_first_on_initiator=action_initiator_first,82                             pair_request_initiator=initiator,83                             scan_timeout=scan_timeout,84                             scan_max_attempts=scan_max_attempts,85                             time_to_wait_timeout_action=timeout_time,86                             version_dut=DUT_VERSION, version_dev=DEV_VERSION)87    #  ############ Actual Test ################88    #  #########################################89    bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()90    bluetooth_steps.UnpairDevice(serial=args["serial"], device_name=PAIRING_DEV_NAME, version=DUT_VERSION)()91    bluetooth_steps.UnpairDevice(serial=serial_dev, device_name=DUT_NAME, version=DEV_VERSION)()92finally:93    #  ########### Postconditions ##############94    #  #########################################95    bluetooth_steps.LogInfo("####### CLEANUP #######")()96    #  DUT: turn on BT if not already97    bluetooth_steps.StopPackage(serial=args["serial"], critical=False)()98    bluetooth_steps.PressHome(serial=args["serial"], critical=False)()99    bluetooth_steps.OpenBluetoothSettings(serial=args["serial"], use_intent=True, version=DUT_VERSION, critical=False)()100    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"], state="ON", version=DUT_VERSION, critical=False)()101    #  DEV: turn on BT if not already102    bluetooth_steps.StopPackage(serial=serial_dev, critical=False)()103    bluetooth_steps.PressHome(serial=serial_dev, critical=False)()104    bluetooth_steps.OpenBluetoothSettings(serial=serial_dev, use_intent=True, version=DEV_VERSION, critical=False)()105    bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev, state="ON", version=DEV_VERSION, critical=False)()106    #  DUT: remove all paired devices and turn off BT107    bluetooth_steps.WaitBtScanning(serial=args["serial"], version=DUT_VERSION, critical=False)()108    bluetooth_steps.BtRemoveAllPairedDevices(serial=args["serial"], version=DUT_VERSION, critical=False)()109    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"], state="OFF", version=DUT_VERSION, critical=False)()110    bluetooth_steps.StopPackage(serial=args["serial"], critical=False)()111    bluetooth_steps.PressHome(serial=args["serial"], critical=False)()112    #  DEV: remove all paired devices and turn off BT113    bluetooth_steps.WaitBtScanning(serial=serial_dev, timeout_appear=0, version=DEV_VERSION, critical=False)()114    bluetooth_steps.BtRemoveAllPairedDevices(serial=serial_dev, version=DEV_VERSION, critical=False)()115    bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev, state="OFF", version=DEV_VERSION, critical=False)()116    bluetooth_steps.StopPackage(serial=serial_dev, critical=False)()...control-panes-hotkeys-controller.js
Source:control-panes-hotkeys-controller.js  
1module.exports =2  function($scope, gettext, $location, $rootScope, ScopedHotkeysService,3    $window) {4    $scope.remotePaneSize = '30% + 2px'5    var actions = {6      previousDevice: function() {7        // console.log('prev')8      },9      nextDevice: function() {10        // console.log('next')11      },12      deviceList: function() {13        $location.path('/devices/')14      },15      switchCharset: function() {16        $scope.control.keyPress('switch_charset')17      },18      // TODO: Refactor this19      rotateLeft: function() {20        var angle = 021        if ($scope.device && $scope.device.display) {22          angle = $scope.device.display.rotation23        }24        if (angle === 0) {25          angle = 27026        } else {27          angle -= 9028        }29        $scope.control.rotate(angle)30        if ($rootScope.standalone) {31          $window.resizeTo($window.outerHeight, $window.outerWidth)32        }33      },34      rotateRight: function() {35        var angle = 036        if ($scope.device && $scope.device.display) {37          angle = $scope.device.display.rotation38        }39        if (angle === 270) {40          angle = 041        } else {42          angle += 9043        }44        $scope.control.rotate(angle)45        if ($rootScope.standalone) {46          $window.resizeTo($window.outerHeight, $window.outerWidth)47        }48      },49      focusUrlBar: function() {50        // TODO: Switch tab and focus51        // console.log('focus')52      },53      takeScreenShot: function() {54        // TODO: Switch tab and take screenshot55        //$scope.takeScreenShot()56      },57      pressMenu: function() {58        $scope.control.menu()59      },60      pressHome: function() {61        $scope.control.home()62      },63      pressBack: function() {64        $scope.control.back()65      },66      pressAppSwitch: function() {67        $scope.control.appSwitch()68      },69      toggleDevice: function() {70        // $scope.controlScreen.show = !$scope.controlScreen.show71      },72      togglePlatform: function() {73        if ($rootScope.platform === 'web') {74          $rootScope.platform = 'native'75        } else {76          $rootScope.platform = 'web'77        }78      },79      scale: function() {80        // TODO: scale size81      }82    }83    ScopedHotkeysService($scope, [84      // ['shift+up', gettext('Previous Device'), actions.previousDevice],85      // ['shift+down', gettext('Next Device'), actions.nextDevice],86      ['command+shift+d', gettext('Go to Device List'), actions.deviceList],87      ['shift+space', gettext('Selects Next IME'), actions.switchCharset],88      ['command+left', gettext('Rotate Left'), actions.rotateLeft],89      ['command+right', gettext('Rotate Right'), actions.rotateRight],90      // ['command+1', gettext('Scale 100%'), actions.scale],91      // ['command+2', gettext('Scale 75%'), actions.scale],92      // ['command+3', gettext('Scale 50%'), actions.scale],93      // ['shift+l', gettext('Focus URL bar'), actions.focusUrlBar],94      // ['shift+s', gettext('Take Screenshot'), actions.takeScreenShot],95      ['command+shift+m', gettext('Press Menu button'), actions.pressMenu],96      ['command+shift+h', gettext('Press Home button'), actions.pressHome],97      ['command+shift+b', gettext('Press Back button'), actions.pressBack],98      // ['shift+i', gettext('Show/Hide device'), actions.toggleDevice],99      ['shift+w', gettext('Toggle Web/Native'), actions.togglePlatform, false]100    ])...Bluetooth_GeneralTest_Modify_DUT_Bluetooth_Name_No_Character_UI.py
Source:Bluetooth_GeneralTest_Modify_DUT_Bluetooth_Name_No_Character_UI.py  
1# !/usr/bin/env python2"""3Copyright (C) 2018 Intel Corporation4?5Licensed under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at8?9http://www.apache.org/licenses/LICENSE-2.010?11Unless required by applicable law or agreed to in writing,12software distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions15and limitations under the License.16?17SPDX-License-Identifier: Apache-2.018"""19#######################################################################20#  @description: Modify the default Bluetooth name of DUT by no character21#  @author:      narasimha.rao.rayala@intel.com22#######################################################################23from testlib.base.base_utils import parse_args24from testlib.scripts.wireless.bluetooth import bluetooth_steps25bluetooth_steps.LogInfo("##### INITIALIZE ######")()26#  ############# Get parameters ############27args = parse_args()28#  Initialize version29DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=args["serial"], blocking=True)()30try:31    #  ########### Preconditions ###############32    #  #########################################33    bluetooth_steps.LogInfo("######## SETUP ########")()34    bluetooth_steps.StopPackage(serial=args["serial"], blocking=True)()35    bluetooth_steps.PressHome(serial=args["serial"], blocking=True)()36    #  ############ Actual Test ################37    #  #########################################38    bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()39    bluetooth_steps.OpenBluetoothSettings(serial=args["serial"], use_intent=True, version=DUT_VERSION)()40    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"], state="ON", version=DUT_VERSION)()41    bluetooth_steps.WaitBtScanning(serial=args["serial"], version=DUT_VERSION)()42    bluetooth_steps.BtChangeDeviceName(serial=args["serial"], name="", version=DUT_VERSION)()43finally:44    #  ########### Postconditions ##############45    #  #########################################46    bluetooth_steps.LogInfo("####### CLEANUP #######")()47    bluetooth_steps.StopPackage(serial=args["serial"], critical=False)()48    bluetooth_steps.PressHome(serial=args["serial"], critical=False)()49    bluetooth_steps.OpenBluetoothSettings(serial=args["serial"], use_intent=True, version=DUT_VERSION, critical=False)()50    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"], state="OFF", version=DUT_VERSION, critical=False)()51    bluetooth_steps.StopPackage(serial=args["serial"], critical=False)()...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
