askui 0.3.2 → 0.4.0

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 (52) hide show
  1. package/README.md +6 -12
  2. package/dist/cjs/core/annotation/annotation-writer.js +2 -4
  3. package/dist/cjs/core/annotation/annotation.d.ts +3 -4
  4. package/dist/cjs/core/annotation/annotation.js +5 -4
  5. package/dist/cjs/core/inference-response/inference-response.d.ts +15 -0
  6. package/dist/cjs/core/inference-response/inference-response.js +25 -0
  7. package/dist/cjs/core/model/annotation-result/boundary-box.d.ts +23 -0
  8. package/dist/cjs/core/model/annotation-result/boundary-box.js +27 -0
  9. package/dist/cjs/core/model/annotation-result/detected-element.d.ts +9 -3
  10. package/dist/cjs/core/model/annotation-result/detected-element.js +10 -4
  11. package/dist/cjs/core/ui-control-commands/control-command.d.ts +1 -1
  12. package/dist/cjs/core/ui-control-commands/control-command.js +2 -1
  13. package/dist/cjs/core/ui-control-commands/index.d.ts +1 -0
  14. package/dist/cjs/core/ui-control-commands/index.js +3 -1
  15. package/dist/cjs/execution/dsl.d.ts +691 -2
  16. package/dist/cjs/execution/dsl.js +968 -7
  17. package/dist/cjs/execution/dsl.spec.js +4 -4
  18. package/dist/cjs/execution/execution-runtime.d.ts +2 -0
  19. package/dist/cjs/execution/execution-runtime.js +11 -1
  20. package/dist/cjs/execution/inference-client.d.ts +3 -0
  21. package/dist/cjs/execution/inference-client.js +28 -12
  22. package/dist/cjs/execution/inference-response-error.d.ts +2 -0
  23. package/dist/cjs/execution/inference-response-error.js +6 -0
  24. package/dist/cjs/execution/ui-control-client.d.ts +5 -3
  25. package/dist/cjs/execution/ui-control-client.js +10 -2
  26. package/dist/cjs/utils/http/http-client-got.js +5 -1
  27. package/dist/esm/core/annotation/annotation-writer.js +2 -4
  28. package/dist/esm/core/annotation/annotation.d.ts +3 -4
  29. package/dist/esm/core/annotation/annotation.js +5 -4
  30. package/dist/esm/core/inference-response/inference-response.d.ts +15 -0
  31. package/dist/esm/core/inference-response/inference-response.js +21 -0
  32. package/dist/esm/core/model/annotation-result/boundary-box.d.ts +23 -0
  33. package/dist/esm/core/model/annotation-result/boundary-box.js +27 -0
  34. package/dist/esm/core/model/annotation-result/detected-element.d.ts +9 -3
  35. package/dist/esm/core/model/annotation-result/detected-element.js +10 -4
  36. package/dist/esm/core/ui-control-commands/control-command.d.ts +1 -1
  37. package/dist/esm/core/ui-control-commands/control-command.js +2 -1
  38. package/dist/esm/core/ui-control-commands/index.d.ts +1 -0
  39. package/dist/esm/core/ui-control-commands/index.js +1 -0
  40. package/dist/esm/execution/dsl.d.ts +691 -2
  41. package/dist/esm/execution/dsl.js +962 -6
  42. package/dist/esm/execution/dsl.spec.js +4 -4
  43. package/dist/esm/execution/execution-runtime.d.ts +2 -0
  44. package/dist/esm/execution/execution-runtime.js +11 -1
  45. package/dist/esm/execution/inference-client.d.ts +3 -0
  46. package/dist/esm/execution/inference-client.js +29 -13
  47. package/dist/esm/execution/inference-response-error.d.ts +2 -0
  48. package/dist/esm/execution/inference-response-error.js +2 -0
  49. package/dist/esm/execution/ui-control-client.d.ts +5 -3
  50. package/dist/esm/execution/ui-control-client.js +11 -3
  51. package/dist/esm/utils/http/http-client-got.js +5 -1
  52. package/package.json +1 -1
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { FluentCommand } from './dsl';
11
11
  class TestCommand extends FluentCommand {
12
12
  // eslint-disable-next-line class-methods-use-this
13
- exec(instruction, customElements) {
13
+ fluentCommandExecutor(instruction, customElements) {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
15
  // eslint-disable-next-line no-console
16
16
  console.log(`${instruction} ${customElements}`);
@@ -22,14 +22,14 @@ describe('DSL', () => {
22
22
  describe('custom element', () => {
23
23
  test('should call exec function with zero custom element', () => __awaiter(void 0, void 0, void 0, function* () {
24
24
  const underTest = new TestCommand();
25
- const testCommandSpy = jest.spyOn(underTest, 'exec');
25
+ const testCommandSpy = jest.spyOn(underTest, 'fluentCommandExecutor');
26
26
  yield underTest.click().button()
27
27
  .exec();
28
28
  expect(testCommandSpy).toHaveBeenCalledWith('Click on button', []);
29
29
  }));
30
30
  test('should call exec function with one custom element', () => __awaiter(void 0, void 0, void 0, function* () {
31
31
  const underTest = new TestCommand();
32
- const testCommandSpy = jest.spyOn(underTest, 'exec');
32
+ const testCommandSpy = jest.spyOn(underTest, 'fluentCommandExecutor');
33
33
  yield underTest.click().customElement({
34
34
  customImage: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
35
35
  imageCompareFormat: 'grayscale',
@@ -44,7 +44,7 @@ describe('DSL', () => {
44
44
  }));
45
45
  test('should call exec function with two custom element', () => __awaiter(void 0, void 0, void 0, function* () {
46
46
  const underTest = new TestCommand();
47
- const testCommandSpy = jest.spyOn(underTest, 'exec');
47
+ const testCommandSpy = jest.spyOn(underTest, 'fluentCommandExecutor');
48
48
  yield underTest.click().customElement({
49
49
  customImage: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
50
50
  imageCompareFormat: 'grayscale',
@@ -3,6 +3,7 @@ import { UiControllerClient } from './ui-controller-client';
3
3
  import { InferenceClient } from './inference-client';
4
4
  import { Annotation } from '../core/annotation/annotation';
5
5
  import { CustomElementJson } from '../core/model/test-case-dto/custom-element-json';
6
+ import { DetectedElement } from '../core/model/annotation-result/detected-element';
6
7
  export declare class ExecutionRuntime {
7
8
  private uiControllerClient;
8
9
  private inferenceClient;
@@ -25,5 +26,6 @@ export declare class ExecutionRuntime {
25
26
  private predictCommand;
26
27
  annotateInteractively(): Promise<void>;
27
28
  takeScreenshotIfImageisNotProvided(imagePath?: string): Promise<string>;
29
+ getDetectedElements(instruction: string, customElementJson?: CustomElementJson[]): Promise<DetectedElement[]>;
28
30
  annotateImage(imagePath?: string, customElementJson?: CustomElementJson[]): Promise<Annotation>;
29
31
  }
@@ -116,7 +116,7 @@ export class ExecutionRuntime {
116
116
  annotateInteractively() {
117
117
  return __awaiter(this, void 0, void 0, function* () {
118
118
  const annotationResponse = yield this.annotateImage();
119
- yield this.uiControllerClient.annotateInteractively(annotationResponse.objects, annotationResponse.image);
119
+ yield this.uiControllerClient.annotateInteractively(annotationResponse.detected_elements, annotationResponse.image);
120
120
  });
121
121
  }
122
122
  takeScreenshotIfImageisNotProvided(imagePath) {
@@ -132,6 +132,16 @@ export class ExecutionRuntime {
132
132
  return base64Image;
133
133
  });
134
134
  }
135
+ getDetectedElements(instruction, customElementJson) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ let customElements = [];
138
+ const base64Image = yield this.takeScreenshotIfImageisNotProvided();
139
+ if (customElementJson !== undefined) {
140
+ customElements = yield CustomElement.fromJsonListWithImagePathOrImage(customElementJson);
141
+ }
142
+ return this.inferenceClient.getDetectedElements(instruction, base64Image, customElements);
143
+ });
144
+ }
135
145
  annotateImage(imagePath, customElementJson) {
136
146
  return __awaiter(this, void 0, void 0, function* () {
137
147
  let customElements = [];
@@ -2,6 +2,7 @@ import { HttpClientGot } from '../utils/http/http-client-got';
2
2
  import { ControlCommand } from '../core/ui-control-commands';
3
3
  import { CustomElement } from '../core/model/test-case-dto';
4
4
  import { Annotation } from '../core/annotation/annotation';
5
+ import { DetectedElement } from '../core/model/annotation-result/detected-element';
5
6
  export declare class InferenceClient {
6
7
  baseUrl: string;
7
8
  httpClient: HttpClientGot;
@@ -11,6 +12,8 @@ export declare class InferenceClient {
11
12
  constructor(baseUrl: string, httpClient: HttpClientGot, workspaceId?: string | undefined, apiVersion?: string);
12
13
  isImageRequired(instruction: string): Promise<boolean>;
13
14
  private resizeIfNeeded;
15
+ inference(customElements?: CustomElement[], image?: string, instruction?: string): Promise<ControlCommand | Annotation>;
14
16
  predictControlCommand(instruction: string, customElements?: CustomElement[], image?: string): Promise<ControlCommand>;
17
+ getDetectedElements(instruction: string, image: string, customElements?: CustomElement[]): Promise<DetectedElement[]>;
15
18
  predictImageAnnotation(image: string, customElements?: CustomElement[]): Promise<Annotation>;
16
19
  }
@@ -8,11 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import urljoin from 'url-join';
11
- import { ControlCommand } from '../core/ui-control-commands';
11
+ import { ControlCommand, InferenceResponse } from '../core/ui-control-commands';
12
12
  import { Annotation } from '../core/annotation/annotation';
13
13
  import { resizeBase64ImageWithSameRatio } from '../utils/transformations';
14
+ import { InferenceResponseError } from './inference-response-error';
14
15
  export class InferenceClient {
15
- constructor(baseUrl, httpClient, workspaceId, apiVersion = 'v2') {
16
+ constructor(baseUrl, httpClient, workspaceId, apiVersion = 'v3') {
16
17
  this.baseUrl = baseUrl;
17
18
  this.httpClient = httpClient;
18
19
  this.workspaceId = workspaceId;
@@ -39,7 +40,7 @@ export class InferenceClient {
39
40
  return resizeBase64ImageWithSameRatio(image);
40
41
  });
41
42
  }
42
- predictControlCommand(instruction, customElements = [], image) {
43
+ inference(customElements = [], image, instruction) {
43
44
  return __awaiter(this, void 0, void 0, function* () {
44
45
  const resizedImage = yield this.resizeIfNeeded(customElements, image);
45
46
  const httpBody = {
@@ -47,21 +48,36 @@ export class InferenceClient {
47
48
  instruction,
48
49
  customElements,
49
50
  };
50
- const url = urljoin(this.url, 'predict-command');
51
+ const url = urljoin(this.url, 'inference');
51
52
  const httpResponse = yield this.httpClient.post(url, httpBody);
52
- return ControlCommand.fromJson(httpResponse, resizedImage.resizeRatio);
53
+ return InferenceResponse.fromJson(httpResponse, resizedImage.resizeRatio, image);
54
+ });
55
+ }
56
+ predictControlCommand(instruction, customElements = [], image) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const inferenceResponse = yield this.inference(customElements, image, instruction);
59
+ if (!(inferenceResponse instanceof ControlCommand)) {
60
+ throw new InferenceResponseError('Internal Error. Can not execute command');
61
+ }
62
+ return inferenceResponse;
63
+ });
64
+ }
65
+ getDetectedElements(instruction, image, customElements = []) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const inferenceResponse = yield this.inference(customElements, image, instruction);
68
+ if (!(inferenceResponse instanceof Annotation)) {
69
+ throw new InferenceResponseError('Internal Error. Unable to get the detected elements');
70
+ }
71
+ return inferenceResponse.detected_elements;
53
72
  });
54
73
  }
55
74
  predictImageAnnotation(image, customElements = []) {
56
75
  return __awaiter(this, void 0, void 0, function* () {
57
- const resizedImage = yield this.resizeIfNeeded(customElements, image);
58
- const httpBody = {
59
- image: resizedImage.base64Image,
60
- customElements,
61
- };
62
- const url = urljoin(this.url, 'annotate', '?format=json');
63
- const httpResponse = yield this.httpClient.post(url, httpBody);
64
- return Annotation.fromJson(Object.assign(Object.assign({}, httpResponse), { image }), resizedImage.resizeRatio);
76
+ const inferenceResponse = yield this.inference(customElements, image);
77
+ if (!(inferenceResponse instanceof Annotation)) {
78
+ throw new InferenceResponseError('Internal Error. Can not execute annotation');
79
+ }
80
+ return inferenceResponse;
65
81
  });
66
82
  }
67
83
  }
@@ -0,0 +1,2 @@
1
+ export declare class InferenceResponseError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export class InferenceResponseError extends Error {
2
+ }
@@ -1,10 +1,11 @@
1
1
  import { CustomElementJson } from '../core/model/test-case-dto';
2
- import { Exec, Executable, FluentCommand, FluentFilters } from './dsl';
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
6
  import { ClientArgs } from './ui-controller-client-interface';
7
- export declare class UiControlClient extends FluentCommand {
7
+ import { DetectedElement } from '../core/model/annotation-result/detected-element';
8
+ export declare class UiControlClient extends ApiCommands {
8
9
  private httpClient;
9
10
  private clientArgs;
10
11
  private workspaceId?;
@@ -19,7 +20,8 @@ export declare class UiControlClient extends FluentCommand {
19
20
  annotate(annotationRequest?: AnnotationRequest): Promise<Annotation>;
20
21
  annotateInteractively(): Promise<void>;
21
22
  private escapeSeparatorString;
22
- exec(instruction: string, customElementJson?: CustomElementJson[]): Promise<void>;
23
+ fluentCommandExecutor(instruction: string, customElementJson?: CustomElementJson[]): Promise<void>;
24
+ getterExecutor(instruction: string, customElementJson?: CustomElementJson[]): Promise<DetectedElement[]>;
23
25
  private secretText;
24
26
  /**
25
27
  * Types a text inside the filtered element.
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { CustomElement } from '../core/model/test-case-dto';
11
- import { FluentCommand, Separators, } from './dsl';
11
+ import { ApiCommands, Separators, } from './dsl';
12
12
  import { HttpClientGot } from '../utils/http/http-client-got';
13
13
  import { UiControllerClient } from './ui-controller-client';
14
14
  import { ExecutionRuntime } from './execution-runtime';
@@ -21,7 +21,7 @@ import { UiControlClientError } from './ui-control-client-error';
21
21
  import { envCredentials } from './read-environment-credentials';
22
22
  import { Analytics } from '../utils/analytics';
23
23
  const getClientArgsWithDefaults = (clientArgs = {}) => (Object.assign({ uiControllerUrl: 'http://127.0.0.1:6769', inferenceServerUrl: 'https://inference.askui.com', annotationLevel: AnnotationLevel.DISABLED }, clientArgs));
24
- export class UiControlClient extends FluentCommand {
24
+ export class UiControlClient extends ApiCommands {
25
25
  constructor(httpClient, clientArgs, workspaceId) {
26
26
  super();
27
27
  this.httpClient = httpClient;
@@ -93,7 +93,7 @@ export class UiControlClient extends FluentCommand {
93
93
  escapeSeparatorString(instruction) {
94
94
  return instruction.split(Separators.STRING).join('"');
95
95
  }
96
- exec(instruction, customElementJson = []) {
96
+ fluentCommandExecutor(instruction, customElementJson = []) {
97
97
  return __awaiter(this, void 0, void 0, function* () {
98
98
  const { secretText } = this;
99
99
  const customElements = yield CustomElement.fromJsonListWithImagePathOrImage(customElementJson);
@@ -114,6 +114,14 @@ export class UiControlClient extends FluentCommand {
114
114
  }
115
115
  });
116
116
  }
117
+ getterExecutor(instruction, customElementJson = []) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const customElements = yield CustomElement.fromJsonListWithImagePathOrImage(customElementJson);
120
+ const stringWithoutSeparators = this.escapeSeparatorString(instruction);
121
+ logger.debug(stringWithoutSeparators);
122
+ return this.executionRuntime.getDetectedElements(instruction, customElements);
123
+ });
124
+ }
117
125
  /**
118
126
  * Types a text inside the filtered element.
119
127
  *
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import got from 'got';
11
11
  import { CookieJar } from 'tough-cookie';
12
+ import { logger } from '../../lib';
12
13
  import { Credentials } from './credentials';
13
14
  import { httpClientErrorHandler } from './custom-errors';
14
15
  export class HttpClientGot {
@@ -33,7 +34,10 @@ export class HttpClientGot {
33
34
  post(url, data) {
34
35
  return __awaiter(this, void 0, void 0, function* () {
35
36
  const options = this.injectHeadersAndCookies(url, { json: data, responseType: 'json', throwHttpErrors: false });
36
- const { body, statusCode } = yield got.post(url, options);
37
+ const { body, statusCode, headers } = yield got.post(url, options);
38
+ if (headers['deprecation'] !== undefined) {
39
+ logger.warn(headers['deprecation']);
40
+ }
37
41
  if (statusCode !== 200) {
38
42
  throw httpClientErrorHandler(statusCode, JSON.stringify(body));
39
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "askui",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "author": "askui GmbH <info@askui.com> (http://www.askui.com/)",
6
6
  "description": "Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on",