askui 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/cjs/core/annotation/template.html +1 -11390
  2. package/dist/cjs/core/model/annotation-result/annotation-interface.d.ts +1 -1
  3. package/dist/cjs/core/model/custom-element-json.d.ts +75 -0
  4. package/dist/cjs/core/model/custom-element-json.js +2 -0
  5. package/dist/cjs/core/model/custom-element.d.ts +21 -0
  6. package/dist/cjs/core/model/custom-element.js +54 -0
  7. package/dist/cjs/core/reporting/default-reporter.d.ts +10 -0
  8. package/dist/cjs/core/reporting/default-reporter.js +12 -0
  9. package/dist/cjs/core/reporting/default-step.d.ts +24 -0
  10. package/dist/cjs/core/reporting/default-step.js +75 -0
  11. package/dist/cjs/core/reporting/index.d.ts +11 -0
  12. package/dist/cjs/core/reporting/index.js +23 -0
  13. package/dist/cjs/core/reporting/instruction.d.ts +7 -0
  14. package/dist/cjs/core/reporting/instruction.js +2 -0
  15. package/dist/cjs/core/reporting/reporter-config.d.ts +13 -0
  16. package/dist/cjs/core/reporting/reporter-config.js +2 -0
  17. package/dist/cjs/core/reporting/reporter.d.ts +14 -0
  18. package/dist/cjs/core/reporting/reporter.js +2 -0
  19. package/dist/cjs/core/reporting/snapshot-detail-level.d.ts +21 -0
  20. package/dist/cjs/core/reporting/snapshot-detail-level.js +2 -0
  21. package/dist/cjs/core/reporting/snapshot.d.ts +6 -0
  22. package/dist/cjs/core/reporting/snapshot.js +2 -0
  23. package/dist/cjs/core/reporting/step-reporter.d.ts +17 -0
  24. package/dist/cjs/core/reporting/step-reporter.js +64 -0
  25. package/dist/cjs/core/reporting/step-run.d.ts +9 -0
  26. package/dist/cjs/core/reporting/step-run.js +2 -0
  27. package/dist/cjs/core/reporting/step-status-end.d.ts +1 -0
  28. package/dist/cjs/core/reporting/step-status-end.js +2 -0
  29. package/dist/cjs/core/reporting/step-status.d.ts +13 -0
  30. package/dist/cjs/core/reporting/step-status.js +2 -0
  31. package/dist/cjs/core/reporting/step.d.ts +36 -0
  32. package/dist/cjs/core/reporting/step.js +2 -0
  33. package/dist/cjs/execution/dsl.d.ts +1 -1
  34. package/dist/cjs/execution/execution-runtime.d.ts +16 -9
  35. package/dist/cjs/execution/execution-runtime.js +79 -33
  36. package/dist/cjs/execution/inference-client.d.ts +1 -1
  37. package/dist/cjs/execution/reporter.d.ts +132 -0
  38. package/dist/cjs/execution/reporter.js +146 -0
  39. package/dist/cjs/execution/ui-control-client-dependency-builder.d.ts +14 -0
  40. package/dist/cjs/execution/ui-control-client-dependency-builder.js +72 -0
  41. package/dist/cjs/execution/ui-control-client.d.ts +27 -15
  42. package/dist/cjs/execution/ui-control-client.js +97 -67
  43. package/dist/cjs/execution/ui-controller-client-interface.d.ts +11 -2
  44. package/dist/cjs/execution/ui-controller-client.d.ts +4 -4
  45. package/dist/cjs/execution/ui-controller-client.js +6 -6
  46. package/dist/cjs/lib/ui-controller-facade.js +1 -1
  47. package/dist/cjs/main.d.ts +2 -1
  48. package/dist/cjs/main.js +2 -2
  49. package/dist/cjs/utils/proxy/proxy-builder.d.ts +1 -1
  50. package/dist/cjs/utils/proxy/proxy-builder.js +3 -3
  51. package/dist/esm/core/annotation/template.html +1 -11390
  52. package/dist/esm/core/model/annotation-result/annotation-interface.d.ts +1 -1
  53. package/dist/esm/core/model/custom-element-json.d.ts +75 -0
  54. package/dist/esm/core/model/custom-element-json.js +1 -0
  55. package/dist/esm/core/model/custom-element.d.ts +21 -0
  56. package/dist/esm/core/model/custom-element.js +50 -0
  57. package/dist/esm/core/reporting/default-reporter.d.ts +10 -0
  58. package/dist/esm/core/reporting/default-reporter.js +9 -0
  59. package/dist/esm/core/reporting/default-step.d.ts +24 -0
  60. package/dist/esm/core/reporting/default-step.js +71 -0
  61. package/dist/esm/core/reporting/index.d.ts +11 -0
  62. package/dist/esm/core/reporting/index.js +11 -0
  63. package/dist/esm/core/reporting/instruction.d.ts +7 -0
  64. package/dist/esm/core/reporting/instruction.js +1 -0
  65. package/dist/esm/core/reporting/reporter-config.d.ts +13 -0
  66. package/dist/esm/core/reporting/reporter-config.js +1 -0
  67. package/dist/esm/core/reporting/reporter.d.ts +14 -0
  68. package/dist/esm/core/reporting/reporter.js +1 -0
  69. package/dist/esm/core/reporting/snapshot-detail-level.d.ts +21 -0
  70. package/dist/esm/core/reporting/snapshot-detail-level.js +1 -0
  71. package/dist/esm/core/reporting/snapshot.d.ts +6 -0
  72. package/dist/esm/core/reporting/snapshot.js +1 -0
  73. package/dist/esm/core/reporting/step-reporter.d.ts +17 -0
  74. package/dist/esm/core/reporting/step-reporter.js +60 -0
  75. package/dist/esm/core/reporting/step-run.d.ts +9 -0
  76. package/dist/esm/core/reporting/step-run.js +1 -0
  77. package/dist/esm/core/reporting/step-status-end.d.ts +1 -0
  78. package/dist/esm/core/reporting/step-status-end.js +1 -0
  79. package/dist/esm/core/reporting/step-status.d.ts +13 -0
  80. package/dist/esm/core/reporting/step-status.js +1 -0
  81. package/dist/esm/core/reporting/step.d.ts +36 -0
  82. package/dist/esm/core/reporting/step.js +1 -0
  83. package/dist/esm/execution/dsl.d.ts +1 -1
  84. package/dist/esm/execution/execution-runtime.d.ts +16 -9
  85. package/dist/esm/execution/execution-runtime.js +77 -31
  86. package/dist/esm/execution/inference-client.d.ts +1 -1
  87. package/dist/esm/execution/reporter.d.ts +132 -0
  88. package/dist/esm/execution/reporter.js +142 -0
  89. package/dist/esm/execution/ui-control-client-dependency-builder.d.ts +14 -0
  90. package/dist/esm/execution/ui-control-client-dependency-builder.js +68 -0
  91. package/dist/esm/execution/ui-control-client.d.ts +27 -15
  92. package/dist/esm/execution/ui-control-client.js +96 -66
  93. package/dist/esm/execution/ui-controller-client-interface.d.ts +11 -2
  94. package/dist/esm/execution/ui-controller-client.d.ts +4 -4
  95. package/dist/esm/execution/ui-controller-client.js +6 -6
  96. package/dist/esm/lib/ui-controller-facade.js +2 -2
  97. package/dist/esm/main.d.ts +2 -1
  98. package/dist/esm/main.js +1 -1
  99. package/dist/esm/utils/proxy/proxy-builder.d.ts +1 -1
  100. package/dist/esm/utils/proxy/proxy-builder.js +1 -1
  101. package/dist/example_projects_templates/typescript_jest/test/my-first-askui-test-suite.test.ts +9 -2
  102. package/package.json +1 -1
