From 4679f31047dd8b60bdd5cb0d2a81bfc3aec6f1c9 Mon Sep 17 00:00:00 2001 From: sandeep-vedam Date: Fri, 6 Mar 2020 17:30:02 +0530 Subject: [PATCH 1/3] Added test cases relate to BluetoothControl Plugin - Scan, Pair, Unpair --- src/commonMethods/commonFunctions.js | 42 +++++++++ src/commonMethods/constants.js | 3 +- .../BluetoothControl_Pair_001.test.js | 68 +++++++++++++++ .../BluetoothControl_Pair_002.test.js | 36 ++++++++ .../BluetoothControl_Pair_003.test.js | 44 ++++++++++ .../BluetoothControl_Scan_001.test.js | 87 +++++++++++++++++++ .../BluetoothControl_Scan_002.test.js | 49 +++++++++++ .../BluetoothControl_Unpair_001.test.js | 66 ++++++++++++++ .../BluetoothControl_Unpair_002.test.js | 41 +++++++++ .../BluetoothControl_Unpair_003.test.js | 44 ++++++++++ 10 files changed, 479 insertions(+), 1 deletion(-) create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Pair_002.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Pair_003.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Scan_002.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Unpair_001.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Unpair_002.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Unpair_003.test.js 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..24e4766 --- /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: 5, + 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..b6c2cbf --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js @@ -0,0 +1,87 @@ +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', + 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() { + return scanDevices.call(this, 'LowEnergy', 10) + }, + 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 devices available are in the list. + // If user says yes pass the test case. Store this device list in a variable + 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_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 + } + }, + }, + ], +} From d9d4d207c1c749852e1d36622dbfdffb5b307498 Mon Sep 17 00:00:00 2001 From: sandeep-vedam Date: Mon, 23 Mar 2020 16:30:24 +0530 Subject: [PATCH 2/3] Added test cases related to Bt Clasic device and BT Timeout and few minor updates --- .../BluetoothControl_Pair_001.test.js | 2 +- .../BluetoothControl_Scan_001.test.js | 6 +- .../BluetoothControl_Scan_003.test.js | 87 +++++++++++++++++++ .../BluetoothControl_Scan_004.test.js | 87 +++++++++++++++++++ 4 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js create mode 100644 src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js index 24e4766..3a3157a 100644 --- a/src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js +++ b/src/tests/bluetoothcontrol/BluetoothControl_Pair_001.test.js @@ -43,7 +43,7 @@ export default { }, { description: 'Check whether pairing is success', - sleep: 5, + 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) => { diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js index b6c2cbf..7cc342c 100644 --- a/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js @@ -10,7 +10,7 @@ let scanCompleteListener export default { title: 'Bluetooth Control - Scan 001', - description: 'Check the Scan Functionality of Bluetooth Control Module', + description: 'Check the Scan Functionality of Bluetooth Control Module for Low Energy devices', setup() { scanCompleteListener = this.$thunder.api.BluetoothControl.on('scancomplete', () => { this.$data.write('scancompleted', 'scancompleted') @@ -73,8 +73,8 @@ export default { return getBluetoothDevices.call(this) }, validate(result) { - //TODO - Prompt the user with result and ask him to confirm the devices available are in the list. - // If user says yes pass the test case. Store this device list in a variable + //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 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..1be6700 --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js @@ -0,0 +1,87 @@ +import { + pluginDeactivate, + pluginActivate, + scanDevices, + getBluetoothDevices, +} from '../../commonMethods/commonFunctions' +import constants from '../../commonMethods/constants' + +let scanCompleteListener + +export default { + title: 'Bluetooth Control - Scan 003', + description: 'Check the Scan Functionality of Bluetooth Control Module for Classic devices', + 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() { + return scanDevices.call(this, 'Classic', 10) + }, + 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 Classic devices available are 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_004.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js new file mode 100644 index 0000000..6862d5b --- /dev/null +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js @@ -0,0 +1,87 @@ +import { + pluginDeactivate, + pluginActivate, + scanDevices, + getBluetoothDevices, +} from '../../commonMethods/commonFunctions' +import constants from '../../commonMethods/constants' + +let scanCompleteListener + +export default { + title: 'Bluetooth Control - Scan 004', + description: 'Check the Scan Functionality of Bluetooth Control Module with modified timeout', + 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() { + return scanDevices.call(this, 'LowEnergy', 20) + }, + 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 + } + }, + }, + ], +} From 1e1bf00ba2fc22bc0fecc1c20e48f6c6c3cdc5f2 Mon Sep 17 00:00:00 2001 From: sandeep-vedam Date: Mon, 23 Mar 2020 17:09:25 +0530 Subject: [PATCH 3/3] Optimized test code by extending basetest --- .../BluetoothControl_Scan_001.test.js | 11 ++- .../BluetoothControl_Scan_003.test.js | 96 +++---------------- .../BluetoothControl_Scan_004.test.js | 95 +++--------------- 3 files changed, 35 insertions(+), 167 deletions(-) diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js index 7cc342c..f7c6eba 100644 --- a/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_001.test.js @@ -11,6 +11,10 @@ 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') @@ -36,7 +40,12 @@ export default { description: 'Invoke Scan', sleep: 5, test() { - return scanDevices.call(this, 'LowEnergy', 10) + 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) { diff --git a/src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js b/src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js index 1be6700..649a163 100644 --- a/src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_003.test.js @@ -1,87 +1,17 @@ -import { - pluginDeactivate, - pluginActivate, - scanDevices, - getBluetoothDevices, -} from '../../commonMethods/commonFunctions' -import constants from '../../commonMethods/constants' - -let scanCompleteListener +import baseTest from './BluetoothControl_Scan_001.test' export default { - title: 'Bluetooth Control - Scan 003', - description: 'Check the Scan Functionality of Bluetooth Control Module for Classic devices', - 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() { - return scanDevices.call(this, 'Classic', 10) - }, - validate(res) { - if (res == null) { - return true - } else { - this.$log('Scan does not start') - return false - } - }, + ...baseTest, + ...{ + context: { + deviceType: 'Classic', + timeOut: 10, }, - { - 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 Classic devices available are 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 - } - }, - }, - ], + + 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 index 6862d5b..c4908e3 100644 --- a/src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js +++ b/src/tests/bluetoothcontrol/BluetoothControl_Scan_004.test.js @@ -1,87 +1,16 @@ -import { - pluginDeactivate, - pluginActivate, - scanDevices, - getBluetoothDevices, -} from '../../commonMethods/commonFunctions' -import constants from '../../commonMethods/constants' - -let scanCompleteListener +import baseTest from './BluetoothControl_Scan_001.test' export default { - title: 'Bluetooth Control - Scan 004', - description: 'Check the Scan Functionality of Bluetooth Control Module with modified timeout', - 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', + ...baseTest, + ...{ + context: { + deviceType: 'Low Energy', + timeOut: 20, }, - { - description: 'Invoke Scan', - sleep: 5, - test() { - return scanDevices.call(this, 'LowEnergy', 20) - }, - 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 - } - }, - }, - ], + 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 + }), + }, }