diff --git a/src/commonMethods/commonFunctions.js b/src/commonMethods/commonFunctions.js index 0a2c915..762fd8a 100644 --- a/src/commonMethods/commonFunctions.js +++ b/src/commonMethods/commonFunctions.js @@ -495,3 +495,45 @@ export const stopWPEFramework = function() { stopProcess('WPEFramework') return true } + +/** + * This function is used to scan Info of Bluetooth Control Plugin + * @param type , timeout + * @returns {Promise>} + */ +export const scanDevices = function(type, timeout) { + return this.$thunder.api.BluetoothControl.scan(type, timeout) + .then(result => result) + .catch(err => err) +} +/** + * This function is used to get available Bluetooth devices + * @returns {Promise>} + */ +export const getBluetoothDevices = function() { + return this.$thunder.api.BluetoothControl.devices() + .then(result => result) + .catch(err => err) +} + +/** + * This function is used to pair with the available Bluetooth devices + * @param address + * @returns {Promise>} + */ +export const pairBTDevice = function(address) { + return this.$thunder.api.BluetoothControl.pair(address) + .then(result => result) + .catch(err => err) +} + +/** + * This function is used to disconnect with the available Bluetooth devices + * @param address + * @returns {Promise>} + */ +export const unpairBTDevice = function(address) { + return this.$thunder.api.BluetoothControl.unpair(address) + .then(result => result) + .catch(err => err) +} diff --git a/src/commonMethods/constants.js b/src/commonMethods/constants.js index 8e1e460..ce20614 100755 --- a/src/commonMethods/constants.js +++ b/src/commonMethods/constants.js @@ -5,6 +5,7 @@ export default { monitorPlugin: 'Monitor', controllerPlugin: 'Controller', webKitBrowserPlugin: 'WebKitBrowser', + bluetoothControlPlugin: 'BluetoothControl', webKitImplementation: 'WebKitImplementation', deviceInfo: 'DeviceInfo', youTubePlugin: 'Cobalt', @@ -19,6 +20,7 @@ export default { provisioningPlugin: 'Provisioning', WPEProcess: 'WPEProcess', remoteControlPlugin: 'RemoteControl', + invalidAddress: 'invalidstring', //Plugin states activate: 'activate', @@ -29,4 +31,3 @@ export default { blankUrl: 'about:blank', host: config.thunder.host, } - diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js new file mode 100644 index 0000000..3a3157a --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js @@ -0,0 +1,68 @@ +import { pairBTDevice } from '../../commonMethods/commonFunctions' + +import baseTest from './BluetoothControl_Scan_001.test' + +let btdevicelist +let scanCompleteListener +let deviceStateChangeListener + +export default { + title: 'Bluetooth Control - Pair 001', + description: 'Check the Pair Functionality of Bluetooth Control Module', + setup() { + scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => { + this.$data.write('scancompleted', 'scancompleted') + }) + deviceStateChangeListener = this.$thunder.api.BluetoothControl.on('devicestatechange', data => { + this.$data.write('address', data.address) + this.$data.write('state', data.state) + }) + }, + teardown() { + scanCompleteListener.dispose() + deviceStateChangeListener.dispose() + }, + steps: [ + baseTest, + { + description: 'Pair with the device', + sleep: 5, + test() { + //TODO - Prompt the user to select the device that need to be paired + // and input(instead of btdevicelist[0]) that to the 'pairBTDevice' + return pairBTDevice.call(this, btdevicelist[0]) + }, + validate(res) { + if (res == null) { + return true + } else { + this.$log('Pairing not started') + return false + } + }, + }, + { + description: 'Check whether pairing is success', + sleep: 60, + test() { + //TODO - Prompt the user to press on the button in the Bluetooth Device to pair with 1 minute timeout + return new Promise((resolve, reject) => { + let attempts = 0 + const interval = setInterval(() => { + attempts++ + if ( + this.$data.read('address') === btdevicelist[0] && //TODO - btdevicelist[0] need to be replaced with the user input given in previous step + this.$data.read('state') === 'Paired' + ) { + clearInterval(interval) + resolve() + } else if (attempts > 10) { + clearInterval(interval) + reject('Pairing does not happen') + } + }, 1000) + }) + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Pair_002.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Pair_002.test.js new file mode 100644 index 0000000..e1838c5 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Pair_002.test.js @@ -0,0 +1,36 @@ +import { pluginDeactivate, pluginActivate, pairBTDevice } from '../../commonMethods/commonFunctions' +import constants from '../../commonMethods/constants' + +export default { + title: 'Bluetooth Control - Pair 002', + description: 'Check the Pair Functionality of Bluetooth Control Module with Invalid MAC', + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Pair with the device', + sleep: 5, + test() { + return pairBTDevice.call(this, constants.invalidAddress) + }, + validate(res) { + if (res.code === 22 && res.message === 'ERROR_UNKNOWN_KEY') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Pair_003.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Pair_003.test.js new file mode 100644 index 0000000..b4c0fd2 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Pair_003.test.js @@ -0,0 +1,44 @@ +import { pairBTDevice } from '../../commonMethods/commonFunctions' + +import baseTest from './BluetoothControl_Pair_001.test' + +let btdevicelist +let scanCompleteListener +let deviceStateChangeListener + +export default { + title: 'Bluetooth Control - Pair 003', + description: + 'Check the Pair Functionality of Bluetooth Control Module with the device which is already paired', + setup() { + scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => { + this.$data.write('scancompleted', 'scancompleted') + }) + deviceStateChangeListener = this.$thunder.api.BluetoothControl.on('devicestatechange', data => { + this.$data.write('address', data.address) + this.$data.write('state', data.state) + }) + }, + teardown() { + scanCompleteListener.dispose() + deviceStateChangeListener.dispose() + }, + steps: [ + baseTest, + { + description: 'Pair with the device', + sleep: 5, + test() { + return pairBTDevice.call(this, btdevicelist[0]) //TODO - btdevicelist[0] need to be replaced with the user input given in previous testcase + }, + validate(res) { + if (res.code === 9 && res.message === 'ERROR_ALREADY_CONNECTED') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js new file mode 100644 index 0000000..f7c6eba --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js @@ -0,0 +1,96 @@ +import { + pluginDeactivate, + pluginActivate, + scanDevices, + getBluetoothDevices, +} from '../../commonMethods/commonFunctions' +import constants from '../../commonMethods/constants' + +let scanCompleteListener + +export default { + title: 'Bluetooth Control - Scan 001', + description: 'Check the Scan Functionality of Bluetooth Control Module for Low Energy devices', + context: { + deviceType: 'Low Energy', + timeOut: 10, + }, + setup() { + scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => { + this.$data.write('scancompleted', 'scancompleted') + }) + }, + teardown() { + scanCompleteListener.dispose() + }, + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Invoke Scan', + sleep: 5, + test() { + this.$log('devicetype is ', this.$context.read('deviceType'), this.$context.read('timeOut')) + return scanDevices.call( + this, + this.$context.read('deviceType'), + this.$context.read('timeOut') + ) + }, + validate(res) { + if (res == null) { + return true + } else { + this.$log('Scan does not start') + return false + } + }, + }, + { + description: 'Check whether scanning is success', + sleep: 5, + test() { + return new Promise((resolve, reject) => { + let attempts = 0 + const interval = setInterval(() => { + attempts++ + if (this.$data.read('scancompleted') === 'scancompleted') { + clearInterval(interval) + resolve() + } else if (attempts > 10) { + clearInterval(interval) + reject('Scanning not completed') + } + }, 1000) + }) + }, + }, + { + description: 'Get scan results', + sleep: 10, + test() { + return getBluetoothDevices.call(this) + }, + validate(result) { + //TODO - Prompt the user with result and ask him to confirm the Low Energy devices available in the list. + // If user says yes pass the test case. + if (result === undefined || result.length === 0) { + this.$log('Result does not have device list') + return false + } else { + return true + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js new file mode 100644 index 0000000..f4fa2b2 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js @@ -0,0 +1,49 @@ +import { pluginDeactivate, pluginActivate, scanDevices } from '../../commonMethods/commonFunctions' +import constants from '../../commonMethods/constants' + +export default { + title: 'Bluetooth Control - Scan 002', + description: 'Check error message when scanning is performed while previous scan is in progress', + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Invoke Scan', + test() { + return scanDevices.call(this, 'LowEnergy', 10) + }, + validate(res) { + if (res == null) { + return true + } else { + this.$log('Scan does not start') + return false + } + }, + }, + { + description: 'Invoke Scan', + test() { + return scanDevices.call(this, 'LowEnergy', 10) + }, + validate(res) { + if (res.code == 12 && res.message == 'ERROR_INPROGRESS') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js new file mode 100644 index 0000000..649a163 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js @@ -0,0 +1,17 @@ +import baseTest from './BluetoothControl_Scan_001.test' + +export default { + ...baseTest, + ...{ + context: { + deviceType: 'Classic', + timeOut: 10, + }, + + title: 'Bluetooth Control - Scan 003', + description: 'Check the Scan Functionality of Bluetooth Control Module for Classic devices', + steps: baseTest.steps.map((step, index) => { + return step + }), + }, +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js new file mode 100644 index 0000000..c4908e3 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js @@ -0,0 +1,16 @@ +import baseTest from './BluetoothControl_Scan_001.test' + +export default { + ...baseTest, + ...{ + context: { + deviceType: 'Low Energy', + timeOut: 20, + }, + title: 'Bluetooth Control - Scan 004', + description: 'Check the Scan Functionality of Bluetooth Control Module with modified timeout', + steps: baseTest.steps.map((step, index) => { + return step + }), + }, +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Unpair_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Unpair_001.test.js new file mode 100644 index 0000000..41be998 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Unpair_001.test.js @@ -0,0 +1,66 @@ +import { unpairBTDevice } from '../../commonMethods/commonFunctions' +import baseTest from './BluetoothControl_Pair_001.test' + +let btdevicelist +let scanCompleteListener +let deviceStateChangeListener + +export default { + title: 'Bluetooth Control - Unpair 001', + description: 'Check the Unpair Functionality of Bluetooth Control Module', + setup() { + scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => { + this.$data.write('scancompleted', 'scancompleted') + }) + deviceStateChangeListener = this.$thunder.api.BluetoothControl.on('devicestatechange', data => { + this.$data.write('address', data.address) + this.$data.write('state', data.state) + }) + }, + teardown() { + scanCompleteListener.dispose() + deviceStateChangeListener.dispose() + }, + steps: [ + baseTest, + { + description: 'Unpair the device', + sleep: 5, + test() { + //TODO - Prompt the user to select the device that need to be paired + // and input(instead of btdevicelist[0]) that to the 'unpairBTDevice' + return unpairBTDevice.call(this, btdevicelist[0]) + }, + validate(res) { + if (res == null) { + return true + } else { + this.$log('Unpairing doesnt happen') + return false + } + }, + }, + { + description: 'Check whether unpairing is success', + sleep: 5, + test() { + return new Promise((resolve, reject) => { + let attempts = 0 + const interval = setInterval(() => { + attempts++ + if ( + this.$data.read('address') === btdevicelist[0] && //TODO - btdevicelist[0] need to be replaced with the user input given in previous step + this.$data.read('state') === 'Unpaired' + ) { + clearInterval(interval) + resolve() + } else if (attempts > 10) { + clearInterval(interval) + reject('Unpairing does not happen') + } + }, 1000) + }) + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Unpair_002.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Unpair_002.test.js new file mode 100644 index 0000000..c4c7b42 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Unpair_002.test.js @@ -0,0 +1,41 @@ +import { + pluginDeactivate, + pluginActivate, + unpairBTDevice, +} from '../../commonMethods/commonFunctions' + +import constants from '../../commonMethods/constants' + +export default { + title: 'Bluetooth Control Unpair 002', + description: 'Check the Unpair Functionality of Bluetooth Control Module with Invalid MAC', + steps: [ + { + description: 'Check if Bluetooth Control Plugin is stopped correctly', + test: pluginDeactivate, + params: constants.bluetoothControlPlugin, + assert: 'deactivated', + }, + { + description: 'Check if Bluetooth Control Plugin is started correctly', + test: pluginActivate, + params: constants.bluetoothControlPlugin, + assert: 'activated', + }, + { + description: 'Unpair with the device with invalid MAC and check error message', + sleep: 5, + test() { + return unpairBTDevice.call(this, constants.invalidAddress) + }, + validate(res) { + if (res.code === 22 && res.message === 'ERROR_UNKNOWN_KEY') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +} diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Unpair_003.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Unpair_003.test.js new file mode 100644 index 0000000..437ca82 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Unpair_003.test.js @@ -0,0 +1,44 @@ +import { unpairBTDevice } from '../../commonMethods/commonFunctions' + +import baseTest from './BluetoothControl_Unpair_001.test' + +let btdevicelist +let scanCompleteListener +let deviceStateChangeListener + +export default { + title: 'Bluetooth Control - Unpair 003', + description: + 'Check the Unpair Functionality of Bluetooth Control Module with the device which is already Unpaired', + setup() { + scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => { + this.$data.write('scancompleted', 'scancompleted') + }) + deviceStateChangeListener = this.$thunder.api.BluetoothControl.on('devicestatechange', data => { + this.$data.write('address', data.address) + this.$data.write('state', data.state) + }) + }, + teardown() { + scanCompleteListener.dispose() + deviceStateChangeListener.dispose() + }, + steps: [ + baseTest, + { + description: 'Unpair the device which is already unpaired and validate error message', + sleep: 5, + test() { + return unpairBTDevice.call(this, btdevicelist[0]) //TODO - Replace btdevicelist[0] with the device address that is used to unpair in the baseTest + }, + validate(res) { + if (res.code === 36 && res.message === 'ERROR_ALREADY_RELEASED') { + return true + } else { + this.$log('Proper error message is not shown') + return false + } + }, + }, + ], +}