@@ -8,22 +8,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { ControlCommandCode } from '../core/ui-control-commands';
11
- import { CustomElement } from '../core/model/test-case-dto';
11
+ import { CustomElement } from '../core/model/custom-element';
12
12
  import { RepeatError } from './repeat-error';
13
13
  import { delay } from './misc';
14
14
  import { ControlCommandError } from './control-command-error';
15
15
  import { logger } from '../lib/logger';
16
16
  import { Base64Image } from '../utils/base_64_image/base-64-image';
17
17
  export class ExecutionRuntime {
18
- constructor(uiControllerClient, inferenceClient) {
18
+ constructor(uiControllerClient, inferenceClient, stepReporter) {
19
19
  this.uiControllerClient = uiControllerClient;
20
20
  this.inferenceClient = inferenceClient;
21
+ this.stepReporter = stepReporter;
21
22
  this.EXEC_REPETITION_COUNT = 25;
22
23
  this.PREDICT_COMMAND_RETRY_COUNT = 2;
23
24
  }
24
- executeTestStep(step) {
25
+ connect() {
25
26
  return __awaiter(this, void 0, void 0, function* () {
26
- yield this.executeCommand(step);
27
+ return this.uiControllerClient.connect();
28
+ });
29
+ }
30
+ disconnect() {
31
+ this.uiControllerClient.disconnect();
32
+ }
33
+ startVideoRecording() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ yield this.uiControllerClient.startVideoRecording();
36
+ });
37
+ }
38
+ stopVideoRecording() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ yield this.uiControllerClient.stopVideoRecording();
41
+ });
42
+ }
43
+ readVideoRecording() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const response = yield this.uiControllerClient.readVideoRecording();
46
+ return response.data.video;
27
47
  });
