askui 0.7.0 → 0.7.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 (62) hide show
  1. package/dist/cjs/core/annotation/annotation-json.d.ts +5 -0
  2. package/dist/cjs/core/annotation/annotation-json.js +2 -0
  3. package/dist/cjs/core/inference-response/inference-response.d.ts +7 -11
  4. package/dist/cjs/core/inference-response/inference-response.js +8 -13
  5. package/dist/cjs/core/inference-response/invalid-model-type-error.d.ts +4 -0
  6. package/dist/cjs/core/inference-response/invalid-model-type-error.js +9 -0
  7. package/dist/cjs/core/inference-response/model-type.d.ts +1 -0
  8. package/dist/cjs/core/inference-response/model-type.js +2 -0
  9. package/dist/cjs/core/model/test-case-dto/custom-element.spec.d.ts +1 -0
  10. package/dist/cjs/core/model/test-case-dto/custom-element.spec.js +53 -0
  11. package/dist/cjs/execution/dsl.d.ts +48 -0
  12. package/dist/cjs/execution/dsl.js +72 -0
  13. package/dist/cjs/execution/dsl.spec.d.ts +1 -0
  14. package/dist/cjs/execution/dsl.spec.js +75 -0
  15. package/dist/cjs/execution/inference-client.d.ts +1 -0
  16. package/dist/cjs/execution/inference-client.js +17 -8
  17. package/dist/cjs/execution/read-environment-credentials.spec.d.ts +1 -0
  18. package/dist/cjs/execution/read-environment-credentials.spec.js +11 -0
  19. package/dist/cjs/lib/download-binaries.d.ts +1 -1
  20. package/dist/cjs/lib/download-binaries.js +42 -29
  21. package/dist/cjs/lib/ui-controller-args.spec.d.ts +1 -0
  22. package/dist/cjs/lib/ui-controller-args.spec.js +23 -0
  23. package/dist/cjs/lib/ui-controller-darwin.js +3 -3
  24. package/dist/cjs/lib/ui-controller-facade.d.ts +1 -2
  25. package/dist/cjs/lib/ui-controller-facade.js +6 -11
  26. package/dist/cjs/lib/ui-controller-linux.js +1 -1
  27. package/dist/cjs/utils/http/credentials.spec.d.ts +1 -0
  28. package/dist/cjs/utils/http/credentials.spec.js +11 -0
  29. package/dist/cjs/utils/http/http-client-got.d.ts +5 -1
  30. package/dist/cjs/utils/http/http-client-got.js +12 -4
  31. package/dist/esm/core/annotation/annotation-json.d.ts +5 -0
  32. package/dist/esm/core/annotation/annotation-json.js +1 -0
  33. package/dist/esm/core/inference-response/inference-response.d.ts +7 -11
  34. package/dist/esm/core/inference-response/inference-response.js +8 -13
  35. package/dist/esm/core/inference-response/invalid-model-type-error.d.ts +4 -0
  36. package/dist/esm/core/inference-response/invalid-model-type-error.js +5 -0
  37. package/dist/esm/core/inference-response/model-type.d.ts +1 -0
  38. package/dist/esm/core/inference-response/model-type.js +1 -0
  39. package/dist/esm/core/model/test-case-dto/custom-element.spec.d.ts +1 -0
  40. package/dist/esm/core/model/test-case-dto/custom-element.spec.js +51 -0
  41. package/dist/esm/execution/dsl.d.ts +48 -0
  42. package/dist/esm/execution/dsl.js +72 -0
  43. package/dist/esm/execution/dsl.spec.d.ts +1 -0
  44. package/dist/esm/execution/dsl.spec.js +73 -0
  45. package/dist/esm/execution/inference-client.d.ts +1 -0
  46. package/dist/esm/execution/inference-client.js +17 -8
  47. package/dist/esm/execution/read-environment-credentials.spec.d.ts +1 -0
  48. package/dist/esm/execution/read-environment-credentials.spec.js +9 -0
  49. package/dist/esm/lib/download-binaries.d.ts +1 -1
  50. package/dist/esm/lib/download-binaries.js +40 -27
  51. package/dist/esm/lib/ui-controller-args.spec.d.ts +1 -0
  52. package/dist/esm/lib/ui-controller-args.spec.js +21 -0
  53. package/dist/esm/lib/ui-controller-darwin.js +3 -3
  54. package/dist/esm/lib/ui-controller-facade.d.ts +1 -2
  55. package/dist/esm/lib/ui-controller-facade.js +7 -12
  56. package/dist/esm/lib/ui-controller-linux.js +1 -1
  57. package/dist/esm/utils/http/credentials.spec.d.ts +1 -0
  58. package/dist/esm/utils/http/credentials.spec.js +9 -0
  59. package/dist/esm/utils/http/http-client-got.d.ts +5 -1
  60. package/dist/esm/utils/http/http-client-got.js +12 -4
  61. package/dist/example_projects_templates/typescript_jest/test/my-first-askui-test-suite.test.ts +5 -6
  62. package/package.json +1 -1
