• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.abilityDelegatorRegistry (AbilityDelegatorRegistry)
2
3**AbilityDelegatorRegistry**, a module of the [Test Framework](../../application-test/arkxtest-guidelines.md), is used to obtain [AbilityDelegator](js-apis-inner-application-abilityDelegator.md) and [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md) 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.
4
5> **NOTE**
6>
7> 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.
8> The APIs provided by this module can be used only in the test framework.
9
10## Modules to Import
11
12```ts
13import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
14```
15
16## AbilityLifecycleState
17
18Enumerates the ability lifecycle states. It can be used in [getAbilityState(ability)](js-apis-inner-application-abilityDelegator.md#getabilitystate9) of [AbilityDelegator](js-apis-inner-application-abilityDelegator.md) to return different ability lifecycle states.
19
20**System capability**: SystemCapability.Ability.AbilityRuntime.Core
21
22| Name         | Value  | Description                       |
23| ------------- | ---- | --------------------------- |
24| UNINITIALIZED | 0    | The ability is in an invalid state.  |
25| CREATE        | 1    | The ability is created.|
26| FOREGROUND    | 2    | The ability is running in the foreground.  |
27| BACKGROUND    | 3    | The ability is running in the background.  |
28| DESTROY       | 4    | The ability is destroyed.|
29
30## AbilityDelegatorRegistry.getAbilityDelegator
31
32getAbilityDelegator(): AbilityDelegator
33
34Obtains an [AbilityDelegator](js-apis-inner-application-abilityDelegator.md) object.
35
36**System capability**: SystemCapability.Ability.AbilityRuntime.Core
37
38**Return value**
39
40| Type                                                        | Description                                                        |
41| ------------------------------------------------------------ | ------------------------------------------------------------ |
42| [AbilityDelegator](js-apis-inner-application-abilityDelegator.md#AbilityDelegator) | [AbilityDelegator](js-apis-inner-application-abilityDelegator.md#AbilityDelegator) object, which can be used to schedule the functionalities of the test framework.|
43
44**Example**
45
46```ts
47import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
48
49let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
50
51let want = {
52    bundleName: 'com.ohos.example',
53    abilityName: 'MainAbility'
54};
55abilityDelegator.startAbility(want, (err) => {
56    if (err.code !== 0) {
57        console.log('Success start ability.');
58    } else {
59        console.log('Failed start ability, error: ' + JSON.stringify(err));
60    }
61})
62```
63
64## AbilityDelegatorRegistry.getArguments
65
66getArguments(): AbilityDelegatorArgs
67
68Obtains an [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md) object.
69
70**System capability**: SystemCapability.Ability.AbilityRuntime.Core
71
72**Return value**
73
74| Type                                                        | Description                                                        |
75| ------------------------------------------------------------ | ------------------------------------------------------------ |
76| [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md) | [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md) object, which can be used to obtain test parameters.|
77
78**Example**
79
80```ts
81import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
82
83let args = AbilityDelegatorRegistry.getArguments();
84console.info('getArguments bundleName:' + args.bundleName);
85console.info('getArguments parameters:' + JSON.stringify(args.parameters));
86console.info('getArguments testCaseNames:' + args.testCaseNames);
87console.info('getArguments testRunnerClassName:' + args.testRunnerClassName);
88```
89