askui 0.12.1 → 0.13.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 (95) hide show
  1. package/README.md +13 -19
  2. package/bin/askui +1 -1
  3. package/dist/cjs/core/model/test-case-dto/custom-element-json.d.ts +75 -0
  4. package/dist/cjs/core/model/test-case-dto/custom-element-json.js +2 -0
  5. package/dist/cjs/core/model/test-case-dto/custom-element.d.ts +21 -0
  6. package/dist/cjs/core/model/test-case-dto/custom-element.js +54 -0
  7. package/dist/cjs/core/model/test-case-dto/index.d.ts +3 -0
  8. package/dist/cjs/core/model/test-case-dto/index.js +5 -0
  9. package/dist/cjs/core/model/test-case-dto/test-step.d.ts +6 -0
  10. package/dist/cjs/core/model/test-case-dto/test-step.js +2 -0
  11. package/dist/cjs/core/model/test-case-result-dto/index.d.ts +2 -0
  12. package/dist/cjs/core/model/test-case-result-dto/index.js +7 -0
  13. package/dist/cjs/core/model/test-case-result-dto/test-step-result-dto.d.ts +9 -0
  14. package/dist/cjs/core/model/test-case-result-dto/test-step-result-dto.js +16 -0
  15. package/dist/cjs/core/model/test-case-result-dto/test-step-state.d.ts +4 -0
  16. package/dist/cjs/core/model/test-case-result-dto/test-step-state.js +8 -0
  17. package/dist/cjs/core/reporting/default-reporter.d.ts +10 -0
  18. package/dist/cjs/core/reporting/default-reporter.js +12 -0
  19. package/dist/cjs/execution/annotation-level.d.ts +5 -0
  20. package/dist/cjs/execution/annotation-level.js +9 -0
  21. package/dist/cjs/execution/ui-control-client-error.d.ts +2 -0
  22. package/dist/cjs/execution/ui-control-client-error.js +6 -0
  23. package/dist/cjs/lib/index.d.ts +1 -0
  24. package/dist/cjs/lib/index.js +3 -1
  25. package/dist/cjs/lib/interactive_cli/add-script-package-json.d.ts +1 -0
  26. package/dist/cjs/lib/interactive_cli/add-script-package-json.js +38 -0
  27. package/dist/cjs/lib/interactive_cli/cli-options-interface.d.ts +8 -0
  28. package/dist/cjs/lib/interactive_cli/cli-options-interface.js +2 -0
  29. package/dist/cjs/lib/interactive_cli/cli.d.ts +2 -0
  30. package/dist/cjs/lib/interactive_cli/cli.js +115 -0
  31. package/dist/cjs/lib/interactive_cli/create-example-project.d.ts +26 -0
  32. package/dist/cjs/lib/interactive_cli/create-example-project.js +293 -0
  33. package/dist/cjs/lib/interactive_cli/index.d.ts +1 -0
  34. package/dist/cjs/lib/interactive_cli/index.js +5 -0
  35. package/dist/cjs/lib/interactive_cli/replace-string-in-file.d.ts +1 -0
  36. package/dist/cjs/lib/interactive_cli/replace-string-in-file.js +31 -0
  37. package/dist/cjs/utils/base_64_image/base-64-image.d.ts +6 -9
  38. package/dist/cjs/utils/base_64_image/base-64-image.js +32 -33
  39. package/dist/cjs/utils/base_64_image/sharp.d.ts +2 -0
  40. package/dist/cjs/utils/base_64_image/sharp.js +56 -0
  41. package/dist/cjs/utils/proxy/proxy-builder.js +3 -1
  42. package/dist/cjs/utils/transformations.js +4 -2
  43. package/dist/esm/core/model/test-case-dto/custom-element-json.d.ts +75 -0
  44. package/dist/esm/core/model/test-case-dto/custom-element-json.js +1 -0
  45. package/dist/esm/core/model/test-case-dto/custom-element.d.ts +21 -0
  46. package/dist/esm/core/model/test-case-dto/custom-element.js +50 -0
  47. package/dist/esm/core/model/test-case-dto/index.d.ts +3 -0
  48. package/dist/esm/core/model/test-case-dto/index.js +1 -0
  49. package/dist/esm/core/model/test-case-dto/test-step.d.ts +6 -0
  50. package/dist/esm/core/model/test-case-dto/test-step.js +1 -0
  51. package/dist/esm/core/model/test-case-result-dto/index.d.ts +2 -0
  52. package/dist/esm/core/model/test-case-result-dto/index.js +2 -0
  53. package/dist/esm/core/model/test-case-result-dto/test-step-result-dto.d.ts +9 -0
  54. package/dist/esm/core/model/test-case-result-dto/test-step-result-dto.js +12 -0
  55. package/dist/esm/core/model/test-case-result-dto/test-step-state.d.ts +4 -0
  56. package/dist/esm/core/model/test-case-result-dto/test-step-state.js +5 -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/execution/annotation-level.d.ts +5 -0
  60. package/dist/esm/execution/annotation-level.js +6 -0
  61. package/dist/esm/execution/ui-control-client-error.d.ts +2 -0
  62. package/dist/esm/execution/ui-control-client-error.js +2 -0
  63. package/dist/esm/lib/index.d.ts +1 -0
  64. package/dist/esm/lib/index.js +1 -0
  65. package/dist/esm/lib/interactive_cli/add-script-package-json.d.ts +1 -0
  66. package/dist/esm/lib/interactive_cli/add-script-package-json.js +31 -0
  67. package/dist/esm/lib/interactive_cli/cli-options-interface.d.ts +8 -0
  68. package/dist/esm/lib/interactive_cli/cli-options-interface.js +1 -0
  69. package/dist/esm/lib/interactive_cli/cli.d.ts +2 -0
  70. package/dist/esm/lib/interactive_cli/cli.js +108 -0
  71. package/dist/esm/lib/interactive_cli/create-example-project.d.ts +26 -0
  72. package/dist/esm/lib/interactive_cli/create-example-project.js +286 -0
  73. package/dist/esm/lib/interactive_cli/index.d.ts +1 -0
  74. package/dist/esm/lib/interactive_cli/index.js +1 -0
  75. package/dist/esm/lib/interactive_cli/replace-string-in-file.d.ts +1 -0
  76. package/dist/esm/lib/interactive_cli/replace-string-in-file.js +24 -0
  77. package/dist/esm/utils/base_64_image/base-64-image.d.ts +6 -9
  78. package/dist/esm/utils/base_64_image/base-64-image.js +32 -33
  79. package/dist/esm/utils/base_64_image/sharp.d.ts +2 -0
  80. package/dist/esm/utils/base_64_image/sharp.js +33 -0
  81. package/dist/esm/utils/proxy/proxy-builder.js +3 -1
  82. package/dist/esm/utils/transformations.js +4 -2
  83. package/dist/example_projects_templates/configs/jasmine.config.json +12 -0
  84. package/dist/example_projects_templates/configs/jest.config.ts +13 -0
  85. package/dist/example_projects_templates/configs/tsconfig.json +7 -0
  86. package/dist/example_projects_templates/templates/askui-helper-windows.nj +35 -0
  87. package/dist/example_projects_templates/templates/askui-helper.nj +49 -0
  88. package/dist/example_projects_templates/typescript/.eslintignore +1 -0
  89. package/dist/example_projects_templates/typescript/.eslintignore-template +1 -0
  90. package/dist/example_projects_templates/typescript/.eslintrc.json +20 -0
  91. package/dist/example_projects_templates/typescript/.eslintrc.json-template +20 -0
  92. package/dist/example_projects_templates/typescript/askui_example/helpers/askui-helper.ts +39 -0
  93. package/dist/example_projects_templates/typescript/askui_example/my-first-askui-test-suite.test.ts +21 -0
  94. package/dist/example_projects_templates/typescript/tsconfig.json +7 -0
  95. package/package.json +11 -3
