askui 0.4.0 → 0.6.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 (41) hide show
  1. package/dist/cjs/execution/config-error.d.ts +2 -0
  2. package/dist/cjs/execution/config-error.js +6 -0
  3. package/dist/cjs/execution/dsl.d.ts +387 -2
  4. package/dist/cjs/execution/dsl.js +405 -2
  5. package/dist/cjs/execution/inference-client.d.ts +2 -1
  6. package/dist/cjs/execution/inference-client.js +9 -3
  7. package/dist/cjs/execution/ui-control-client.js +4 -2
  8. package/dist/cjs/execution/ui-controller-client-interface.d.ts +13 -0
  9. package/dist/cjs/lib/copy-example-project.js +40 -4
  10. package/dist/cjs/lib/download-binaries.d.ts +7 -1
  11. package/dist/cjs/lib/download-binaries.js +2 -2
  12. package/dist/cjs/lib/ui-controller-args.d.ts +4 -0
  13. package/dist/cjs/lib/ui-controller-facade.js +4 -3
  14. package/dist/cjs/shared/proxy-agent-args.d.ts +35 -0
  15. package/dist/cjs/shared/proxy-agent-args.js +2 -0
  16. package/dist/cjs/utils/http/http-client-got.d.ts +11 -1
  17. package/dist/cjs/utils/http/http-client-got.js +5 -3
  18. package/dist/cjs/utils/proxy/proxy-builder.d.ts +4 -0
  19. package/dist/cjs/utils/proxy/proxy-builder.js +67 -0
  20. package/dist/esm/execution/config-error.d.ts +2 -0
  21. package/dist/esm/execution/config-error.js +2 -0
  22. package/dist/esm/execution/dsl.d.ts +387 -2
  23. package/dist/esm/execution/dsl.js +405 -2
  24. package/dist/esm/execution/inference-client.d.ts +2 -1
  25. package/dist/esm/execution/inference-client.js +9 -3
  26. package/dist/esm/execution/ui-control-client.js +4 -2
  27. package/dist/esm/execution/ui-controller-client-interface.d.ts +13 -0
  28. package/dist/esm/lib/copy-example-project.js +40 -4
  29. package/dist/esm/lib/download-binaries.d.ts +7 -1
  30. package/dist/esm/lib/download-binaries.js +2 -2
  31. package/dist/esm/lib/ui-controller-args.d.ts +4 -0
  32. package/dist/esm/lib/ui-controller-facade.js +4 -3
  33. package/dist/esm/shared/proxy-agent-args.d.ts +35 -0
  34. package/dist/esm/shared/proxy-agent-args.js +1 -0
  35. package/dist/esm/utils/http/http-client-got.d.ts +11 -1
  36. package/dist/esm/utils/http/http-client-got.js +5 -3
  37. package/dist/esm/utils/proxy/proxy-builder.d.ts +4 -0
  38. package/dist/esm/utils/proxy/proxy-builder.js +43 -0
  39. package/dist/example_projects_templates/typescript_jest/test/helper/jest.setup.ts +8 -3
  40. package/dist/example_projects_templates/typescript_jest/test/my-first-askui-test-suite.test.ts +5 -0
  41. package/package.json +5 -2
@@ -18,6 +18,7 @@ import { downloadServerBinaries, getBinaryPath } from './download-binaries';
18
18
  import { logger } from './logger';
19
19
  import { TimeoutError } from './timeout-error';
20
20
  import { UnkownError } from './unkown-error';