@@ -1,7 +1,18 @@
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
+ };
1
10
  import fs from 'fs';
2
11
  import got from 'got';
3
12
  import os from 'os';
4
13
  import path from 'path';
14
+ import { promisify } from 'util';
15
+ import stream from 'stream';
5
16
  import { getPathToNodeModulesRoot } from '../utils/path';
6
17
  import { logger } from './logger';
7
18
  var SupportedPlatform;
@@ -25,10 +36,13 @@ export function platform() {
25
36
  }
26
37
  throw new Error(`Platform "${pf}" is not supported.`);
27
38
  }
28
- function buildBinaryNotAvailbleError(binaryVersion) {
29
- return new Error(`It seems that the UI Controller version "${binaryVersion}" for your system "${platform()} ${os.arch}" is not availble, Please contact as at info@askui.com for more information`);
39
+ function buildBinaryNotAvailableError(binaryVersion) {
40
+ return new Error(`There was an error during downloading and creating the askui UI Controller. You can try a fresh install.
41
+ If you specified a binary version it is possible that the askui UI Controller version "${binaryVersion}"
42
+ for your system "${platform()} ${os.arch}" is not available.
43
+ If this problem still occurs, please contact us at info@askui.com for more information`);
30
44
  }
31
- export function getBinaryPath(version) {
45
+ export function getBinaryFilePath(version) {
32
46
  return path.join(getPathToNodeModulesRoot(), 'release', version, ...binarySubPathsByPlatform[platform()]);
33
47
  }
34
48
  function getBinaryDownloadUrl(binaryVersion) {
@@ -37,31 +51,30 @@ function getBinaryDownloadUrl(binaryVersion) {
37
51
  return `${baseUrl}/${platform()}/${arch}/${binarySubPathsByPlatform[platform()][1]}`;
38
52
  }
39
53
  export function downloadServerBinaries(binaryVersion, proxyAgent) {
40
- return new Promise((resolve, reject) => {
41
- const url = getBinaryDownloadUrl(binaryVersion);
42
- const binaryOutputPath = getBinaryPath(binaryVersion);
43
- const binaryFolder = path.dirname(binaryOutputPath);
54
+ return __awaiter(this, void 0, void 0, function* () {
44
55
  logger.info(`Start downloading UI Controller version "${binaryVersion}"`);
45
- if (!(fs.existsSync(binaryFolder))) {
46
- fs.mkdirSync(binaryFolder, { recursive: true });
47
- }
56
+ const url = getBinaryDownloadUrl(binaryVersion);
57
+ const binaryFilePath = getBinaryFilePath(binaryVersion);
58
+ const binaryFolderPath = path.dirname(binaryFilePath);
59
+ const tempFilePath = path.join(binaryFolderPath, 'askui-ui-controller.temp');
60
+ const pipeline = promisify(stream.pipeline);
48
61
  const downloadStream = got.stream(url, proxyAgent ? { agent: proxyAgent } : {});
49
- const fileWriterStream = fs.createWriteStream(binaryOutputPath);
50
- downloadStream.on('error', () => {
51
- reject();
52
- fs.unlink(binaryOutputPath, (err) => { logger.error(err); });
53
- throw buildBinaryNotAvailbleError(binaryVersion);
54
- });
55
- fileWriterStream
56
- .on('error', () => {
57
- fs.unlink(binaryOutputPath, () => { });
58
- reject(new Error('oops, an error during the downloaded occurred, try again with fresh install'));
59
- })
60
- .on('finish', () => {
61
- logger.info(`UI Controller version ${binaryVersion} for your system "${platform()} ${os.arch}" was downloaded`);
62
- logger.debug(`Binary of UI Controller is located at "${binaryOutputPath}".`);
63
- resolve();
64
- });
65
- downloadStream.pipe(fileWriterStream);
62
+ const fileWriterStream = fs.createWriteStream(tempFilePath);
63
+ if (!(fs.existsSync(binaryFolderPath))) {
64
+ fs.mkdirSync(binaryFolderPath, { recursive: true });
65
+ }
66
+ try {
67
+ yield pipeline(downloadStream, fileWriterStream);
68
+ fs.rename(tempFilePath, binaryFilePath, () => {
69
+ logger.info(`UI Controller version ${binaryVersion} for your system "${platform()} ${os.arch}" was downloaded`);
70
+ logger.debug(`Binary of UI Controller is located at "${binaryFilePath}".`);
71
+ });
72
+ }
73
+ catch (error) {
74
+ logger.error(error);
75
+ fs.unlink(tempFilePath, (err) => { logger.error(err); });
76
+ throw buildBinaryNotAvailableError(binaryVersion);
77
+ }
78
+ return Promise.resolve();
66
79
  });
67
80
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { createArgsWithDefaults, createCliFlagsFromArgs } from './ui-controller-args';
2
+ describe('createCliFlagsFromArgs()', () => {
3
+ test('test createCliFlagsFromArgs should return -d 0 as default output', () => {
4
+ const expected = ['-d 0', '-p 6769', '--action_wait_time 1000', '--host 127.0.0.1', '-m ', '--log-level debug'];
5
+ const argsWithDefaults = createArgsWithDefaults();
6
+ const actual = createCliFlagsFromArgs(argsWithDefaults);
7
+ expect(actual).toStrictEqual(expected);
8
+ });
9
+ test('test createCliFlagsFromArgs output should include -d 0 when no display was selected', () => {
10
+ const expected = ['-d 0', '-p 6777', '--action_wait_time 1000', '--host 0.0.0.0', '-m ', '--log-level debug'];
11
+ const argsWithDefaults = createArgsWithDefaults({ port: 6777, host: '0.0.0.0' });
12
+ const actual = createCliFlagsFromArgs(argsWithDefaults);
13
+ expect(actual).toStrictEqual(expected);
14
+ });
15
+ test('test createCliFlagsFromArgs output should include the display that was selected ', () => {
16
+ const expected = ['-d 99', '-p 6777', '--action_wait_time 1000', '--host 0.0.0.0', '-m ', '--log-level debug'];
17
+ const argsWithDefaults = createArgsWithDefaults({ port: 6777, host: '0.0.0.0', display: 99 });
18
+ const actual = createCliFlagsFromArgs(argsWithDefaults);
19
+ expect(actual).toStrictEqual(expected);
20
+ });
21
+ });
@@ -8,7 +8,7 @@ export class UiControllerDarwin extends UiControllerFacade {
8
8
  this.makeDiskImageExecutable();
9
9
  }
10
10
  getStartingCommand() {
11
- return `"${path.dirname(this.binaryPath)}/askui-ui-controller.app/Contents/MacOS/askui-ui-controller"`;
11
+ return `"${path.dirname(this.binaryFilePath)}/askui-ui-controller.app/Contents/MacOS/askui-ui-controller"`;
12
12
  }
13
13
  makeDiskImageExecutable() {
14
14
  const mountPoint = '/Volumes/askui-ui-controller.dmg';
@@ -19,11 +19,11 @@ export class UiControllerDarwin extends UiControllerFacade {
19
19
  '-noautofsck',
20
20
  '-noautoopen',
21
21
  `-mountpoint "${mountPoint}"`,
22
- `"${this.binaryPath}"`,
22
+ `"${this.binaryFilePath}"`,
23
23
  ].join(' '));
24
24
  const appBaseName = 'askui-ui-controller.app';
25
25
  const appSrcPath = `${mountPoint}/${appBaseName}`;
26
- const appDestPath = `${path.dirname(this.binaryPath)}/${appBaseName}`;
26
+ const appDestPath = `${path.dirname(this.binaryFilePath)}/${appBaseName}`;
27
27
  fs.removeSync(appDestPath);
28
28
  fs.copySync(appSrcPath, appDestPath);
29
29
  exec(`hdiutil detach "${mountPoint}"`, (_exception, stdout) => logger.debug(stdout));
@@ -1,6 +1,6 @@
1
1
  import { UiControllerArgs, UiControllerArgsWithDefaults } from './ui-controller-args';
2
2
  export declare abstract class UiControllerFacade {
3
- protected binaryPath: string;
3
+ protected binaryFilePath: string;
4
4
  protected serverLogFile: string;
5
5
  protected readonly DefaultmaxWaitingForStartingInMs: number;
6
6
  start(args?: UiControllerArgs, maxWaitingForStartingInSeconds?: number): Promise<void>;
@@ -11,7 +11,6 @@ export declare abstract class UiControllerFacade {
11
11
  protected makeBinaryExecutable(): void;
12
12
  protected runPreStartChecks(): Promise<void>;
13
13
  protected waitUntilStarted(args: UiControllerArgsWithDefaults, maxWaitingForStartingInSeconds?: number): Promise<void>;
14
- private isBinaryValid;
15
14
  private getBinary;
16
15
  private startWithDefaults;
17
16
  }
@@ -14,14 +14,14 @@ import fkill from 'fkill';
14
14
  import os from 'os';
15
15
  import path from 'path';
16
16
  import { createArgsWithDefaults, createCliFlagsFromArgs, } from './ui-controller-args';
17
- import { downloadServerBinaries, getBinaryPath } from './download-binaries';
17
+ import { downloadServerBinaries, getBinaryFilePath } from './download-binaries';
18
18
  import { logger } from './logger';
19
19
  import { TimeoutError } from './timeout-error';
20
20
  import { UnkownError } from './unkown-error';
21
21
  import { buildProxyAgentArgsFromEnvironment } from '../utils/proxy/proxy-builder';
22
22
  export class UiControllerFacade {
23
23
  constructor() {
24
- this.binaryPath = getBinaryPath('latest');
24
+ this.binaryFilePath = getBinaryFilePath('latest');
25
25
  this.DefaultmaxWaitingForStartingInMs = 30 * 1000;
26
26
  }
27
27
  start(args, maxWaitingForStartingInSeconds) {
@@ -29,7 +29,7 @@ export class UiControllerFacade {
29
29
  yield this.runPreStartChecks();
30
30
  const argsWithDefaults = createArgsWithDefaults(args);
31
31
  const argsWithLogPath = this.serverLogFilePath(argsWithDefaults);
32
- this.binaryPath = getBinaryPath(argsWithLogPath.binaryVersion);
32
+ this.binaryFilePath = getBinaryFilePath(argsWithLogPath.binaryVersion);
33
33
  yield this.getBinary(argsWithLogPath.binaryVersion, argsWithLogPath.overWriteBinary, argsWithLogPath.proxyAgents || (yield buildProxyAgentArgsFromEnvironment()));
34
34
  this.makeBinaryExecutable();
35
35
  logger.debug(`UI Controller log path "${this.serverLogFile}"`);
@@ -65,7 +65,7 @@ export class UiControllerFacade {
65
65
  });
66
66
  }
67
67
  getStartingCommand() {
68
- return `"${this.binaryPath}"`;
68
+ return `"${this.binaryFilePath}"`;
69
69
  }
70
70
  // eslint-disable-next-line class-methods-use-this
71
71
  makeBinaryExecutable() {
@@ -99,19 +99,14 @@ export class UiControllerFacade {
99
99
  }
100
100
  });
101
101
  }
102
- isBinaryValid() {
103
- const sizeThresholdInMB = 100;
104
- const binarysizeInMB = fs.statSync(this.binaryPath).size / (1024 * 1024);
105
- return binarysizeInMB > sizeThresholdInMB;
106
- }
107
102
  getBinary(binaryVersion, overWriteBinary = false, proxyAgent) {
108
103
  return __awaiter(this, void 0, void 0, function* () {
109
- if (!fs.existsSync(this.binaryPath) || overWriteBinary || !this.isBinaryValid()) {
110
- logger.debug(`Currently, no binary of the UI Controller is available at "${this.binaryPath}"`);
104
+ if (!fs.existsSync(this.binaryFilePath) || overWriteBinary) {
105
+ logger.debug(`Currently, no binary of the UI Controller is available at "${this.binaryFilePath}"`);
111
106
  yield downloadServerBinaries(binaryVersion, proxyAgent);
112
107
  }
113
108
  else {
114
- logger.debug(`Binary of UI Controller is already present at "${this.binaryPath}".`);
109
+ logger.debug(`Binary of UI Controller is already present at "${this.binaryFilePath}".`);
115
110
  }
116
111
  });
117
112
  }
@@ -16,7 +16,7 @@ import { LibfuseError } from './libfuse-error';
16
16
  export class UiControllerLinux extends UiControllerFacade {
17
17
  // eslint-disable-next-line class-methods-use-this
18
18
  makeBinaryExecutable() {
19
- exec(`chmod +x "${this.binaryPath}"`, (_exception, stdout) => logger.debug(stdout));
19
+ exec(`chmod +x "${this.binaryFilePath}"`, (_exception, stdout) => logger.debug(stdout));
20
20
  }
21
21
  // eslint-disable-next-line class-methods-use-this
22
22
  runPreStartChecks() {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { Credentials } from './credentials';
2
+ describe('Credentials', () => {
3
+ describe('base64Encoded()', () => {
4
+ test('should return base64-encoded credentials', () => {
5
+ const credentials = new Credentials('password');
6
+ expect(credentials.base64Encoded).toBe('cGFzc3dvcmQ=');
7
+ });
8
+ });
9
+ });
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { OptionsOfJSONResponseBody } from 'got';
2
3
  import http from 'http';
3
4
  import https from 'https';
@@ -17,6 +18,9 @@ export declare class HttpClientGot {
17
18
  } | undefined);
18
19
  private initHeaders;
19
20
  private injectHeadersAndCookies;
20
- post<T>(url: string, data: Record<string | number | symbol, unknown>): Promise<T>;
21
+ post<T>(url: string, data: Record<string | number | symbol, unknown>): Promise<{
22
+ headers: http.IncomingHttpHeaders;
23
+ body: T;
24
+ }>;
21
25
  get<T>(url: string, options?: OptionsOfJSONResponseBody): Promise<T>;
22
26
  }
@@ -24,18 +24,26 @@ export class HttpClientGot {
24
24
  }
25
25
  initHeaders(token, customHeaders = {}) {
26
26
  const credentials = token ? new Credentials(token) : undefined;
27
- this.headers = Object.assign(Object.assign({}, (credentials ? { Authorization: `Basic ${credentials === null || credentials === void 0 ? void 0 : credentials.base64Encoded}` } : {})), customHeaders);
27
+ this.headers = Object.assign(Object.assign({}, (credentials
28
+ ? { Authorization: `Basic ${credentials === null || credentials === void 0 ? void 0 : credentials.base64Encoded}` }
29
+ : {})), customHeaders);
28
30
  }
29
31
  injectHeadersAndCookies(url, options) {
30
32
  const cookieJar = new CookieJar();
31
- Object.keys(this.cookies).map((key) => `${key}=${this.cookies[key]}`).forEach((cookie) => {
33
+ Object.keys(this.cookies)
34
+ .map((key) => `${key}=${this.cookies[key]}`)
35
+ .forEach((cookie) => {
32
36
  cookieJar.setCookieSync(cookie, url);
33
37
  });
34
38
  return Object.assign(Object.assign({}, options), { headers: this.headers, cookieJar });
35
39
  }
36
40
  post(url, data) {
37
41
  return __awaiter(this, void 0, void 0, function* () {
38
- const options = this.injectHeadersAndCookies(url, { json: data, responseType: 'json', throwHttpErrors: false });
42
+ const options = this.injectHeadersAndCookies(url, {
43
+ json: data,
44
+ responseType: 'json',
45
+ throwHttpErrors: false,
46
+ });
39
47
  const { body, statusCode, headers } = yield this.askuiGot.post(url, options);
40
48
  if (headers['deprecation'] !== undefined) {
41
49
  logger.warn(headers['deprecation']);
@@ -43,7 +51,7 @@ export class HttpClientGot {
43
51
  if (statusCode !== 200) {
44
52
  throw httpClientErrorHandler(statusCode, JSON.stringify(body));
45
53
  }
46
- return body;
54
+ return { headers, body };
47
55
  });
48
56
  }
49
57
  get(url, options = { responseType: 'json' }) {
@@ -1,15 +1,14 @@
1
1
  import { aui } from './helper/jest.setup';
2
2
 
3
3
  describe('jest with askui', () => {
4
- it('should click on text', async () => {
5
- // Run this to see what askui annotates
4
+
5
+ it('should generate an interactive annotation', async () => {
6
6
  await aui.annotateInteractively();
7
+ });
7
8
 
8
- await aui.moveMouse(0, 0).exec();
9
+ it('should click on my element', async () => {
9
10
  await aui
10
11
  .click()
11
- .text()
12
- .withText('Click on this text right here!')
13
- .exec();
12
+ // <INSERT YOUR COPIED FILTER HERE AND UNCOMMENT THIS LINE>.exec();
14
13
  });
15
14
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "askui",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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",