askui 0.4.0 → 0.5.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.
@@ -799,6 +799,120 @@ class FluentFilters extends FluentBase {
799
799
  exports.FluentFilters = FluentFilters;
800
800
  // Relations
801
801
  class FluentFiltersOrRelations extends FluentFilters {
802
+ /**
803
+ * Logic or operator
804
+ *
805
+ * **Examples:**
806
+ * ```text
807
+ * scene 1
808
+ * -------------- ---------------
809
+ * | button | | icon |
810
+ * -------------- ---------------
811
+ *
812
+ * scene 2
813
+ * -------------- ---------------
814
+ * | button | | text |
815
+ * -------------- ---------------
816
+ *
817
+ * ```
818
+ * In case, that your reference element can have multiple values, in the following example, the element right of the button can be either icon or text.
819
+ * You can use **the `or()` relation**, so your teststep is valid for both scenes
820
+ * ```typescript
821
+ * const button = await aui.get().button().rightOf().icon().or().text().exec();
822
+ * console.log(button);
823
+ * ```
824
+ * Returns the same button for both cases
825
+ * ```text
826
+ * console output: [
827
+ * DetectedElement {
828
+ * name: 'BUTTON',
829
+ * text: 'button',
830
+ * colors: [ 'red', 'black', 'red' ],
831
+ * bndbox: BoundingBox {
832
+ * xmin: 900,
833
+ * ymin: 910,
834
+ * xmax: 920,
835
+ * ymax: 930
836
+ * }
837
+ * }
838
+ * ]
839
+ * ```
840
+ *
841
+ * @return {FluentFilters}
842
+ */
843
+ or() {
844
+ this._textStr = 'or';
845
+ return new FluentFilters(this);
846
+ }
847
+ /**
848
+ * Logic and operator
849
+ *
850
+ * **Examples:**
851
+ * ```text
852
+ * example scene:
853
+ * -------------------------- --------------------------
854
+ * | icon user colored black | | icon user colored red |
855
+ * -------------------------- --------------------------
856
+ * ```
857
+ * ```typescript
858
+ * const icons = await aui.get().icon().withText('user').exec();
859
+ * console.log(icons);
860
+ * ```
861
+ * Using only the filter withText, the get command will return both icons because they share the same text
862
+ * ```text
863
+ * console output: [
864
+ * DetectedElement {
865
+ * name: 'ICON',
866
+ * text: 'user',
867
+ * colors: [ 'black', 'black', 'black' ],
868
+ * bndbox: BoundingBox {
869
+ * xmin: 1000,
870
+ * ymin: 1010,
871
+ * xmax: 1020,
872
+ * ymax: 1030
873
+ * }
874
+ * },
875
+ * DetectedElement {
876
+ * name: 'ICON',
877
+ * text: 'user',
878
+ * colors: [ 'red', 'red', 'red' ],
879
+ * bndbox: BoundingBox {
880
+ * xmin: 900,
881
+ * ymin: 910,
882
+ * xmax: 920,
883
+ * ymax: 930
884
+ * }
885
+ * }
886
+ * ]
887
+ * ```
888
+ * You can combine filters with **the `and()` relation** and specify exactly which icon you want
889
+ * ```typescript
890
+ * const icons = await aui.get().icon().withText('user').and().colored('red').exec()
891
+ * console.log(icons)
892
+ * ```
893
+ * The get command returns only the red icon although both icons have the same text
894
+ * ```text
895
+ * console output: [
896
+ * DetectedElement {
897
+ * name: 'ICON',
898
+ * text: 'user',
899
+ * colors: [ 'red', 'red', 'red' ],
900
+ * bndbox: BoundingBox {
901
+ * xmin: 900,
902
+ * ymin: 910,
903
+ * xmax: 920,
904
+ * ymax: 930
905
+ * }
906
+ * }
907
+ * ]
908
+ * ```
909
+ *
910
+ * @return {FluentFilters}
911
+ */
912
+ and() {
913
+ this._textStr = 'and';
914
+ return new FluentFilters(this);
915
+ }
802
916
  /**
803
917
  * Filters for an element inside another element.
804
918
  *
@@ -1711,6 +1825,120 @@ class FluentFiltersCondition extends FluentBase {
1711
1825
  exports.FluentFiltersCondition = FluentFiltersCondition;
1712
1826
  // Relations
1713
1827
  class FluentFiltersOrRelationsCondition extends FluentFiltersCondition {
1828
+ /**
1829
+ * Logic or operator
1830
+ *
1831
+ * **Examples:**
1832
+ * ```text
1833
+ * scene 1
1834
+ * -------------- ---------------
1835
+ * | button | | icon |
1836
+ * -------------- ---------------
1837
+ *
1838
+ * scene 2
1839
+ * -------------- ---------------
1840
+ * | button | | text |
1841
+ * -------------- ---------------
1842
+ *
1843
+ * ```
1844
+ * In case, that your reference element can have multiple values, in the following example, the element right of the button can be either icon or text.
1845
+ * You can use **the `or()` relation**, so your teststep is valid for both scenes
1846
+ * ```typescript
1847
+ * const button = await aui.get().button().rightOf().icon().or().text().exec();
1848
+ * console.log(button);
1849
+ * ```
1850
+ * Returns the same button for both cases
1851
+ * ```text
1852
+ * console output: [
1853
+ * DetectedElement {
1854
+ * name: 'BUTTON',
1855
+ * text: 'button',
1856
+ * colors: [ 'red', 'black', 'red' ],
1857
+ * bndbox: BoundingBox {
1858
+ * xmin: 900,
1859
+ * ymin: 910,
1860
+ * xmax: 920,
1861
+ * ymax: 930
1862
+ * }
1863
+ * }
1864
+ * ]
1865
+ * ```
1866
+ *
1867
+ * @return {FluentFiltersCondition}
1868
+ */
1869
+ or() {
1870
+ this._textStr = 'or';
1871
+ return new FluentFiltersCondition(this);
1872
+ }
1873
+ /**
1874
+ * Logic and operator
1875
+ *
1876
+ * **Examples:**
1877
+ * ```text
1878
+ * example scene:
1879
+ * -------------------------- --------------------------
1880
+ * | icon user colored black | | icon user colored red |
1881
+ * -------------------------- --------------------------
1882
+ * ```
1883
+ * ```typescript
1884
+ * const icons = await aui.get().icon().withText('user').exec();
1885
+ * console.log(icons);
1886
+ * ```
1887
+ * Using only the filter withText, the get command will return both icons because they share the same text
1888
+ * ```text
1889
+ * console output: [
1890
+ * DetectedElement {
1891
+ * name: 'ICON',
1892
+ * text: 'user',
1893
+ * colors: [ 'black', 'black', 'black' ],
1894
+ * bndbox: BoundingBox {
1895
+ * xmin: 1000,
1896
+ * ymin: 1010,
1897
+ * xmax: 1020,
1898
+ * ymax: 1030
1899
+ * }
1900
+ * },
1901
+ * DetectedElement {
1902
+ * name: 'ICON',
1903
+ * text: 'user',
1904
+ * colors: [ 'red', 'red', 'red' ],
1905
+ * bndbox: BoundingBox {
1906
+ * xmin: 900,
1907
+ * ymin: 910,
1908
+ * xmax: 920,
1909
+ * ymax: 930
1910
+ * }
1911
+ * }
1912
+ * ]
1913
+ * ```
1914
+ * You can combine filters with **the `and()` relation** and specify exactly which icon you want
1915
+ * ```typescript
1916
+ * const icons = await aui.get().icon().withText('user').and().colored('red').exec()
1917
+ * console.log(icons)
1918
+ * ```
1919
+ * The get command returns only the red icon although both icons have the same text
1920
+ * ```text
1921
+ * console output: [
1922
+ * DetectedElement {
1923
+ * name: 'ICON',
1924
+ * text: 'user',
1925
+ * colors: [ 'red', 'red', 'red' ],
1926
+ * bndbox: BoundingBox {
1927
+ * xmin: 900,
1928
+ * ymin: 910,
1929
+ * xmax: 920,
1930
+ * ymax: 930
1931
+ * }
1932
+ * }
1933
+ * ]
1934
+ * ```
1935
+ *
1936
+ * @return {FluentFiltersCondition}
1937
+ */
1938
+ and() {
1939
+ this._textStr = 'and';
1940
+ return new FluentFiltersCondition(this);
1941
+ }
1714
1942
  /**
1715
1943
  * Filters for an element inside another element.
1716
1944
  *
@@ -2933,6 +3161,120 @@ class FluentFiltersGetter extends FluentBase {
2933
3161
  exports.FluentFiltersGetter = FluentFiltersGetter;
2934
3162
  // Relations
2935
3163
  class FluentFiltersOrRelationsGetter extends FluentFiltersGetter {
3164
+ /**
3165
+ * Logic or operator
3166
+ *
3167
+ * **Examples:**
3168
+ * ```text
3169
+ * scene 1
3170
+ * -------------- ---------------
3171
+ * | button | | icon |
3172
+ * -------------- ---------------
3173
+ *
3174
+ * scene 2
3175
+ * -------------- ---------------
3176
+ * | button | | text |
3177
+ * -------------- ---------------
3178
+ *
3179
+ * ```
3180
+ * In case, that your reference element can have multiple values, in the following example, the element right of the button can be either icon or text.
3181
+ * You can use **the `or()` relation**, so your teststep is valid for both scenes
3182
+ * ```typescript
3183
+ * const button = await aui.get().button().rightOf().icon().or().text().exec();
3184
+ * console.log(button);
3185
+ * ```
3186
+ * Returns the same button for both cases
3187
+ * ```text
3188
+ * console output: [
3189
+ * DetectedElement {
3190
+ * name: 'BUTTON',
3191
+ * text: 'button',
3192
+ * colors: [ 'red', 'black', 'red' ],
3193
+ * bndbox: BoundingBox {
3194
+ * xmin: 900,
3195
+ * ymin: 910,
3196
+ * xmax: 920,
3197
+ * ymax: 930
3198
+ * }
3199
+ * }
3200
+ * ]
3201
+ * ```
3202
+ *
3203
+ * @return {FluentFiltersGetter}
3204
+ */
3205
+ or() {
3206
+ this._textStr = 'or';
3207
+ return new FluentFiltersGetter(this);
3208
+ }
3209
+ /**
3210
+ * Logic and operator
3211
+ *
3212
+ * **Examples:**
3213
+ * ```text
3214
+ * example scene:
3215
+ * -------------------------- --------------------------
3216
+ * | icon user colored black | | icon user colored red |
3217
+ * -------------------------- --------------------------
3218
+ * ```
3219
+ * ```typescript
3220
+ * const icons = await aui.get().icon().withText('user').exec();
3221
+ * console.log(icons);
3222
+ * ```
3223
+ * Using only the filter withText, the get command will return both icons because they share the same text
3224
+ * ```text
3225
+ * console output: [
3226
+ * DetectedElement {
3227
+ * name: 'ICON',
3228
+ * text: 'user',
3229
+ * colors: [ 'black', 'black', 'black' ],
3230
+ * bndbox: BoundingBox {
3231
+ * xmin: 1000,
3232
+ * ymin: 1010,
3233
+ * xmax: 1020,
3234
+ * ymax: 1030
3235
+ * }
3236
+ * },
3237
+ * DetectedElement {
3238
+ * name: 'ICON',
3239
+ * text: 'user',
3240
+ * colors: [ 'red', 'red', 'red' ],
3241
+ * bndbox: BoundingBox {
3242
+ * xmin: 900,
3243
+ * ymin: 910,
3244
+ * xmax: 920,
3245
+ * ymax: 930
3246
+ * }
3247
+ * }
3248
+ * ]
3249
+ * ```
3250
+ * You can combine filters with **the `and()` relation** and specify exactly which icon you want
3251
+ * ```typescript
3252
+ * const icons = await aui.get().icon().withText('user').and().colored('red').exec()
3253
+ * console.log(icons)
3254
+ * ```
3255
+ * The get command returns only the red icon although both icons have the same text
3256
+ * ```text
3257
+ * console output: [
3258
+ * DetectedElement {
3259
+ * name: 'ICON',
3260
+ * text: 'user',
3261
+ * colors: [ 'red', 'red', 'red' ],
3262
+ * bndbox: BoundingBox {
3263
+ * xmin: 900,
3264
+ * ymin: 910,
3265
+ * xmax: 920,
3266
+ * ymax: 930
3267
+ * }
3268
+ * }
3269
+ * ]
3270
+ * ```
3271
+ *
3272
+ * @return {FluentFiltersGetter}
3273
+ */
3274
+ and() {
3275
+ this._textStr = 'and';
3276
+ return new FluentFiltersGetter(this);
3277
+ }
2936
3278
  /**
2937
3279
  * Filters for an element inside another element.
2938
3280
  *
@@ -3114,7 +3456,32 @@ exports.FluentFiltersOrRelationsGetter = FluentFiltersOrRelationsGetter;
3114
3456
  // Commands
3115
3457
  class Getter extends FluentCommand {
3116
3458
  /**
3117
- * Returns the filtered element
3459
+ * Returns an array with all filtered elements.
3460
+ * A detected element has the following properties:
3461
+ * - `name` of the element
3462
+ * - `text` content of element
3463
+ * - `colors` of element
3464
+ * - `bndbox`: location of element described with coordinates of a bounding box
3465
+ * **Examples:**
3466
+ * ```typescript
3467
+ * const text = await aui.get().text().withText('Sign').exec();
3468
+ * console.log(text);
3469
+ * ```
3470
+ * ```text
3471
+ * console output: [
3472
+ * DetectedElement {
3473
+ * name: 'TEXT',
3474
+ * text: 'Sign In',
3475
+ * colors: [ 'black', 'gray', 'gray' ],
3476
+ * bndbox: BoundingBox {
3477
+ * xmin: 1128.2720982142857,
3478
+ * ymin: 160.21332310267857,
3479
+ * xmax: 1178.8204241071428,
3480
+ * ymax: 180.83512834821428
3481
+ * }
3482
+ * }
3483
+ * ]
3484
+ * ```
3118
3485
  *
3119
3486
  * @return {FluentFiltersGetter}
3120
3487
  */
@@ -3123,7 +3490,43 @@ class Getter extends FluentCommand {
3123
3490
  return new FluentFiltersGetter(this);
3124
3491
  }
3125
3492
  /**
3126
- * Returns all detected elements
3493
+ * Returns an array with all detected elements.
3494
+ * A detected element has the following properties:
3495
+ * - `name` of the element
3496
+ * - `text` content of element
3497
+ * - `colors` of element
3498
+ * - `bndbox`: location of element described with coordinates of a bounding box
3499
+ * **Examples:**
3500
+ * ```typescript
3501
+ * const detectedElements = await aui.getAll().exec();
3502
+ * console.log(detectedElements);
3503
+ * ```
3504
+ * ```text
3505
+ * console output: [
3506
+ * DetectedElement {
3507
+ * name: 'TEXT',
3508
+ * text: 'Sign In',
3509
+ * colors: [ 'black', 'gray', 'gray' ],
3510
+ * bndbox: BoundingBox {
3511
+ * xmin: 1128.2720982142857,
3512
+ * ymin: 160.21332310267857,
3513
+ * xmax: 1178.8204241071428,
3514
+ * ymax: 180.83512834821428
3515
+ * },
3516
+ * DetectedElement {
3517
+ * name: 'ICON',
3518
+ * text: 'search',
3519
+ * colors: [ 'black', 'red', 'gray' ],
3520
+ * bndbox: BoundingBox {
3521
+ * xmin: 250.8204241071428,
3522
+ * ymin: 300.21332310267857,
3523
+ * xmax: 450.6304241071428,
3524
+ * ymax: 950.47812834821428
3525
+ * },
3526
+ * ... 381 more items
3527
+ * }
3528
+ * ]
3529
+ * ```
3127
3530
  *
3128
3531
  * @return {ExecGetter}
3129
3532
  */
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -8,14 +17,36 @@ const commander_1 = require("commander");
8
17
  const path_1 = __importDefault(require("path"));
9
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
10
19
  const path_2 = require("../utils/path");
20
+ const logger_1 = require("./logger");
11
21
  const createProgram = () => {
12
22
  const program = new commander_1.Command('askui');
13
23
  program.usage('<command> [options]');
14
24
  return program;
15
25
  };
16
- function copyExampleProject() {
17
- const exampleProjectPath = path_1.default.join('example_projects_templates', 'typescript_jest');
18
- fs_extra_1.default.copySync(path_1.default.join((0, path_2.getPathToNodeModulesRoot)(), exampleProjectPath), '.');
26
+ function replaceStringInFile(filePath, replace, replacement) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ const data = yield fs_extra_1.default.readFile(filePath, 'utf8');
30
+ const result = data.replace(replace, replacement);
31
+ yield fs_extra_1.default.writeFile(filePath, result, 'utf8');
32
+ }
33
+ catch (error) {
34
+ logger_1.logger.error(`Could not replace '${replace}' with '${replacement}' in file '${path_1.default}'`);
35
+ logger_1.logger.error(error.message);
36
+ }
37
+ });
38
+ }
39
+ function copyExampleProject(options) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const exampleProjectPath = path_1.default.join('example_projects_templates', 'typescript_jest');
42
+ fs_extra_1.default.copySync(path_1.default.join((0, path_2.getPathToNodeModulesRoot)(), exampleProjectPath), '.');
43
+ if (options['workspaceId']) {
44
+ yield replaceStringInFile('./test/helper/jest.setup.ts', '<your workspace id>', options['workspaceId']);
45
+ }
46
+ if (options['accessToken']) {
47
+ yield replaceStringInFile('./test/helper/jest.setup.ts', '<your access token>', options['accessToken']);
48
+ }
49
+ });
19
50
  }
20
51
  function init(argv) {
21
52
  const args = argv || process.argv;
@@ -23,7 +54,12 @@ function init(argv) {
23
54
  program
24
55
  .command('init')
25
56
  .description('creates a typescript example project')
26
- .action(() => { copyExampleProject(); });
57
+ .option('-w, --workspace-id <value>', 'a workspace id')
58
+ .option('-a, --access-token <value>', 'an access token for the workspace with the id')
59
+ .usage('[-w workspace_id] [-a access_token]')
60
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
61
+ yield copyExampleProject(opts);
62
+ }));
27
63
  return program.parse(args);
28
64
  }
29
65
  exports.init = init;