28
48
  }
29
49
  requestControl(controlCommand) {
@@ -31,25 +51,22 @@ export class ExecutionRuntime {
31
51
  yield this.uiControllerClient.requestControl(controlCommand);
32
52
  });
33
53
  }
34
- /**
35
- * @param {TestStep} step - Test step used for predicting command.
36
- */
37
- executeCommand(step) {
38
- var _a;
54
+ executeInstruction(instruction) {
55
+ var _a, _b, _c;
39
56
  return __awaiter(this, void 0, void 0, function* () {
40
- const controlCommand = yield this.predictCommandWithRetry(step);
57
+ const controlCommand = yield this.predictCommandWithRetry(instruction);
41
58
  if (controlCommand.code === ControlCommandCode.OK) {
42
59
  return this.requestControl(controlCommand);
43
60
  }
44
61
  if (controlCommand.tryToRepeat) {
45
62
  yield this.requestControl(controlCommand);
46
- return this.executeCommandRepeatedly(step);
63
+ return this.executeCommandRepeatedly(instruction);
47
64
  }
48
- throw new ControlCommandError(((_a = controlCommand.actions[0]) === null || _a === void 0 ? void 0 : _a.text) || '');
65
+ throw new ControlCommandError((_c = (_b = (_a = controlCommand.actions) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : '');
49
66
  });
50
67
  }
51
- executeCommandRepeatedly(step) {
52
- var _a;
68
+ executeCommandRepeatedly(instruction) {
69
+ var _a, _b, _c;
53
70
  return __awaiter(this, void 0, void 0, function* () {
54
71
  /* eslint-disable no-await-in-loop */
55
72
  for (let repeatCount = this.EXEC_REPETITION_COUNT; repeatCount >= 0; repeatCount -= 1) {
@@ -58,7 +75,7 @@ export class ExecutionRuntime {
58
75
  + 'from a single test step reached');
59
76
  }
60
77
  logger.debug('Repeat command execution....');
61
- const controlCommand = yield this.predictCommandWithRetry(step);
78
+ const controlCommand = yield this.predictCommandWithRetry(instruction);
62
79
  if (controlCommand.code === ControlCommandCode.OK) {
63
80
  break;
64
81
  }
@@ -66,7 +83,7 @@ export class ExecutionRuntime {
66
83
  yield this.requestControl(controlCommand);
67
84
  }
68
85
  else {
69
- throw new ControlCommandError(((_a = controlCommand.actions[0]) === null || _a === void 0 ? void 0 : _a.text) || '');
86
+ throw new ControlCommandError((_c = (_b = (_a = controlCommand.actions) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : '');
70
87
  }
71
88
  }
72
89
  });
@@ -76,9 +93,10 @@ export class ExecutionRuntime {
76
93
  * --> retry with linear back-off
77
94
  */
78
95
  /* eslint-disable-next-line consistent-return */
79
- predictCommandWithRetry(step) {
96
+ predictCommandWithRetry(instruction) {
97
+ var _a, _b, _c;
80
98
  return __awaiter(this, void 0, void 0, function* () {
81
- let command = yield this.predictCommand(step);
99
+ let command = yield this.predictCommand(instruction);
82
100
  /* eslint-disable no-await-in-loop */
83
101
  for (let k = 0; k < this.PREDICT_COMMAND_RETRY_COUNT; k += 1) {
84
102
  if (command.code === ControlCommandCode.OK) {
@@ -87,28 +105,56 @@ export class ExecutionRuntime {
87
105
  const msUntilRetry = k * 1000;
88
106
  logger.debug(`Wait ${msUntilRetry} and retry predicting command...`);
89
107
  yield delay(msUntilRetry);
90
- command = yield this.predictCommand(step);
108
+ command = yield this.predictCommand(instruction, new ControlCommandError((_c = (_b = (_a = command.actions) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : ''));
91
109
  }
92
110
  /* eslint-enable no-await-in-loop */
93
111
  return command;
94
112
  });
95
113
  }
96
- getImageIfRequired(instruction) {
114
+ isImageRequiredByConfig() {
115
+ return this.stepReporter.config.withScreenshots === 'begin'
116
+ || this.stepReporter.config.withScreenshots === 'always';
117
+ }
118
+ isImageRequired(instruction) {
97
119
  return __awaiter(this, void 0, void 0, function* () {
98
- const isImageRequired = yield this.inferenceClient.isImageRequired(instruction);
99
- if (!isImageRequired) {
100
- return undefined;
101
- }
102
- const screenshotResponse = yield this.uiControllerClient.requestScreenshot();
103
- return screenshotResponse.data.image;
120
+ if (this.isImageRequiredByConfig())
121
+ return Promise.resolve(true);
122
+ return this.inferenceClient.isImageRequired(instruction);
123
+ });
124
+ }
125
+ isAnnotationRequired() {
126
+ return this.stepReporter.config.withDetectedElements === 'begin'
127
+ || this.stepReporter.config.withDetectedElements === 'always';
128
+ }
129
+ getScreenshot() {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ const requestScreenshotResponse = yield this.uiControllerClient.requestScreenshot();
132
+ return requestScreenshotResponse.data.image;
133
+ });
134
+ }
135
+ buildSnapshot(instruction) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const createdAt = new Date();
138
+ const screenshot = (yield this.isImageRequired(instruction))
139
+ ? yield this.getScreenshot() : undefined;
140
+ const annotation = this.isAnnotationRequired() ? yield this.annotateImage() : undefined;
141
+ return {
142
+ createdAt,
143
+ screenshot,
144
+ detectedElements: annotation === null || annotation === void 0 ? void 0 : annotation.detected_elements,
145
+ };
104
146
  });
105
147
  }
106
- predictCommand(step) {
148
+ predictCommand(instruction, retryError) {
107
149
  return __awaiter(this, void 0, void 0, function* () {
108
- const image = yield this.getImageIfRequired(step.instruction);
109
- const controlCommand = yield this.inferenceClient.predictControlCommand(step.instruction, step.customElements, image);
110
- if (step.secretText !== undefined) {
111
- controlCommand.setTextToBeTyped(step.secretText);
150
+ const snapshot = yield this.buildSnapshot(instruction.value);
151
+ if (retryError !== undefined)
152
+ this.stepReporter.onStepRetry(snapshot, retryError);
153
+ else
154
+ this.stepReporter.onStepBegin(snapshot);
155
+ const controlCommand = yield this.inferenceClient.predictControlCommand(instruction.value, instruction.customElements, snapshot.screenshot);
156
+ if (instruction.secretText !== undefined) {
157
+ controlCommand.setTextToBeTyped(instruction.secretText);
112
158
  }
113
159
  return controlCommand;
114
160
  });
@@ -1,6 +1,6 @@
1
1
  import { HttpClientGot } from '../utils/http/http-client-got';
2
2
  import { ControlCommand } from '../core/ui-control-commands';
3
- import { CustomElement } from '../core/model/test-case-dto';
3
+ import { CustomElement } from '../core/model/custom-element';
4
4
  import { Annotation } from '../core/annotation/annotation';
5
5
  import { DetectedElement } from '../core/model/annotation-result/detected-element';
6
6
  import { ModelCompositionBranch } from './model-composition-branch';
@@ -0,0 +1,132 @@
1
+ import { DetectedElement } from "@/core/model/annotation-result/detected-element";
2
+ import { CustomElement } from "@/core/model/custom-element";
3
+ export interface Snapshot {
4
+ readonly createdAt: Date;
5
+ readonly screenshot?: string | undefined;
6
+ readonly detectedElements?: Readonly<Readonly<DetectedElement>>[] | undefined;
7
+ }
8
+ export interface Instruction {
9
+ readonly value: string;
10
+ readonly valueHumanReadable: string;
11
+ readonly customElements?: Readonly<Readonly<CustomElement>>[];
12
+ readonly secretText?: string | undefined;
13
+ }
14
+ export interface Step {
15
+ readonly instruction: Readonly<Instruction>;
16
+ readonly status: StepStatus;
17
+ /**
18
+ * A snapshot of the state of the screen before the step is ran which is nearly immediately after the call to `.exec()`
19
+ */
20
+ readonly begin?: Snapshot | undefined;
21
+ /**
22
+ * The duration of the step in milliseconds based on the start and end time. If the step is still running, this property is undefined.
23
+ */
24
+ readonly duration?: number | undefined;
25
+ /**
26
+ * A snapshot of the state of the screen after the step has been run. If the step is still running or still pending, this property is undefined.
27
+ */
28
+ readonly end?: Snapshot | undefined;
29
+ /**
30
+ * When a step failed or is erroneous, this property contains the error.
31
+ */
32
+ readonly error?: Error | undefined;
33
+ readonly runs: Readonly<StepRun[]>;
34
+ readonly retries: Readonly<StepRun[]>;
35
+ readonly retryCount: number;
36
+ readonly firstRun?: StepRun | undefined;
37
+ readonly lastRun?: StepRun | undefined;
38
+ /**
39
+ * retryCount > 0.
40
+ */
41
+ readonly flaky: boolean;
42
+ }
43
+ export interface StepRun {
44
+ readonly status: StepStatus;
45
+ readonly begin?: Snapshot | undefined;
46
+ readonly end?: Snapshot | undefined;
47
+ readonly duration?: number | undefined;
48
+ readonly error?: Error | undefined;
49
+ }
50
+ declare class askuiStep implements Step {
51
+ instruction: Instruction;
52
+ runs: Readonly<StepRun[]>;
53
+ constructor(instruction: Instruction);
54
+ get status(): StepStatus;
55
+ get begin(): Snapshot | undefined;
56
+ get end(): Snapshot | undefined;
57
+ get error(): Error | undefined;
58
+ get retries(): StepRun[];
59
+ get retryCount(): number;
60
+ get firstRun(): StepRun | undefined;
61
+ get lastRun(): StepRun | undefined;
62
+ get flaky(): boolean;
63
+ get duration(): number | undefined;
64
+ onBegin(snapshot: Snapshot): askuiStep;
65
+ onRetry(snapshot: Snapshot, error: Error): askuiStep;
66
+ onEnd(snapshot: Snapshot, error?: Error): askuiStep;
67
+ private determineLastRunStatus;
68
+ }
69
+ /**
70
+ * - `passed`: the step passed
71
+ * - `failed`: the step failed because of a failed (implicit/explicit) assertion, e.g., an element could not be found
72
+ * - `pending`: the step is waiting for a previous step to pass
73
+ * - `running`: the step is currently running (including retries)
74
+ * - `skipped`: the step was skipped, e.g., because a previous step failed or because workflow was skipped
75
+ * - `erroneous`: the step could not be run because of a runtime error, e.g., the user has no usage left, response of inference backend cannot be processed, e.g., because lib version is outdated, etc. (currently not supported, everything "failed")
76
+ */
77
+ export declare type StepStatus = 'passed' | 'failed' | 'pending' | 'running' | 'erroneous';
78
+ export declare type StepStatusEnd = 'passed' | 'failed' | 'erroneous';
79
+ /**
80
+ * Can be used to report on a step run.
81
+ *
82
+ * The reporter is an interface (instead of a class) so that the it may be implemented by a class that already extends another class, e.g., the reporter of a test framework.
83
+ */
84
+ export interface Reporter {
85
+ config?: ReporterConfig;
86
+ onStepBegin?(step: Step): Promise<void>;
87
+ onStepRetry?(step: Step): Promise<void>;
88
+ onStepEnd?(step: Step): Promise<void>;
89
+ }
90
+ export declare type SnapshotDetailLevel =
91
+ /**
92
+ * Details of snapshot, e.g., screenshot or detected elements, may or may not be available depending on if they are required by the step. There are not guarantees made.
93
+ */
94
+ 'required' |
95
+ /**
96
+ * Details are available when the step fails, e.g., for debugging. Includes everything of required.
97
+ */
98
+ 'onFailure' |
99
+ /**
100
+ * Details are available also when the command is started, e.g., for detecting why a certain element was interacted with. Includes everything of onFailure.
101
+ */
102
+ 'begin' |
103
+ /**
104
+ * Details are available always, e.g., before and after a step has been run no matter if it failed or not for debugging.
105
+ */
106
+ 'always';
107
+ export interface ReporterConfig {
108
+ withScreenshots?: SnapshotDetailLevel;
109
+ withDetectedElements?: SnapshotDetailLevel;
110
+ }
111
+ export declare const DEFAULT_REPORTER: {
112
+ config: {
113
+ readonly withScreenshots: "onFailure";
114
+ readonly withDetectedElements: "onFailure";
115
+ };
116
+ onStepBegin: (_step: Step) => Promise<void>;
117
+ onStepRetry: (_step: Step) => Promise<void>;
118
+ onStepEnd: (_step: Step) => Promise<void>;
119
+ };
120
+ export declare class StepReporter {
121
+ private reporter;
122
+ currentStep?: askuiStep | undefined;
123
+ constructor(reporter: Required<Reporter> & {
124
+ config: Required<ReporterConfig>;
125
+ });
126
+ get config(): Required<ReporterConfig>;
127
+ resetStep(instruction: Instruction): void;
128
+ onStepBegin(snapshot: Snapshot): Promise<void>;
129
+ onStepRetry(snapshot: Snapshot, error: Error): Promise<void>;
130
+ onStepEnd(snapshot: Snapshot, error?: Error): Promise<void>;
131
+ }
132
+ export {};
@@ -0,0 +1,142 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ // retries could be modeled as totally new steps only that we set the retry no at the beginning, it is undefined if there is no retry or 0 --> user could filter out the retries for the report and has to get the last retry to find out when the step actually ended and the snapshot at that point in time
11
+ // Where do I save the error of the first step, what state does the first step have?
12
+ // We could point back from retry to original step, but then we have to save the original step in the retry step, which is not nice
13
+ // retry should be handled like completely new step but the state of the whole state is not failed --> if a passed step can have an error, then this is fine
14
+ // how do we determine if it is erroneous or failed?
15
+ class askuiStep {
16
+ constructor(instruction) {
17
+ this.instruction = instruction;
18
+ this.runs = [];
19
+ }
20
+ get status() {
21
+ var _a, _b;
22
+ return (_b = (_a = this.lastRun) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 'pending';
23
+ }
24
+ get begin() {
25
+ var _a;
26
+ return (_a = this.firstRun) === null || _a === void 0 ? void 0 : _a.begin;
27
+ }
28
+ get end() {
29
+ var _a;
30
+ return (_a = this.lastRun) === null || _a === void 0 ? void 0 : _a.end;
31
+ }
32
+ get error() {
33
+ var _a;
34
+ return (_a = this.lastRun) === null || _a === void 0 ? void 0 : _a.error;
35
+ }
36
+ get retries() {
37
+ var _a, _b;
38
+ return (_b = (_a = this.runs) === null || _a === void 0 ? void 0 : _a.slice(1)) !== null && _b !== void 0 ? _b : [];
39
+ }
40
+ get retryCount() {
41
+ var _a, _b;
42
+ return (_b = (_a = this.retries) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
43
+ }
44
+ get firstRun() {
45
+ var _a;
46
+ return (_a = this.runs) === null || _a === void 0 ? void 0 : _a[0];
47
+ }
48
+ get lastRun() {
49
+ var _a;
50
+ return (_a = this.runs) === null || _a === void 0 ? void 0 : _a[this.runs.length - 1];
51
+ }
52
+ get flaky() {
53
+ return this.retryCount > 0;
54
+ }
55
+ get duration() {
56
+ if (this.begin !== undefined && this.end !== undefined) {
57
+ return this.end.createdAt.getTime() - this.begin.createdAt.getTime();
58
+ }
59
+ return undefined;
60
+ }
61
+ onBegin(snapshot) {
62
+ this.runs = [...this.runs, {
63
+ status: 'running',
64
+ begin: snapshot,
65
+ }];
66
+ return this;
67
+ }
68
+ onRetry(snapshot, error) {
69
+ this.onEnd(snapshot, error);
70
+ this.onBegin(snapshot);
71
+ return this;
72
+ }
73
+ onEnd(snapshot, error) {
74
+ this.runs = [...this.runs.slice(0, -1), Object.assign(Object.assign({}, this.lastRun), { status: this.determineLastRunStatus(error), end: snapshot, error, duration: snapshot.createdAt.getTime() - this.lastRun.begin.createdAt.getTime() })];
75
+ return this;
76
+ }
77
+ determineLastRunStatus(error) {
78
+ if (error !== undefined) {
79
+ return 'failed';
80
+ }
81
+ return 'passed';
82
+ }
83
+ }
84
+ export const DEFAULT_REPORTER = {
85
+ config: {
86
+ withScreenshots: 'onFailure',
87
+ withDetectedElements: 'onFailure',
88
+ },
89
+ onStepBegin: (_step) => {
90
+ return Promise.resolve();
91
+ },
92
+ onStepRetry: (_step) => {
93
+ return Promise.resolve();
94
+ },
95
+ onStepEnd: (_step) => {
96
+ return Promise.resolve();
97
+ },
98
+ };
99
+ export class StepReporter {
100
+ constructor(reporter) {
101
+ this.reporter = reporter;
102
+ }
103
+ get config() {
104
+ return this.reporter.config;
105
+ }
106
+ resetStep(instruction) {
107
+ this.currentStep = new askuiStep(instruction);
108
+ }
109
+ onStepBegin(snapshot) {
110
+ var _a, _b;
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ if (this.currentStep === undefined)
113
+ throw new Error('Cannot begin step if step is undefined.');
114
+ if (this.currentStep.status !== 'pending')
115
+ throw new Error('Cannot begin step that is not pending.');
116
+ this.currentStep.onBegin(snapshot);
117
+ yield ((_b = (_a = this.reporter).onStepBegin) === null || _b === void 0 ? void 0 : _b.call(_a, this.currentStep));
118
+ });
119
+ }
120
+ onStepRetry(snapshot, error) {
121
+ var _a, _b;
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ if (this.currentStep === undefined)
124
+ throw new Error('Cannot retry step if step is undefined.');
125
+ if (this.currentStep.status !== 'running')
126
+ throw new Error('Cannot retry step that has not been running.');
127
+ this.currentStep.onRetry(snapshot, error);
128
+ yield ((_b = (_a = this.reporter).onStepRetry) === null || _b === void 0 ? void 0 : _b.call(_a, this.currentStep));
129
+ });
130
+ }
131
+ onStepEnd(snapshot, error) {
132
+ var _a, _b;
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ if (this.currentStep === undefined)
135
+ throw new Error('Cannot end step if step is undefined.');
136
+ if (this.currentStep.status !== 'running')
137
+ throw new Error('Cannot end step that has not been running.');
138
+ this.currentStep.onEnd(snapshot, error);
139
+ yield ((_b = (_a = this.reporter).onStepEnd) === null || _b === void 0 ? void 0 : _b.call(_a, this.currentStep));
140
+ });
141
+ }
142
+ }
@@ -0,0 +1,14 @@
1
+ import { ClientArgs, ClientArgsWithDefaults } from './ui-controller-client-interface';
2
+ import { ExecutionRuntime } from './execution-runtime';
3
+ import { StepReporter } from '../core/reporting';
4
+ export declare class UiControlClientDependencyBuilder {
5
+ private static buildHttpClient;
6
+ private static buildInferenceClient;
7
+ private static buildUiControllerClient;
8
+ static build(clientArgs: ClientArgsWithDefaults): Promise<{
9
+ executionRuntime: ExecutionRuntime;
10
+ stepReporter: StepReporter;
11
+ }>;
12
+ private static buildReporter;
13
+ static getClientArgsWithDefaults(clientArgs: ClientArgs): Promise<ClientArgsWithDefaults>;
14
+ }
@@ -0,0 +1,68 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { HttpClientGot } from '../utils/http/http-client-got';
11
+ import { UiControllerClient } from './ui-controller-client';
12
+ import { InferenceClient } from './inference-client';
13
+ import { envCredentials } from './read-environment-credentials';
14
+ import { Analytics } from '../utils/analytics';
15
+ import { envProxyAgents } from '../utils/proxy/proxy-builder';
16
+ import { AnnotationLevel } from './annotation-level';
17
+ import { ExecutionRuntime } from './execution-runtime';
18
+ import { DEFAULT_REPORTER, StepReporter, } from '../core/reporting';
19
+ export class UiControlClientDependencyBuilder {
20
+ static buildHttpClient(clientArgs) {
21
+ var _a;
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const analytics = new Analytics();
24
+ const analyticsHeaders = yield analytics.getAnalyticsHeaders();
25
+ const analyticsCookies = yield analytics.getAnalyticsCookies();
26
+ return new HttpClientGot((_a = clientArgs.credentials) === null || _a === void 0 ? void 0 : _a.token, analyticsHeaders, analyticsCookies, clientArgs.proxyAgents);
27
+ });
28
+ }
29
+ static buildInferenceClient(clientArgs) {
30
+ var _a;
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const httpClient = yield UiControlClientDependencyBuilder.buildHttpClient(clientArgs);
33
+ return new InferenceClient(clientArgs.inferenceServerUrl, httpClient, clientArgs.resize, (_a = clientArgs.credentials) === null || _a === void 0 ? void 0 : _a.workspaceId, clientArgs.modelComposition);
34
+ });
35
+ }
36
+ static buildUiControllerClient(clientArgs) {
37
+ return new UiControllerClient(clientArgs.uiControllerUrl);
38
+ }
39
+ static build(clientArgs) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const uiControllerClient = UiControlClientDependencyBuilder.buildUiControllerClient(clientArgs);
42
+ const inferenceClient = yield UiControlClientDependencyBuilder.buildInferenceClient(clientArgs);
43
+ const stepReporter = new StepReporter(clientArgs.reporter);
44
+ return {
45
+ executionRuntime: new ExecutionRuntime(uiControllerClient, inferenceClient, stepReporter),
46
+ stepReporter,
47
+ };
48
+ });
49
+ }
50
+ static buildReporter(reporterArg) {
51
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
52
+ return {
53
+ config: {
54
+ withScreenshots: (_b = (_a = reporterArg === null || reporterArg === void 0 ? void 0 : reporterArg.config) === null || _a === void 0 ? void 0 : _a.withScreenshots) !== null && _b !== void 0 ? _b : DEFAULT_REPORTER.config.withScreenshots,
55
+ withDetectedElements: (_d = (_c = reporterArg === null || reporterArg === void 0 ? void 0 : reporterArg.config) === null || _c === void 0 ? void 0 : _c.withDetectedElements) !== null && _d !== void 0 ? _d : DEFAULT_REPORTER.config.withDetectedElements,
56
+ },
57
+ onStepBegin: (_f = (_e = reporterArg === null || reporterArg === void 0 ? void 0 : reporterArg.onStepBegin) === null || _e === void 0 ? void 0 : _e.bind(reporterArg)) !== null && _f !== void 0 ? _f : DEFAULT_REPORTER.onStepBegin.bind(DEFAULT_REPORTER),
58
+ onStepRetry: (_h = (_g = reporterArg === null || reporterArg === void 0 ? void 0 : reporterArg.onStepRetry) === null || _g === void 0 ? void 0 : _g.bind(reporterArg)) !== null && _h !== void 0 ? _h : DEFAULT_REPORTER.onStepRetry.bind(DEFAULT_REPORTER),
59
+ onStepEnd: (_k = (_j = reporterArg === null || reporterArg === void 0 ? void 0 : reporterArg.onStepEnd) === null || _j === void 0 ? void 0 : _j.bind(reporterArg)) !== null && _k !== void 0 ? _k : DEFAULT_REPORTER.onStepEnd.bind(DEFAULT_REPORTER),
60
+ };
61
+ }
62
+ static getClientArgsWithDefaults(clientArgs) {
63
+ var _a, _b, _c, _d, _e;
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ return Object.assign(Object.assign({}, clientArgs), { uiControllerUrl: (_a = clientArgs.uiControllerUrl) !== null && _a !== void 0 ? _a : 'http://127.0.0.1:6769', inferenceServerUrl: (_b = clientArgs.inferenceServerUrl) !== null && _b !== void 0 ? _b : 'https://inference.askui.com', annotationLevel: (_c = clientArgs.annotationLevel) !== null && _c !== void 0 ? _c : AnnotationLevel.DISABLED, credentials: (_d = clientArgs.credentials) !== null && _d !== void 0 ? _d : envCredentials(), proxyAgents: (_e = clientArgs.proxyAgents) !== null && _e !== void 0 ? _e : yield envProxyAgents(), reporter: UiControlClientDependencyBuilder.buildReporter(clientArgs.reporter) });
66
+ });
67
+ }
68
+ }
@@ -1,28 +1,44 @@
1
- import { CustomElementJson } from '../core/model/test-case-dto';
1
+ import { CustomElementJson } from '../core/model/custom-element-json';
2
2
  import { Exec, Executable, FluentFilters, ApiCommands } from './dsl';