@@ -0,0 +1,21 @@
1
+ import { CustomElementJson } from './custom-element-json';
2
+ export declare class CustomElement implements CustomElementJson {
3
+ customImage: string;
4
+ name?: string | undefined;
5
+ threshold?: number | undefined;
6
+ rotationDegreePerStep?: number | undefined;
7
+ imageCompareFormat?: "RGB" | "grayscale" | undefined;
8
+ mask?: {
9
+ x: number;
10
+ y: number;
11
+ }[] | undefined;
12
+ private static schema;
13
+ constructor(customImage: string, name?: string | undefined, threshold?: number | undefined, rotationDegreePerStep?: number | undefined, imageCompareFormat?: "RGB" | "grayscale" | undefined, mask?: {
14
+ x: number;
15
+ y: number;
16
+ }[] | undefined);
17
+ static fromJsonListWithImagePathOrImage(ceJson?: CustomElementJson[]): Promise<CustomElement[]>;
18
+ static fromJsonWithImagePathOrImage(ceJson: CustomElementJson): Promise<CustomElement>;
19
+ static fromJson(ceJson: CustomElementJson): CustomElement;
20
+ validate(): void;
21
+ }
@@ -0,0 +1,50 @@
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 { array, number, object, ValidationError, } from 'yup';
11
+ import { Base64Image } from '../../../utils/base_64_image/base-64-image';
12
+ export class CustomElement {
13
+ constructor(customImage, name, threshold, rotationDegreePerStep, imageCompareFormat, mask) {
14
+ this.customImage = customImage;
15
+ this.name = name;
16
+ this.threshold = threshold;
17
+ this.rotationDegreePerStep = rotationDegreePerStep;
18
+ this.imageCompareFormat = imageCompareFormat;
19
+ this.mask = mask;
20
+ }
21
+ static fromJsonListWithImagePathOrImage(ceJson = []) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return Promise.all(ceJson.map((customElement) => CustomElement.fromJsonWithImagePathOrImage(customElement)));
24
+ });
25
+ }
26
+ static fromJsonWithImagePathOrImage(ceJson) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const customImage = (yield Base64Image.fromPathOrString(ceJson.customImage)).toString();
29
+ const customElement = CustomElement.fromJson(Object.assign(Object.assign({}, ceJson), { customImage }));
30
+ customElement.validate();
31
+ return customElement;
32
+ });
33
+ }
34
+ static fromJson(ceJson) {
35
+ return new CustomElement(ceJson.customImage, ceJson.name, ceJson.threshold, ceJson.rotationDegreePerStep, ceJson.imageCompareFormat, ceJson.mask);
36
+ }
37
+ validate() {
38
+ try {
39
+ CustomElement.schema.validateSync(this, { abortEarly: false, strict: true });
40
+ }
41
+ catch (e) { // ValidationError
42
+ throw new ValidationError(e.errors.join(', '));
43
+ }
44
+ }
45
+ }
46
+ CustomElement.schema = object({
47
+ threshold: number().optional().min(0).max(1),
48
+ rotationDegreePerStep: number().optional().min(0).lessThan(360),
49
+ mask: array().optional().min(3, 'mask must contain at least 3 points'),
50
+ });
@@ -0,0 +1,3 @@
1
+ export { CustomElement } from './custom-element';
2
+ export { CustomElementJson } from './custom-element-json';
3
+ export { TestStep } from './test-step';
@@ -0,0 +1 @@
1
+ export { CustomElement } from './custom-element';
@@ -0,0 +1,6 @@
1
+ import { CustomElement } from './custom-element';
2
+ export interface TestStep {
3
+ instruction: string;
4
+ customElements?: CustomElement[];
5
+ secretText?: string | undefined;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export { TestStepResultDto } from './test-step-result-dto';
2
+ export { TestStepState } from './test-step-state';
@@ -0,0 +1,2 @@
1
+ export { TestStepResultDto } from './test-step-result-dto';
2
+ export { TestStepState } from './test-step-state';
@@ -0,0 +1,9 @@
1
+ import { TestStepState } from './test-step-state';
2
+ export declare class TestStepResultDto {
3
+ state: TestStepState;
4
+ comment: string;
5
+ createDate: Date;
6
+ updateDate: Date;
7
+ constructor(state: TestStepState, comment?: string, createDate?: Date, updateDate?: Date);
8
+ static fromJson(testStepResult: TestStepResultDto): TestStepResultDto;
9
+ }
@@ -0,0 +1,12 @@
1
+ import { TestStepState } from './test-step-state';
2
+ export class TestStepResultDto {
3
+ constructor(state, comment = '', createDate = new Date(), updateDate = new Date()) {
4
+ this.state = state;
5
+ this.comment = comment;
6
+ this.createDate = createDate;
7
+ this.updateDate = updateDate;
8
+ }
9
+ static fromJson(testStepResult) {
10
+ return new TestStepResultDto(TestStepState[testStepResult.state], testStepResult.comment, new Date(testStepResult.createDate), new Date(testStepResult.updateDate));
11
+ }
12
+ }
@@ -0,0 +1,4 @@
1
+ export declare enum TestStepState {
2
+ PASSED = "PASSED",
3
+ FAILED = "FAILED"
4
+ }
@@ -0,0 +1,5 @@
1
+ export var TestStepState;
2
+ (function (TestStepState) {
3
+ TestStepState["PASSED"] = "PASSED";
4
+ TestStepState["FAILED"] = "FAILED";
5
+ })(TestStepState || (TestStepState = {}));
@@ -0,0 +1,10 @@
1
+ import { Step } from './step';
2
+ export declare const DEFAULT_REPORTER: {
3
+ config: {
4
+ readonly withScreenshots: "onFailure";
5
+ readonly withDetectedElements: "onFailure";
6
+ };
7
+ onStepBegin: (_step: Step) => Promise<void>;
8
+ onStepRetry: (_step: Step) => Promise<void>;
9
+ onStepEnd: (_step: Step) => Promise<void>;
10
+ };
@@ -0,0 +1,9 @@
1
+ export const DEFAULT_REPORTER = {
2
+ config: {
3
+ withScreenshots: 'onFailure',
4
+ withDetectedElements: 'onFailure',
5
+ },
6
+ onStepBegin: (_step) => Promise.resolve(),
7
+ onStepRetry: (_step) => Promise.resolve(),
8
+ onStepEnd: (_step) => Promise.resolve(),
9
+ };
@@ -0,0 +1,5 @@
1
+ export declare enum AnnotationLevel {
2
+ DISABLED = "disabled",
3
+ ON_FAILURE = "onFailure",
4
+ ALL = "all"
5
+ }
@@ -0,0 +1,6 @@
1
+ export var AnnotationLevel;
2
+ (function (AnnotationLevel) {
3
+ AnnotationLevel["DISABLED"] = "disabled";
4
+ AnnotationLevel["ON_FAILURE"] = "onFailure";
5
+ AnnotationLevel["ALL"] = "all";
6
+ })(AnnotationLevel || (AnnotationLevel = {}));
@@ -0,0 +1,2 @@
1
+ export declare class UiControlClientError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export class UiControlClientError extends Error {
2
+ }
@@ -1,3 +1,4 @@
1
+ export { init } from './interactive_cli';
1
2
  export { UnkownError } from './unkown-error';
2
3
  export { TimeoutError } from './timeout-error';
3
4
  export { UiController } from './ui-controller';
@@ -1,3 +1,4 @@
1
+ export { init } from './interactive_cli';
1
2
  export { UnkownError } from './unkown-error';
2
3
  export { TimeoutError } from './timeout-error';
3
4
  export { UiController } from './ui-controller';
@@ -0,0 +1 @@
1
+ export declare function addScript(filePath: string, name: string, command: string): Promise<void>;
@@ -0,0 +1,31 @@
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 fs from 'fs-extra';
11
+ import { logger } from '../logger';
12
+ export function addScript(filePath, name, command) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ try {
15
+ const data = yield fs.readFile(filePath, 'utf8');
16
+ const jsonData = JSON.parse(data);
17
+ if (jsonData.scripts === undefined) {
18
+ jsonData.scripts = { [name]: `${command}` };
19
+ }
20
+ else {
21
+ jsonData.scripts[name] = command;
22
+ }
23
+ const jsonString = JSON.stringify(jsonData, null, 2);
24
+ yield fs.writeFile(filePath, jsonString, 'utf8');
25
+ }
26
+ catch (error) {
27
+ logger.error(`Could write script '${command}' in file '${filePath}'`);
28
+ logger.error(error.message);
29
+ }
30
+ });
31
+ }
@@ -0,0 +1,8 @@
1
+ export interface CliOptions {
2
+ operatingSystem: 'windows' | 'linux' | 'macos';
3
+ workspaceId: string;
4
+ accessToken: string;
5
+ testFramework: 'jasmine' | 'jest';
6
+ usingProxy: boolean;
7
+ typescriptConfig: boolean;
8
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function init(argv: string[]): Command;
@@ -0,0 +1,108 @@
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 inquirer from 'inquirer';
11
+ import { Command, Option } from 'commander';
12
+ import { CreateExampleProject } from './create-example-project';
13
+ const nonEmpty = (subject) => (input) => (input.trim().length > 0) || `${subject} is required.`;
14
+ const questions = [
15
+ {
16
+ type: 'list',
17
+ name: 'testFramework',
18
+ message: 'Which framework do you prefer',
19
+ choices: ['jest', 'jasmine'],
20
+ },
21
+ {
22
+ type: 'input',
23
+ name: 'workspaceId',
24
+ message: 'Your workspace id',
25
+ validate: nonEmpty('workspace id'),
26
+ },
27
+ {
28
+ type: 'password',
29
+ name: 'accessToken',
30
+ message: 'Your access token',
31
+ mask: '*',
32
+ validate: nonEmpty('access token'),
33
+ },
34
+ {
35
+ type: 'confirm',
36
+ name: 'usingProxy',
37
+ message: 'Are you using a proxy?',
38
+ default: false,
39
+ },
40
+ {
41
+ type: 'confirm',
42
+ name: 'typescriptConfig',
43
+ message: 'Do you want to add the tsconfig.json file? This action will overwrite the file if it exists. Default True ',
44
+ default: true,
45
+ },
46
+ ];
47
+ const options = [
48
+ {
49
+ option: '-f, --test-framework <value>',
50
+ choices: ['jasmine', 'jest'],
51
+ description: 'the test framework to use',
52
+ },
53
+ {
54
+ option: '-w, --workspace-id <value>',
55
+ choices: [],
56
+ description: 'a workspace id',
57
+ },
58
+ {
59
+ option: '-a, --access-token <value>',
60
+ choices: [],
61
+ description: 'an access token for the workspace with the id',
62
+ },
63
+ {
64
+ option: '-p, --using-proxy <value>',
65
+ choices: ['true', 'false'],
66
+ description: 'use a proxy',
67
+ },
68
+ {
69
+ option: '-t, --typescript-config <value>',
70
+ choices: ['true', 'false'],
71
+ description: 'overwrite tsconfig.json flag',
72
+ },
73
+ ];
74
+ const createProgram = () => {
75
+ const program = new Command('askui');
76
+ program.usage('<command> [options]');
77
+ return program;
78
+ };
79
+ export function init(argv) {
80
+ const args = argv || process.argv;
81
+ const program = createProgram();
82
+ const programInit = program.command('init');
83
+ programInit.description('Creates a askui example project');
84
+ // Loop through the options object and register each option with the program
85
+ options.forEach((opt) => {
86
+ const tempOption = new Option(opt.option, opt.description);
87
+ if (opt.choices.length > 0) {
88
+ tempOption.choices(opt.choices);
89
+ }
90
+ programInit.addOption(tempOption);
91
+ });
92
+ programInit.usage('[-f test_framework] [-w workspace_id] [-a access_token] [-p boolean] [-t boolean]');
93
+ programInit
94
+ .action((_opts) => __awaiter(this, void 0, void 0, function* () {
95
+ const userAnswers = programInit.opts();
96
+ // Check which options are missing and prompt the user for them
97
+ const missingOptions = questions.filter((entry) => !(entry.name in userAnswers));
98
+ if (missingOptions.length > 0) {
99
+ inquirer.prompt(missingOptions).then((answers) => __awaiter(this, void 0, void 0, function* () {
100
+ yield new CreateExampleProject(Object.assign(Object.assign({}, userAnswers), answers)).createExampleProject();
101
+ }));
102
+ }
103
+ else {
104
+ yield new CreateExampleProject(userAnswers).createExampleProject();
105
+ }
106
+ }));
107
+ return program.parse(args);
108
+ }
@@ -0,0 +1,26 @@
1
+ import { CliOptions } from './cli-options-interface';
2
+ export declare class CreateExampleProject {
3
+ readonly cliOptions: CliOptions;
4
+ private distexampleFolderPath;
5
+ private exampleFolderName;
6
+ private baseDirPath;
7
+ private proxyDocUrl;
8
+ private remoteDeviceControllerUrl;
9
+ private helperTemplateConfig;
10
+ constructor(cliOptions: CliOptions);
11
+ private copyTemplateProject;
12
+ private copyTestFrameworkConfig;
13
+ private addTestFrameWorkTimeout;
14
+ private addReporterConfig;
15
+ private addAskuiRunCommand;
16
+ private addESLintRunCommand;
17
+ private createAskUIHelperFromTemplate;
18
+ private setupTestFrameWork;
19
+ private installTestFrameworkPackages;
20
+ private addUserCredentails;
21
+ private copyESLintConfigFiles;
22
+ private copyTsConfigFile;
23
+ private installProxy;
24
+ private normalizeCliOptions;
25
+ createExampleProject(): Promise<void>;
26
+ }