app.js 2.6 KB
Newer Older
Y
yuxiaoya2 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
18
import { UiDriver, BY } from '@ohos.uitest'
Y
yuxiaoya2 已提交
19 20
import testsuite from '../test/List.test'

21 22 23 24 25 26 27 28 29 30 31 32 33
import featureAbility from '@ohos.ability.featureAbility';

async function requestPermission() {
    try {
        let context = featureAbility.getContext();
        await context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, (data) => {
            console.info('TestApplication requestPermission data: ' + JSON.stringify(data));
        });
    } catch (err) {
        console.error('TestApplication permission' + JSON.stringify(err));
    }
}

34 35 36 37 38 39 40 41 42 43 44
async function clickPermission(driver) {
    console.info("clickPermission begin");
    await driver.delayMs(2000);

    var data_sync_allow = await driver.findComponent(BY.text("允许"))
    await driver.delayMs(1000)
    var wait_count = 0
    while (data_sync_allow == null || data_sync_allow == undefined) {
        data_sync_allow = await driver.findComponent(BY.text("允许"))
        wait_count += 1
        await driver.delayMs(1000)
45
        if (wait_count == 15) {
46 47 48 49 50 51 52 53 54 55 56
            break
        }
    }
    if (data_sync_allow == null) {
        console.info('应用非首次开启')
    } else {
        await data_sync_allow.click()
        console.log('点击多设备授权框的允许按钮')
    }
}

Y
yuxiaoya2 已提交
57 58 59 60 61 62 63
export default {
    onCreate() {
        console.info('TestApplication onCreate')
        var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
        var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
        console.info('start run testcase!!!')
        Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
64
        var driver = UiDriver.create()
65
        requestPermission()
66
        clickPermission(driver)
Y
yuxiaoya2 已提交
67 68 69 70 71
    },
    onDestroy() {
        console.info("TestApplication onDestroy");
    }
};