未验证 提交 c76403dd 编写于 作者: O openharmony_ci 提交者: Gitee

!7843 【媒体子系统】增加try catch捕获UiDriver异常

Merge pull request !7843 from 秦莉文/monthly_20221018
...@@ -449,15 +449,20 @@ export default function audioCapturer() { ...@@ -449,15 +449,20 @@ export default function audioCapturer() {
}) })
} }
async function driveFn() { async function driveFn() {
console.info(`come in driveFn`); try {
let driver = await UiDriver.create(); let driver = await UiDriver.create()
console.info(`driver is ${JSON.stringify(driver)}`); console.info(`case come in driveFn 222`)
console.info(`driver is ${JSON.stringify(driver)}`)
await sleep(100); await sleep(100);
console.info(`UiDriver start`);
let button = await driver.findComponent(BY.text('允许')); let button = await driver.findComponent(BY.text('允许'));
console.info(`button is ${JSON.stringify(button)}`); console.info(`button is ${JSON.stringify(button)}`);
await sleep(100); await sleep(100);
await button.click(); await button.click();
} catch (err) {
console.info('err is ' + err);
return;
}
} }
beforeAll(async function () { beforeAll(async function () {
......
...@@ -19,7 +19,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from ...@@ -19,7 +19,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from
import { UiDriver, BY } from '@ohos.UiTest' import { UiDriver, BY } from '@ohos.UiTest'
export default function audioCapturerChange() { export default function audioCapturerChange() {
describe('audioCapturerChange', function () { describe('audioCapturerChange', function () {
let audioStreamManager; let audioStreamManager;
let audioStreamManagerCB; let audioStreamManagerCB;
let Tag = "AFCapLog"; let Tag = "AFCapLog";
...@@ -37,15 +37,20 @@ describe('audioCapturerChange', function () { ...@@ -37,15 +37,20 @@ describe('audioCapturerChange', function () {
}) })
} }
async function driveFn() { async function driveFn() {
console.info(`come in driveFn`); try {
let driver = await UiDriver.create(); let driver = await UiDriver.create()
console.info(`driver is ${JSON.stringify(driver)}`); console.info(`case come in driveFn 222`)
console.info(`driver is ${JSON.stringify(driver)}`)
await sleep(100); await sleep(100);
console.info(`UiDriver start`); console.info(`UiDriver start`);
let button = await driver.findComponent(BY.text('允许')); let button = await driver.findComponent(BY.text('允许'));
console.info(`button is ${JSON.stringify(button)}`); console.info(`button is ${JSON.stringify(button)}`);
await sleep(100); await sleep(100);
await button.click(); await button.click();
} catch (err) {
console.info('err is ' + err);
return;
}
} }
beforeAll(async function () { beforeAll(async function () {
...@@ -1638,5 +1643,5 @@ describe('audioCapturerChange', function () { ...@@ -1638,5 +1643,5 @@ describe('audioCapturerChange', function () {
}); });
}) })
}) })
} }
\ No newline at end of file
...@@ -20,7 +20,7 @@ import { UiDriver, BY } from '@ohos.UiTest' ...@@ -20,7 +20,7 @@ import { UiDriver, BY } from '@ohos.UiTest'
export default function audioFramework() { export default function audioFramework() {
describe('audioFramework', function () { describe('audioFramework', function () {
let TagFrmwk = "AudioFrameworkTest"; let TagFrmwk = "AudioFrameworkTest";
console.info(`${TagFrmwk}: Create AudioManger Object JS Framework`); console.info(`${TagFrmwk}: Create AudioManger Object JS Framework`);
let audioManager = null; let audioManager = null;
...@@ -105,15 +105,20 @@ describe('audioFramework', function () { ...@@ -105,15 +105,20 @@ describe('audioFramework', function () {
}) })
} }
async function driveFn() { async function driveFn() {
console.info(`come in driveFn`); try {
let driver = await UiDriver.create(); let driver = await UiDriver.create()
console.info(`driver is ${JSON.stringify(driver)}`); console.info(`case come in driveFn 222`)
console.info(`driver is ${JSON.stringify(driver)}`)
await sleep(100); await sleep(100);
console.info(`UiDriver start`); console.info(`UiDriver start`);
let button = await driver.findComponent(BY.text('允许')); let button = await driver.findComponent(BY.text('允许'));
console.info(`button is ${JSON.stringify(button)}`); console.info(`button is ${JSON.stringify(button)}`);
await sleep(100); await sleep(100);
await button.click(); await button.click();
} catch (err) {
console.info('err is ' + err);
return;
}
} }
beforeAll(async function () { beforeAll(async function () {
...@@ -3580,15 +3585,15 @@ describe('audioFramework', function () { ...@@ -3580,15 +3585,15 @@ describe('audioFramework', function () {
}); });
await audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then(function (value) { await audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then(function (value) {
if (flag == true && value == false) { if (flag == true && value == false) {
console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0100 isDeviceActive : SPEAKER: Deactivate : PASS :${value } flag is ${flag}`); console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0100 isDeviceActive : SPEAKER: Deactivate : PASS :${value} flag is ${flag}`);
expect(true).assertTrue(); expect(true).assertTrue();
} }
else if (flag == false && value == true) { else if (flag == false && value == true) {
console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0100 isDeviceActive : SPEAKER: Deactivate : PASS :${value } flag is ${flag}`); console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0100 isDeviceActive : SPEAKER: Deactivate : PASS :${value} flag is ${flag}`);
expect(true).assertTrue(); expect(true).assertTrue();
} }
else { else {
console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0100 isDeviceActive : SPEAKER: Deactivate : fail :${value } flag is ${flag}`); console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0100 isDeviceActive : SPEAKER: Deactivate : fail :${value} flag is ${flag}`);
expect(false).assertTrue(); expect(false).assertTrue();
} }
}).catch((err) => { }).catch((err) => {
...@@ -3637,7 +3642,7 @@ describe('audioFramework', function () { ...@@ -3637,7 +3642,7 @@ describe('audioFramework', function () {
*@tc.type : Function *@tc.type : Function
*@tc.level : Level 2 *@tc.level : Level 2
*/ */
it('SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0300', 2,async function (done) { it('SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0300', 2, async function (done) {
let flag = true let flag = true
let outputDeviceDescription = await audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG); let outputDeviceDescription = await audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG);
console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0300 outputDeviceDescription is ${JSON.stringify(outputDeviceDescription)}`); console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0300 outputDeviceDescription is ${JSON.stringify(outputDeviceDescription)}`);
...@@ -3656,14 +3661,14 @@ describe('audioFramework', function () { ...@@ -3656,14 +3661,14 @@ describe('audioFramework', function () {
console.error(`${TagFrmwk}: Device Test: Callback : isDeviceActive : SPEAKER: Deactivate: Error: ${err.message}`); console.error(`${TagFrmwk}: Device Test: Callback : isDeviceActive : SPEAKER: Deactivate: Error: ${err.message}`);
expect(false).assertTrue(); expect(false).assertTrue();
} else if (value == false && flag == true) { } else if (value == false && flag == true) {
console.info(`${TagFrmwk}: Device Test: Callback : isDeviceActive : SPEAKER: Deactivate : PASS :${value } flag is ${flag}`); console.info(`${TagFrmwk}: Device Test: Callback : isDeviceActive : SPEAKER: Deactivate : PASS :${value} flag is ${flag}`);
expect(true).assertTrue(); expect(true).assertTrue();
} else if (value == true && flag == false) { } else if (value == true && flag == false) {
console.info(`${TagFrmwk}: Device Test: Callback : isDeviceActive : SPEAKER: Deactivate : PASS :${value } flag is ${flag}`); console.info(`${TagFrmwk}: Device Test: Callback : isDeviceActive : SPEAKER: Deactivate : PASS :${value} flag is ${flag}`);
expect(true).assertTrue(); expect(true).assertTrue();
} }
else { else {
console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0300 ${TagFrmwk}: Device Test: Callback : isDeviceActive : SPEAKER: Deactivate : FAIL :${value } flag is ${flag}`); console.info(`SUB_MULTIMEDIA_AUDIO_MANAGER_SETDEVICEACTIVE_0300 ${TagFrmwk}: Device Test: Callback : isDeviceActive : SPEAKER: Deactivate : FAIL :${value} flag is ${flag}`);
expect(false).assertTrue(); expect(false).assertTrue();
} }
done(); done();
...@@ -4675,7 +4680,7 @@ describe('audioFramework', function () { ...@@ -4675,7 +4680,7 @@ describe('audioFramework', function () {
*@tc.type : Function *@tc.type : Function
*@tc.level : Level 2 *@tc.level : Level 2
*/ */
it('SUB_MULTIMEDIA_AUDIO_ROUTING_MANAGER_GETDEVICES_0100', 2,async function (done) { it('SUB_MULTIMEDIA_AUDIO_ROUTING_MANAGER_GETDEVICES_0100', 2, async function (done) {
let AudioRoutingManager = audioManager.getRoutingManager(); let AudioRoutingManager = audioManager.getRoutingManager();
AudioRoutingManager.getDevices(1, (err, value) => { AudioRoutingManager.getDevices(1, (err, value) => {
// Getting all Output devices Enumb 1 = OUTPUT_DEVICES_FLAG // Getting all Output devices Enumb 1 = OUTPUT_DEVICES_FLAG
...@@ -4709,7 +4714,7 @@ describe('audioFramework', function () { ...@@ -4709,7 +4714,7 @@ describe('audioFramework', function () {
*@tc.type : Function *@tc.type : Function
*@tc.level : Level 2 *@tc.level : Level 2
*/ */
it('SUB_MULTIMEDIA_AUDIO_ROUTING_MANAGER_GETDEVICES_0200', 2,async function (done) { it('SUB_MULTIMEDIA_AUDIO_ROUTING_MANAGER_GETDEVICES_0200', 2, async function (done) {
let AudioRoutingManager = audioManager.getRoutingManager(); let AudioRoutingManager = audioManager.getRoutingManager();
AudioRoutingManager.getDevices(2, (err, value) => { AudioRoutingManager.getDevices(2, (err, value) => {
// Getting all Input Devices ENUM 2 = INPUT_DEVICES_FLAG // Getting all Input Devices ENUM 2 = INPUT_DEVICES_FLAG
...@@ -4914,5 +4919,5 @@ describe('audioFramework', function () { ...@@ -4914,5 +4919,5 @@ describe('audioFramework', function () {
await sleep(50); await sleep(50);
done(); done();
}) })
}) })
} }
...@@ -40,15 +40,20 @@ describe('audioVoip', function () { ...@@ -40,15 +40,20 @@ describe('audioVoip', function () {
}) })
} }
async function driveFn() { async function driveFn() {
console.info(`come in driveFn`); try {
let driver = await UiDriver.create(); let driver = await UiDriver.create()
console.info(`driver is ${JSON.stringify(driver)}`); console.info(`case come in driveFn 222`)
console.info(`driver is ${JSON.stringify(driver)}`)
await sleep(100); await sleep(100);
console.info(`UiDriver start`); console.info(`UiDriver start`);
let button = await driver.findComponent(BY.text('允许')); let button = await driver.findComponent(BY.text('允许'));
console.info(`button is ${JSON.stringify(button)}`); console.info(`button is ${JSON.stringify(button)}`);
await sleep(100); await sleep(100);
await button.click(); await button.click();
} catch (err) {
console.info('err is ' + err);
return;
}
} }
beforeAll(async function () { beforeAll(async function () {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import {expect} from 'deccjsunit/index' import { expect } from 'deccjsunit/index'
import router from '@system.router' import router from '@system.router'
import mediaLibrary from '@ohos.multimedia.mediaLibrary' import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import fileio from '@ohos.fileio' import fileio from '@ohos.fileio'
...@@ -31,6 +31,7 @@ export async function getPermission(permissionNames) { ...@@ -31,6 +31,7 @@ export async function getPermission(permissionNames) {
export async function driveFn(num) { export async function driveFn(num) {
console.info(`case come in driveFn 111`) console.info(`case come in driveFn 111`)
try {
let driver = await UiDriver.create() let driver = await UiDriver.create()
console.info(`case come in driveFn 222`) console.info(`case come in driveFn 222`)
console.info(`driver is ${JSON.stringify(driver)}`) console.info(`driver is ${JSON.stringify(driver)}`)
...@@ -43,6 +44,10 @@ export async function driveFn(num) { ...@@ -43,6 +44,10 @@ export async function driveFn(num) {
await button.click() await button.click()
} }
await msleepAsync(2000) await msleepAsync(2000)
} catch (err) {
console.info('err is ' + err);
return;
}
} }
// File operation // File operation
...@@ -50,7 +55,7 @@ export async function getFileDescriptor(fileName) { ...@@ -50,7 +55,7 @@ export async function getFileDescriptor(fileName) {
let fileDescriptor = undefined; let fileDescriptor = undefined;
await resourceManager.getResourceManager().then(async (mgr) => { await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.getRawFileDescriptor(fileName).then(value => { await mgr.getRawFileDescriptor(fileName).then(value => {
fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length}; fileDescriptor = { fd: value.fd, offset: value.offset, length: value.length };
console.log('case getRawFileDescriptor success fileName: ' + fileName); console.log('case getRawFileDescriptor success fileName: ' + fileName);
}).catch(error => { }).catch(error => {
console.log('case getRawFileDescriptor err: ' + error); console.log('case getRawFileDescriptor err: ' + error);
...@@ -61,7 +66,7 @@ export async function getFileDescriptor(fileName) { ...@@ -61,7 +66,7 @@ export async function getFileDescriptor(fileName) {
export async function closeFileDescriptor(fileName) { export async function closeFileDescriptor(fileName) {
await resourceManager.getResourceManager().then(async (mgr) => { await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.closeRawFileDescriptor(fileName).then(()=> { await mgr.closeRawFileDescriptor(fileName).then(() => {
console.log('case closeRawFileDescriptor ' + fileName); console.log('case closeRawFileDescriptor ' + fileName);
}).catch(error => { }).catch(error => {
console.log('case closeRawFileDescriptor err: ' + error); console.log('case closeRawFileDescriptor err: ' + error);
...@@ -98,7 +103,7 @@ export async function closeFdNumber(fdNumber) { ...@@ -98,7 +103,7 @@ export async function closeFdNumber(fdNumber) {
// wait synchronously // wait synchronously
export function msleep(time) { export function msleep(time) {
for(let t = Date.now();Date.now() - t <= time;); for (let t = Date.now(); Date.now() - t <= time;);
} }
// wait asynchronously // wait asynchronously
...@@ -127,19 +132,19 @@ export function catchCallback(error) { ...@@ -127,19 +132,19 @@ export function catchCallback(error) {
export function checkDescription(actualDescription, descriptionKey, descriptionValue) { export function checkDescription(actualDescription, descriptionKey, descriptionValue) {
for (let i = 0; i < descriptionKey.length; i++) { for (let i = 0; i < descriptionKey.length; i++) {
let property = actualDescription[descriptionKey[i]]; let property = actualDescription[descriptionKey[i]];
console.info('case key is '+ descriptionKey[i]); console.info('case key is ' + descriptionKey[i]);
console.info('case actual value is '+ property); console.info('case actual value is ' + property);
console.info('case hope value is '+ descriptionValue[i]); console.info('case hope value is ' + descriptionValue[i]);
expect(property).assertEqual(descriptionValue[i]); expect(property).assertEqual(descriptionValue[i]);
} }
} }
export function printDescription(obj) { export function printDescription(obj) {
let description = ""; let description = "";
for(let i in obj) { for (let i in obj) {
let property = obj[i]; let property = obj[i];
console.info('case key is '+ i); console.info('case key is ' + i);
console.info('case value is '+ property); console.info('case value is ' + property);
description += i + " = " + property + "\n"; description += i + " = " + property + "\n";
} }
} }
...@@ -167,8 +172,8 @@ export async function clearRouter() { ...@@ -167,8 +172,8 @@ export async function clearRouter() {
export async function getFd(pathName) { export async function getFd(pathName) {
let fdObject = { let fdObject = {
fileAsset : null, fileAsset: null,
fdNumber : null fdNumber: null
} }
let displayName = pathName; let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary(); const mediaTest = mediaLibrary.getMediaLibrary();
...@@ -179,8 +184,8 @@ export async function getFd(pathName) { ...@@ -179,8 +184,8 @@ export async function getFd(pathName) {
if (dataUri != undefined) { if (dataUri != undefined) {
let args = dataUri.id.toString(); let args = dataUri.id.toString();
let fetchOp = { let fetchOp = {
selections : fileKeyObj.ID + "=?", selections: fileKeyObj.ID + "=?",
selectionArgs : [args], selectionArgs: [args],
} }
let fetchFileResult = await mediaTest.getFileAssets(fetchOp); let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
fdObject.fileAsset = await fetchFileResult.getAllObject(); fdObject.fileAsset = await fetchFileResult.getAllObject();
...@@ -192,8 +197,8 @@ export async function getFd(pathName) { ...@@ -192,8 +197,8 @@ export async function getFd(pathName) {
export async function getAudioFd(pathName) { export async function getAudioFd(pathName) {
let fdObject = { let fdObject = {
fileAsset : null, fileAsset: null,
fdNumber : null fdNumber: null
} }
let displayName = pathName; let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary(); const mediaTest = mediaLibrary.getMediaLibrary();
...@@ -204,8 +209,8 @@ export async function getAudioFd(pathName) { ...@@ -204,8 +209,8 @@ export async function getAudioFd(pathName) {
if (dataUri != undefined) { if (dataUri != undefined) {
let args = dataUri.id.toString(); let args = dataUri.id.toString();
let fetchOp = { let fetchOp = {
selections : fileKeyObj.ID + "=?", selections: fileKeyObj.ID + "=?",
selectionArgs : [args], selectionArgs: [args],
} }
let fetchFileResult = await mediaTest.getFileAssets(fetchOp); let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
fdObject.fileAsset = await fetchFileResult.getAllObject(); fdObject.fileAsset = await fetchFileResult.getAllObject();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册