1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' 17import { Hypium } from '@ohos/hypium' 18import { UiDriver, BY } from '@ohos.UiTest' 19import testsuite from '../test/List.test' 20 21import featureAbility from '@ohos.ability.featureAbility'; 22 23async function requestPermission() { 24 try { 25 let context = featureAbility.getContext(); 26 await context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, (data) => { 27 console.info('TestApplication requestPermission data: ' + JSON.stringify(data)); 28 }); 29 } catch (err) { 30 console.error('TestApplication permission' + JSON.stringify(err)); 31 } 32} 33 34async function clickPermission(driver) { 35 console.info("clickPermission begin"); 36 await driver.delayMs(2000); 37 38 var data_sync_allow = await driver.findComponent(BY.text("允许")) 39 await driver.delayMs(1000) 40 var wait_count = 0 41 while (data_sync_allow == null || data_sync_allow == undefined) { 42 data_sync_allow = await driver.findComponent(BY.text("允许")) 43 wait_count += 1 44 await driver.delayMs(1000) 45 if (wait_count == 15) { 46 break 47 } 48 } 49 if (data_sync_allow == null) { 50 console.info('应用非首次开启') 51 } else { 52 await data_sync_allow.click() 53 console.log('点击多设备授权框的允许按钮') 54 } 55} 56 57export default { 58 onCreate() { 59 console.info('TestApplication onCreate') 60 var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() 61 var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() 62 console.info('start run testcase!!!') 63 Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) 64 var driver = UiDriver.create() 65 requestPermission() 66 clickPermission(driver) 67 }, 68 onDestroy() { 69 console.info("TestApplication onDestroy"); 70 } 71}; 72