21
+ import { buildProxyAgentArgsFromEnvironment } from '../utils/proxy/proxy-builder';
21
22
  export class UiControllerFacade {
22
23
  constructor() {
23
24
  this.binaryPath = getBinaryPath('latest');
@@ -29,7 +30,7 @@ export class UiControllerFacade {
29
30
  const argsWithDefaults = createArgsWithDefaults(args);
30
31
  const argsWithLogPath = this.serverLogFilePath(argsWithDefaults);
31
32
  this.binaryPath = getBinaryPath(argsWithLogPath.binaryVersion);
32
- yield this.getBinary(argsWithLogPath.binaryVersion, argsWithLogPath.overWriteBinary);
33
+ yield this.getBinary(argsWithLogPath.binaryVersion, argsWithLogPath.overWriteBinary, argsWithLogPath.proxyAgents || (yield buildProxyAgentArgsFromEnvironment()));
33
34
  this.makeBinaryExecutable();
34
35
  logger.debug(`UI Controller log path "${this.serverLogFile}"`);
35
36
  yield this.startWithDefaults(argsWithLogPath, maxWaitingForStartingInSeconds);
@@ -103,11 +104,11 @@ export class UiControllerFacade {
103
104
  const binarysizeInMB = fs.statSync(this.binaryPath).size / (1024 * 1024);
104
105
  return binarysizeInMB > sizeThresholdInMB;
105
106
  }
106
- getBinary(binaryVersion, overWriteBinary = false) {
107
+ getBinary(binaryVersion, overWriteBinary = false, proxyAgent) {
107
108
  return __awaiter(this, void 0, void 0, function* () {
108
109
  if (!fs.existsSync(this.binaryPath) || overWriteBinary || !this.isBinaryValid()) {
109
110
  logger.debug(`Currently, no binary of the UI Controller is available at "${this.binaryPath}"`);
110
- yield downloadServerBinaries(binaryVersion);
111
+ yield downloadServerBinaries(binaryVersion, proxyAgent);
111
112
  }
112
113
  else {
113
114
  logger.debug(`Binary of UI Controller is already present at "${this.binaryPath}".`);
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ import http from 'http';
3
+ import https from 'https';
4
+ /**
5
+ * Proxy agent configuration for HTTP(S) requests
6
+ *
7
+ * All modules which implement the `http.Agent`'s or `https.Agent`'s
8
+ * interface, respectively, can be used.
9
+ * We recommend to use [hpagent](https://github.com/delvedore/hpagent).
10
+ *
11
+ * Installation:
12
+ * ```shell
13
+ * npm install --save hpagent
14
+ * ```
15
+ *
16
+ * Configuration:
17
+ * ```typescript
18
+ * const httpProxyUrl = "http://your-proxy:3128";
19
+ * const httpsProxyUrl = "https://your-proxy:3129";
20
+ *
21
+ * const aui = await UiControlClient.build({
22
+ * proxyAgents: {
23
+ * http: new HttpProxyAgent({ proxy: httpProxyUrl }),
24
+ * https: new HttpsProxyAgent({ proxy: httpsProxyUrl }),
25
+ * },
26
+ * });
27
+ * ```
28
+ *
29
+ * @param {http.Agent} http - Agent for http requests
30
+ * @param {https.Agent} https - Agent for https requests
31
+ ** */
32
+ export interface ProxyAgentArgs {
33
+ http: http.Agent;
34
+ https: https.Agent;
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,20 @@
1
1
  import { OptionsOfJSONResponseBody } from 'got';
2
+ import http from 'http';
3
+ import https from 'https';
2
4
  export declare class HttpClientGot {
3
5
  readonly token?: string | undefined;
4
6
  readonly customHeaders?: Record<string, string> | undefined;
5
7
  private readonly cookies;
8
+ readonly proxyAgents?: {
9
+ http: http.Agent;
10
+ https: https.Agent;
11
+ } | undefined;
6
12
  private headers;
7
- constructor(token?: string | undefined, customHeaders?: Record<string, string> | undefined, cookies?: Record<string, string>);
13
+ private askuiGot;
14
+ constructor(token?: string | undefined, customHeaders?: Record<string, string> | undefined, cookies?: Record<string, string>, proxyAgents?: {
15
+ http: http.Agent;
16
+ https: https.Agent;
17
+ } | undefined);
8
18
  private initHeaders;
9
19
  private injectHeadersAndCookies;
10
20
  post<T>(url: string, data: Record<string | number | symbol, unknown>): Promise<T>;
@@ -13,12 +13,14 @@ import { logger } from '../../lib';
13
13
  import { Credentials } from './credentials';
14
14
  import { httpClientErrorHandler } from './custom-errors';
15
15
  export class HttpClientGot {
16
- constructor(token, customHeaders, cookies = {}) {
16
+ constructor(token, customHeaders, cookies = {}, proxyAgents) {
17
17
  this.token = token;
18
18
  this.customHeaders = customHeaders;
19
19
  this.cookies = cookies;
20
+ this.proxyAgents = proxyAgents;
20
21
  this.headers = {};
21
22
  this.initHeaders(token, customHeaders);
23
+ this.askuiGot = got.extend(proxyAgents ? { agent: proxyAgents } : {});
22
24
  }
23
25
  initHeaders(token, customHeaders = {}) {
24
26
  const credentials = token ? new Credentials(token) : undefined;
@@ -34,7 +36,7 @@ export class HttpClientGot {
34
36
  post(url, data) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
38
  const options = this.injectHeadersAndCookies(url, { json: data, responseType: 'json', throwHttpErrors: false });
37
- const { body, statusCode, headers } = yield got.post(url, options);
39
+ const { body, statusCode, headers } = yield this.askuiGot.post(url, options);
38
40
  if (headers['deprecation'] !== undefined) {
39
41
  logger.warn(headers['deprecation']);
40
42
  }
@@ -46,7 +48,7 @@ export class HttpClientGot {
46
48
  }
47
49
  get(url, options = { responseType: 'json' }) {
48
50
  return __awaiter(this, void 0, void 0, function* () {
49
- const response = yield got.get(url, this.injectHeadersAndCookies(url, options));
51
+ const response = yield this.askuiGot.get(url, this.injectHeadersAndCookies(url, options));
50
52
  return response.body;
51
53
  });
52
54
  }
@@ -0,0 +1,4 @@
1
+ import { ProxyAgentArgs } from '../../shared/proxy-agent-args';
2
+ export declare class ProxyImportError extends Error {
3
+ }
4
+ export declare function buildProxyAgentArgsFromEnvironment(): Promise<ProxyAgentArgs | undefined>;
@@ -0,0 +1,43 @@
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 { logger } from '../../lib/logger';
11
+ export class ProxyImportError extends Error {
12
+ }
13
+ function dynmicImportHpagent() {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ try {
16
+ // eslint-disable-next-line import/no-extraneous-dependencies
17
+ return yield import('hpagent');
18
+ }
19
+ catch (err) {
20
+ throw new ProxyImportError('Can\'t find "hpagent" module to configure proxy! Please, install hpagent for proxy support with "npm install --save-dev hpagent".');
21
+ }
22
+ });
23
+ }
24
+ export function buildProxyAgentArgsFromEnvironment() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const httpProxyUrl = process.env['HTTP_PROXY'];
27
+ const httpsProxyUrl = process.env['HTTPS_PROXY'];
28
+ if (httpProxyUrl === undefined && httpsProxyUrl === undefined) {
29
+ logger.debug('No proxy defined. "HTTPS_PROXY" and "HTTP_PROXY" environment variables are empty.');
30
+ return undefined;
31
+ }
32
+ const hpagent = yield dynmicImportHpagent();
33
+ logger.info('Using proxy! One of following environment variables are defined: "HTTPS_PROXY", "https_proxy", "HTTP_PROXY" and "http_proxy"');
34
+ return {
35
+ http: new hpagent.HttpProxyAgent({
36
+ proxy: (httpProxyUrl || httpsProxyUrl),
37
+ }),
38
+ https: new hpagent.HttpsProxyAgent({
39
+ proxy: (httpsProxyUrl || httpProxyUrl),
40
+ }),
41
+ };
42
+ });
43
+ }
@@ -20,15 +20,20 @@ beforeAll(async () => {
20
20
 
21
21
  await uiController.start();
22
22
 
23
- aui = await UiControlClient.build();
23
+ aui = await UiControlClient.build({
24
+ credentials: {
25
+ workspaceId: '<your workspace id>',
26
+ token: '<your access token>',
27
+ },
28
+ });
24
29
 
25
30
  await aui.connect();
26
31
  });
27
32
 
28
33
  afterAll(async () => {
29
- await uiController.stop();
30
-
31
34
  aui.close();
35
+
36
+ await uiController.stop();
32
37
  });
33
38
 
34
39
  export { aui };
@@ -2,9 +2,14 @@ import { aui } from './helper/jest.setup';
2
2
 
3
3
  describe('jest with askui', () => {
4
4
  it('should click on text', async () => {
5
+ // Run this to see what askui annotates
6
+ await aui.annotateInteractively();
7
+
8
+ await aui.moveMouse(0, 0).exec();
5
9
  await aui
6
10
  .click()
7
11
  .text()
12
+ .withText('Click on this text right here!')
8
13
  .exec();
9
14
  });
10
15
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "askui",
3
- "version": "0.4.0",
3
+ "version": "0.6.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",
@@ -39,7 +39,7 @@
39
39
  "copyExampleProject": "shx cp -r example_projects_templates/ dist/ && shx cp -r bin/* dist/",
40
40
  "lint": "eslint --cache --fix --max-warnings 0 \"./**/*.{js,ts}\"",
41
41
  "lint:staged": "lint-staged",
42
- "test": "jest '/src'",
42
+ "test": "NODE_EXTRA_CA_CERTS='test/proxy/certs/unit_test.pem' jest '/src'",
43
43
  "postinstall": "node -e \"require('./bin/askui-postinstall')\""
44
44
  },
45
45
  "files": [
@@ -73,7 +73,10 @@
73
73
  "@types/url-join": "4.0.1",
74
74
  "@types/webrtc": "0.0.30",
75
75
  "@types/ws": "7.4.4",
76
+ "hpagent": "^1.2.0",
76
77
  "jest": "28.1.1",
78
+ "proxy": "^1.0.2",
79
+ "proxy-agent": "^5.0.0",
77
80
  "sharp": "0.30.6",
78
81
  "shx": "0.3.4",
79
82
  "ts-jest": "28.0.4",