@ohos.app.ability.abilityDelegatorRegistry (AbilityDelegatorRegistry)

AbilityDelegatorRegistry, a module of the Test Framework, is used to obtain AbilityDelegator and AbilityDelegatorArgs objects. AbilityDelegator provides APIs for creating AbilityMonitor objects, which can be used to listen for ability lifecycle changes. AbilityDelegatorArgs provides APIs for obtaining test parameters.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. The APIs provided by this module can be used only in the test framework.

Modules to Import

import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';

AbilityLifecycleState

Enumerates the ability lifecycle states. It can be used in getAbilityState(ability) of AbilityDelegator to return different ability lifecycle states.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Value Description
UNINITIALIZED 0 The ability is in an invalid state.
CREATE 1 The ability is created.
FOREGROUND 2 The ability is running in the foreground.
BACKGROUND 3 The ability is running in the background.
DESTROY 4 The ability is destroyed.

AbilityDelegatorRegistry.getAbilityDelegator

getAbilityDelegator(): AbilityDelegator

Obtains an AbilityDelegator object.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Return value

Type Description
AbilityDelegator AbilityDelegator object, which can be used to schedule the functionalities of the test framework.

Example

import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';

let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();

let want = {
    bundleName: 'com.ohos.example',
    abilityName: 'MainAbility'
};
abilityDelegator.startAbility(want, (err) => {
    if (err.code !== 0) {
        console.log('Success start ability.');
    } else {
        console.log('Failed start ability, error: ' + JSON.stringify(err));
    }
})

AbilityDelegatorRegistry.getArguments

getArguments(): AbilityDelegatorArgs

Obtains an AbilityDelegatorArgs object.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Return value

Type Description
AbilityDelegatorArgs AbilityDelegatorArgs object, which can be used to obtain test parameters.

Example

import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';

let args = AbilityDelegatorRegistry.getArguments();
console.info('getArguments bundleName:' + args.bundleName);
console.info('getArguments parameters:' + JSON.stringify(args.parameters));
console.info('getArguments testCaseNames:' + args.testCaseNames);
console.info('getArguments testRunnerClassName:' + args.testRunnerClassName);