3
3
  import { UiControllerClientConnectionState } from './ui-controller-client-connection-state';
4
4
  import { Annotation } from '../core/annotation/annotation';
5
5
  import { AnnotationRequest } from '../core/model/annotation-result/annotation-interface';
6
- import { ClientArgs } from './ui-controller-client-interface';
7
6
  import { DetectedElement } from '../core/model/annotation-result/detected-element';
7
+ import { ClientArgs } from './ui-controller-client-interface';
8
8
  export declare class UiControlClient extends ApiCommands {
9
- private httpClient;
10
- private clientArgs;
11
- private workspaceId?;
12
- private _uiControllerClient?;
9
+ private config;
10
+ private executionRuntime;
11
+ private stepReporter;
13
12
  private constructor();
14
13
  static build(clientArgs?: ClientArgs): Promise<UiControlClient>;
15
- private get uiControllerClient();
16
- private get inferenceClient();
17
- private get executionRuntime();
18
- private annotateByDefault;
14
+ /**
15
+ * Connects to the askui UI Controller.
16
+ */
19
17
  connect(): Promise<UiControllerClientConnectionState>;
18
+ /**
19
+ * Disconnects from the askui UI Controller.
20
+ */
21
+ disconnect(): void;
22
+ /**
23
+ * Disconnects from the askui UI Controller.
24
+ *
25
+ * @deprecated Use {@link disconnect} instead.
26
+ */
27
+ close(): void;
28
+ startVideoRecording(): Promise<void>;
29
+ stopVideoRecording(): Promise<void>;
30
+ readVideoRecording(): Promise<string>;
31
+ private shouldWriteAnntotationAfterCommandExecution;
32
+ private shouldAnnotateAfterCommandExecution;
33
+ private afterCommandExecution;
20
34
  annotate(annotationRequest?: AnnotationRequest): Promise<Annotation>;
21
35
  annotateInteractively(): Promise<void>;
22
36
  private escapeSeparatorString;
23
- fluentCommandExecutor(instruction: string, customElementJson?: CustomElementJson[]): Promise<void>;
37
+ private buildInstruction;
38
+ fluentCommandExecutor(instructionString: string, customElementJson?: CustomElementJson[]): Promise<void>;
24
39
  getterExecutor(instruction: string, customElementJson?: CustomElementJson[]): Promise<DetectedElement[]>;
25
40
  private secretText;
41
+ private getAndResetSecretText;
26
42
  /**
27
43
  * Types a text inside the filtered element.
28
44
  *
@@ -76,8 +92,4 @@ export declare class UiControlClient extends ApiCommands {
76
92
  * @return {Executable}
77
93
  */
78
94
  waitFor(delayInMs: number): Executable;
79
- /**
80
- * Closes the connection to the askui UI Controller
81
- */
82
- close(): void;
83
95
  }