@mablhq/mabl-cli 2.70.35 → 2.72.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 (59) hide show
  1. package/api/mablApiClient.js +2 -4
  2. package/execution/index.js +1 -1
  3. package/mablscript/MablStepV2.js +40 -10
  4. package/mablscript/MablStepWithFindAction.js +126 -2
  5. package/mablscript/actions/AwaitDownloadAction.js +4 -3
  6. package/mablscript/actions/AwaitPDFDownloadAction.js +6 -5
  7. package/mablscript/actions/ConditionAction.js +2 -1
  8. package/mablscript/actions/ExtractAction.js +8 -13
  9. package/mablscript/actions/FindAction.js +20 -0
  10. package/mablscript/actions/GetVariableValue.js +15 -4
  11. package/mablscript/actions/JavaScriptAction.js +25 -39
  12. package/mablscript/diffing/diffingUtil.js +5 -5
  13. package/mablscript/importer.js +79 -59
  14. package/mablscript/mobile/steps/CreateVariableMobileStep.js +3 -1
  15. package/mablscript/steps/AbstractAssertionsAndVariablesStep.js +10 -8
  16. package/mablscript/steps/AccessibilityCheck.js +76 -36
  17. package/mablscript/steps/AssertStep.js +266 -86
  18. package/mablscript/steps/AssertStepOld.js +69 -139
  19. package/mablscript/steps/AwaitTabStep.js +30 -9
  20. package/mablscript/steps/AwaitUploadsStep.js +22 -8
  21. package/mablscript/steps/ClearCookiesStep.js +22 -8
  22. package/mablscript/steps/ClickAndHoldStep.js +45 -47
  23. package/mablscript/steps/ClickStep.js +36 -33
  24. package/mablscript/steps/CreateVariableStep.js +169 -137
  25. package/mablscript/steps/DatabaseQueryStep.js +14 -4
  26. package/mablscript/steps/DoubleClickStep.js +37 -40
  27. package/mablscript/steps/DownloadStep.js +79 -63
  28. package/mablscript/steps/EchoStep.js +26 -8
  29. package/mablscript/steps/ElseIfConditionStep.js +23 -12
  30. package/mablscript/steps/ElseStep.js +22 -9
  31. package/mablscript/steps/EndStep.js +22 -9
  32. package/mablscript/steps/EnterAuthCodeStep.js +36 -34
  33. package/mablscript/steps/EnterTextStep.js +51 -64
  34. package/mablscript/steps/EvaluateFlowStep.js +39 -18
  35. package/mablscript/steps/EvaluateJavaScriptStep.js +17 -19
  36. package/mablscript/steps/HoverStep.js +37 -39
  37. package/mablscript/steps/IfConditionStep.js +139 -99
  38. package/mablscript/steps/NavigateStep.js +29 -9
  39. package/mablscript/steps/OpenEmailStep.js +39 -21
  40. package/mablscript/steps/ReleaseStep.js +46 -38
  41. package/mablscript/steps/RemoveCookieStep.js +25 -9
  42. package/mablscript/steps/RightClickStep.js +36 -33
  43. package/mablscript/steps/SelectStep.js +69 -46
  44. package/mablscript/steps/SendHttpRequestStep.js +13 -4
  45. package/mablscript/steps/SendKeyStep.js +174 -50
  46. package/mablscript/steps/SetCookieStep.js +56 -23
  47. package/mablscript/steps/SetFilesStep.js +42 -43
  48. package/mablscript/steps/SetViewportStep.js +39 -13
  49. package/mablscript/steps/StepGroupStep.js +70 -0
  50. package/mablscript/steps/SwitchContextStep.js +89 -83
  51. package/mablscript/steps/SyntheticStep.js +1 -1
  52. package/mablscript/steps/VisitUrlStep.js +30 -22
  53. package/mablscript/steps/WaitStep.js +20 -9
  54. package/mablscript/steps/WaitUntilStep.js +31 -14
  55. package/mablscript/types/AssertStepDescriptor.js +2 -0
  56. package/mablscript/types/ConditionDescriptor.js +5 -5
  57. package/mablscript/types/GetVariableDescriptor.js +0 -8
  58. package/mablscript/types/StepGroupStepDescriptor.js +2 -0
  59. package/package.json +1 -1
@@ -1,95 +1,111 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DownloadStep = void 0;
4
- const MablStep_1 = require("../MablStep");
4
+ const MablStepV2_1 = require("../MablStepV2");
5
5
  const MablAction_1 = require("../MablAction");
6
6
  const AwaitDownloadAction_1 = require("../actions/AwaitDownloadAction");
7
7
  const AwaitPDFDownloadAction_1 = require("../actions/AwaitPDFDownloadAction");
8
8
  const domUtil_1 = require("../../domUtil");
9
- class DownloadStep extends MablStep_1.MablStep {
10
- constructor(name, args, actions) {
11
- super(name, args, actions, 'assert_download');
12
- this.validate();
13
- this.fileAttributes = (this.getActionArgs()[0] ?? {});
14
- this.awaitDownloadAction = this.actions[0];
9
+ class DownloadStep extends MablStepV2_1.MablStepV2 {
10
+ constructor(stepName, descriptor) {
11
+ super(stepName, descriptor, DownloadStep.actionCode);
12
+ const isPdfDownload = stepName === DownloadStep.pdfStepName;
13
+ if (isPdfDownload) {
14
+ if (!descriptor.tabIdentifier) {
15
+ throw new Error('DownloadPdfStep must have a tabIdentifier');
16
+ }
17
+ this.awaitDownloadAction = new AwaitPDFDownloadAction_1.AwaitPDFDownloadAction('await_pdf', [
18
+ { uuid: descriptor.tabIdentifier },
19
+ ]);
20
+ }
21
+ else {
22
+ this.awaitDownloadAction = new AwaitDownloadAction_1.AwaitDownloadAction('await_download', []);
23
+ }
24
+ this.fileAttributes =
25
+ DownloadStep.populateDownloadArgsFromDescriptor(descriptor);
26
+ }
27
+ static populateDownloadArgsFromDescriptor(descriptor) {
28
+ return {
29
+ file_name: descriptor.fileName,
30
+ file_mime_type: descriptor.mimeType,
31
+ file_md5: descriptor.fileMd5,
32
+ file_sha256: descriptor.fileSha256,
33
+ file_size_bytes: descriptor.sizeBytes,
34
+ file_size_bytes_max: descriptor.sizeBytesMax,
35
+ file_size_bytes_min: descriptor.sizeBytesMin,
36
+ };
15
37
  }
16
- validate() {
17
- if (this.actions.length !== 1 &&
18
- !(this.actions[0] instanceof AwaitDownloadAction_1.AwaitDownloadAction)) {
38
+ validate(actions) {
39
+ if (actions.length !== 1 && !(actions[0] instanceof AwaitDownloadAction_1.AwaitDownloadAction)) {
19
40
  throw new Error('Download step should contain an await download sub action');
20
41
  }
21
42
  }
22
43
  getStepName() {
23
44
  if (this.isPDFDownload()) {
24
- return 'DownloadPdfStep';
45
+ return DownloadStep.pdfStepName;
25
46
  }
26
- return 'DownloadStep';
47
+ return DownloadStep.stepName;
27
48
  }
28
49
  isPDFDownload() {
29
50
  return this.awaitDownloadAction instanceof AwaitPDFDownloadAction_1.AwaitPDFDownloadAction;
30
51
  }
31
52
  toStepDescriptor() {
32
- const formatted = {};
33
- if (this.isPDFDownload()) {
34
- formatted.tabIdentifier = this.actions[0].pdfUUID;
35
- }
36
- if (this.fileAttributes.file_name !== undefined) {
37
- formatted.fileName = this.fileAttributes.file_name;
38
- }
39
- if (this.fileAttributes.file_mime_type !== undefined) {
40
- formatted.mimeType = this.fileAttributes.file_mime_type;
41
- }
42
- if (this.fileAttributes.file_md5 !== undefined) {
43
- formatted.fileMd5 = this.fileAttributes.file_md5;
44
- }
45
- if (this.fileAttributes.file_sha256 !== undefined) {
46
- formatted.fileSha256 = this.fileAttributes.file_sha256;
47
- }
48
- if (this.fileAttributes.file_size_bytes !== undefined) {
49
- formatted.sizeBytes = this.fileAttributes.file_size_bytes;
50
- }
51
- if (this.fileAttributes.file_size_bytes_max !== undefined) {
52
- formatted.sizeBytesMax = this.fileAttributes.file_size_bytes_max;
53
- }
54
- if (this.fileAttributes.file_size_bytes_min !== undefined) {
55
- formatted.sizeBytesMin = this.fileAttributes.file_size_bytes_min;
56
- }
57
- return formatted;
53
+ return this.descriptor;
58
54
  }
59
- static fromYaml(_stepName, stepArgs) {
60
- const fileAttributes = {};
61
- const assertDownload = stepArgs;
62
- fileAttributes.file_name = assertDownload.fileName;
63
- fileAttributes.file_mime_type = assertDownload.mimeType;
64
- fileAttributes.file_md5 = assertDownload.fileMd5;
65
- fileAttributes.file_sha256 = assertDownload.fileSha256;
66
- fileAttributes.file_size_bytes = assertDownload.sizeBytes;
67
- fileAttributes.file_size_bytes_max = assertDownload.sizeBytesMax;
68
- fileAttributes.file_size_bytes_min = assertDownload.sizeBytesMin;
69
- let awaitDownloadAction;
70
- if (assertDownload.tabIdentifier) {
71
- awaitDownloadAction = new AwaitPDFDownloadAction_1.AwaitPDFDownloadAction('await_pdf', [
72
- { uuid: assertDownload.tabIdentifier },
73
- ]);
74
- }
75
- else {
76
- awaitDownloadAction = new AwaitDownloadAction_1.AwaitDownloadAction('await_download', []);
77
- }
78
- const step = new DownloadStep('assert_download', [fileAttributes], [awaitDownloadAction]);
55
+ static fromYaml(stepName, stepArgs) {
56
+ const stepDescriptor = stepArgs;
57
+ const step = new DownloadStep(stepName, stepDescriptor);
79
58
  step.setStepId(stepArgs.id);
80
59
  return step;
81
60
  }
61
+ static fromLegacyMablscript(args, actions) {
62
+ DownloadStep.validateLegacyActions(actions);
63
+ const fileAttributes = (args[0] ?? {});
64
+ const awaitDownloadAction = actions[0];
65
+ const stepDescriptor = {
66
+ fileName: fileAttributes.file_name,
67
+ mimeType: fileAttributes.file_mime_type,
68
+ sizeBytes: fileAttributes.file_size_bytes,
69
+ sizeBytesMax: fileAttributes.file_size_bytes_max,
70
+ sizeBytesMin: fileAttributes.file_size_bytes_min,
71
+ fileMd5: fileAttributes.file_md5,
72
+ fileSha256: fileAttributes.file_sha256,
73
+ };
74
+ const isPdfDownload = awaitDownloadAction instanceof AwaitPDFDownloadAction_1.AwaitPDFDownloadAction;
75
+ if (isPdfDownload) {
76
+ stepDescriptor.tabIdentifier = awaitDownloadAction.pdfUUID;
77
+ }
78
+ const stepName = isPdfDownload
79
+ ? DownloadStep.pdfStepName
80
+ : DownloadStep.stepName;
81
+ return new DownloadStep(stepName, stepDescriptor);
82
+ }
83
+ static validateLegacyActions(actions) {
84
+ if (actions.length !== 1 && !(actions[0] instanceof AwaitDownloadAction_1.AwaitDownloadAction)) {
85
+ throw new Error('Download step should contain an await download sub action');
86
+ }
87
+ }
82
88
  toMablscript() {
89
+ const meaningfulAttributes = DownloadStep.populateDownloadArgsFromDescriptor(this.toStepDescriptor());
83
90
  const mablArgs = (0, domUtil_1.buildStepArgumentString)({
84
- params: { ...this.fileAttributes },
91
+ params: meaningfulAttributes,
85
92
  legacy: true,
86
93
  });
87
- return `${this.awaitDownloadAction.toMablscript()}.assert_download(${mablArgs ? mablArgs : ''})`;
94
+ return `${this.awaitDownloadAction.toMablscript()}.assert_download(${mablArgs ?? '{}'})`;
88
95
  }
89
96
  getInputVariables() {
90
- return MablAction_1.MablAction.findUniqueVariableReferencesInValue(this.fileAttributes);
97
+ return MablAction_1.MablAction.findUniqueVariableReferencesInValue(this.descriptor);
98
+ }
99
+ stepDescription() {
100
+ return 'Assert file download';
91
101
  }
92
102
  }
93
103
  exports.DownloadStep = DownloadStep;
94
- DownloadStep.mablScriptStepNames = ['assert_download'];
95
- DownloadStep.yamlMablScriptNames = ['DownloadStep', 'DownloadPdfStep'];
104
+ DownloadStep.stepName = 'DownloadStep';
105
+ DownloadStep.pdfStepName = 'DownloadPdfStep';
106
+ DownloadStep.actionCode = 'assert_download';
107
+ DownloadStep.mablScriptStepNames = [DownloadStep.actionCode];
108
+ DownloadStep.yamlMablScriptNames = [
109
+ DownloadStep.stepName,
110
+ DownloadStep.pdfStepName,
111
+ ];
@@ -1,25 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EchoStep = void 0;
4
- const MablStep_1 = require("../MablStep");
5
4
  const domUtil_1 = require("../../domUtil");
6
5
  const MablAction_1 = require("../MablAction");
7
- class EchoStep extends MablStep_1.MablStep {
8
- constructor(name, args, actions) {
9
- super(name, args, actions, 'echo');
10
- this.echoValue = (0, MablAction_1.parseArgument)(this.getActionArgs()[0]);
6
+ const MablStepV2_1 = require("../MablStepV2");
7
+ class EchoStep extends MablStepV2_1.MablStepV2 {
8
+ constructor(descriptor) {
9
+ super(EchoStep.stepName, descriptor, EchoStep.actionCode);
10
+ this.echoValue = descriptor.value;
11
+ }
12
+ static getStepName() {
13
+ return EchoStep.stepName;
11
14
  }
12
15
  getStepName() {
13
16
  return EchoStep.stepName;
14
17
  }
15
18
  toStepDescriptor() {
16
- return { value: this.echoValue.toString(), actionCode: this.actionCode };
19
+ return { value: this.echoValue, actionCode: this.actionCode };
17
20
  }
18
21
  static fromYaml(_stepName, stepArgs) {
19
- const step = new EchoStep(EchoStep.stepName, [stepArgs.value], []);
22
+ const stepDescriptor = {
23
+ actionCode: EchoStep.actionCode,
24
+ value: (0, MablAction_1.parseArgument)(stepArgs.value),
25
+ };
26
+ const step = new EchoStep(stepDescriptor);
20
27
  step.setStepId(stepArgs.id);
21
28
  return step;
22
29
  }
30
+ static fromLegacyMablscript(args, _actions) {
31
+ const stepDescriptor = {
32
+ actionCode: EchoStep.actionCode,
33
+ value: (0, MablAction_1.parseArgument)(args[0]),
34
+ };
35
+ return new EchoStep(stepDescriptor);
36
+ }
23
37
  toMablscript() {
24
38
  const stringEchoValue = `${this.echoValue}`;
25
39
  return `echo("${(0, domUtil_1.escapeMablscriptString)(stringEchoValue)}")`;
@@ -27,8 +41,12 @@ class EchoStep extends MablStep_1.MablStep {
27
41
  getInputVariables() {
28
42
  return MablAction_1.MablAction.findUniqueVariableReferencesInValue(this.echoValue);
29
43
  }
44
+ stepDescription() {
45
+ return `Echo: "${this.echoValue}"`;
46
+ }
30
47
  }
31
48
  exports.EchoStep = EchoStep;
32
49
  EchoStep.stepName = 'Echo';
33
- EchoStep.mablScriptStepNames = ['echo'];
50
+ EchoStep.actionCode = 'echo';
51
+ EchoStep.mablScriptStepNames = [EchoStep.actionCode];
34
52
  EchoStep.yamlMablScriptNames = [EchoStep.stepName];
@@ -2,30 +2,41 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ElseIfConditionStep = void 0;
4
4
  exports.isElseIfConditionStep = isElseIfConditionStep;
5
- const MablAction_1 = require("../MablAction");
6
5
  const IfConditionStep_1 = require("./IfConditionStep");
7
6
  class ElseIfConditionStep extends IfConditionStep_1.IfConditionStep {
7
+ constructor(descriptor, stepActions) {
8
+ super(ElseIfConditionStep.stepName, ElseIfConditionStep.actionCode, descriptor, stepActions);
9
+ }
8
10
  getStepName() {
9
- return 'ElseIf';
11
+ return ElseIfConditionStep.stepName;
10
12
  }
11
13
  static fromYaml(_stepName, stepArgs) {
12
- const actions = [
13
- new MablAction_1.MablAction('conditional_else', 'conditional_else_if', []),
14
- ];
15
- actions.push(...IfConditionStep_1.IfConditionStep.getActionsFromYamlForCondition(stepArgs));
16
- const step = new ElseIfConditionStep('conditional_else_if', [], actions);
14
+ const actions = IfConditionStep_1.IfConditionStep.getActionsFromYamlForCondition(stepArgs);
15
+ const validatedActions = IfConditionStep_1.IfConditionStep.validateAndParseActions(actions);
16
+ const stepDescriptor = IfConditionStep_1.IfConditionStep.buildDescriptor(validatedActions);
17
+ const step = new ElseIfConditionStep(stepDescriptor, validatedActions);
17
18
  step.setStepId(stepArgs.id);
18
19
  return step;
19
20
  }
21
+ static fromLegacyMablscript(_args, actions) {
22
+ const validatedActions = IfConditionStep_1.IfConditionStep.validateAndParseActions(actions);
23
+ const stepDescriptor = IfConditionStep_1.IfConditionStep.buildDescriptor(validatedActions);
24
+ return new ElseIfConditionStep(stepDescriptor, validatedActions);
25
+ }
20
26
  toMablscript() {
21
- const actions = this.actions.reduce((mablscript, action) => `${mablscript}${action.toMablscript()}.`, '');
22
- return `conditional_else()${actions}conditional_else_if()`;
27
+ const actions = [
28
+ this.primaryAction,
29
+ this.extractAction,
30
+ this.conditionAction,
31
+ ].filter(Boolean);
32
+ return `conditional_else().${actions.reduce((mablscript, action) => `${mablscript}${action?.toMablscript()}.`, '')}conditional_else_if()`;
23
33
  }
24
34
  }
25
35
  exports.ElseIfConditionStep = ElseIfConditionStep;
26
- ElseIfConditionStep.stepName = 'conditional_else_if';
27
- ElseIfConditionStep.mablScriptStepNames = [ElseIfConditionStep.stepName];
28
- ElseIfConditionStep.yamlMablScriptNames = ['ElseIf'];
36
+ ElseIfConditionStep.stepName = 'ElseIf';
37
+ ElseIfConditionStep.actionCode = 'conditional_else_if';
38
+ ElseIfConditionStep.mablScriptStepNames = [ElseIfConditionStep.actionCode];
39
+ ElseIfConditionStep.yamlMablScriptNames = [ElseIfConditionStep.stepName];
29
40
  function isElseIfConditionStep(value) {
30
41
  return (value?.getStepName &&
31
42
  value?.getStepName() === ElseIfConditionStep.yamlMablScriptNames[0]);
@@ -1,27 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ElseStep = void 0;
4
- const MablStep_1 = require("../MablStep");
5
- class ElseStep extends MablStep_1.MablStep {
6
- constructor(name, args, actions) {
7
- super(name, args, actions, 'conditional_else');
4
+ const MablStepV2_1 = require("../MablStepV2");
5
+ class ElseStep extends MablStepV2_1.MablStepV2 {
6
+ constructor(descriptor) {
7
+ super(ElseStep.stepName, descriptor, ElseStep.actionCode);
8
8
  }
9
9
  getStepName() {
10
- return 'Else';
10
+ return ElseStep.stepName;
11
11
  }
12
12
  toStepDescriptor() {
13
13
  return { actionCode: this.actionCode };
14
14
  }
15
15
  static fromYaml(_stepName, stepArgs) {
16
- const step = new ElseStep('conditional_else', [], []);
16
+ const stepDescriptor = {
17
+ actionCode: ElseStep.actionCode,
18
+ };
19
+ const step = new ElseStep(stepDescriptor);
17
20
  step.setStepId(stepArgs.id);
18
21
  return step;
19
22
  }
23
+ static fromLegacyMablscript(_args, _actions) {
24
+ const stepDescriptor = {
25
+ actionCode: ElseStep.actionCode,
26
+ };
27
+ return new ElseStep(stepDescriptor);
28
+ }
20
29
  toMablscript() {
21
30
  return `conditional_else()`;
22
31
  }
32
+ stepDescription() {
33
+ return 'ELSE';
34
+ }
23
35
  }
24
36
  exports.ElseStep = ElseStep;
25
- ElseStep.stepName = 'conditional_else';
26
- ElseStep.mablScriptStepNames = [ElseStep.stepName];
27
- ElseStep.yamlMablScriptNames = ['Else'];
37
+ ElseStep.stepName = 'Else';
38
+ ElseStep.actionCode = 'conditional_else';
39
+ ElseStep.mablScriptStepNames = [ElseStep.actionCode];
40
+ ElseStep.yamlMablScriptNames = [ElseStep.stepName];
@@ -1,27 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EndStep = void 0;
4
- const MablStep_1 = require("../MablStep");
5
- class EndStep extends MablStep_1.MablStep {
6
- constructor(name, args, actions) {
7
- super(name, args, actions, 'conditional_end');
4
+ const MablStepV2_1 = require("../MablStepV2");
5
+ class EndStep extends MablStepV2_1.MablStepV2 {
6
+ constructor(descriptor) {
7
+ super(EndStep.stepName, descriptor, EndStep.actionCode);
8
8
  }
9
9
  getStepName() {
10
- return 'End';
10
+ return EndStep.stepName;
11
11
  }
12
12
  toStepDescriptor() {
13
13
  return { actionCode: this.actionCode };
14
14
  }
15
15
  static fromYaml(_stepName, stepArgs) {
16
- const step = new EndStep('conditional_end', [], []);
16
+ const stepDescriptor = {
17
+ actionCode: EndStep.actionCode,
18
+ };
19
+ const step = new EndStep(stepDescriptor);
17
20
  step.setStepId(stepArgs.id);
18
21
  return step;
19
22
  }
23
+ static fromLegacyMablscript(_args, _actions) {
24
+ const stepDescriptor = {
25
+ actionCode: EndStep.actionCode,
26
+ };
27
+ return new EndStep(stepDescriptor);
28
+ }
20
29
  toMablscript() {
21
30
  return `conditional_end()`;
22
31
  }
32
+ stepDescription() {
33
+ return 'END';
34
+ }
23
35
  }
24
36
  exports.EndStep = EndStep;
25
- EndStep.stepName = 'conditional_end';
26
- EndStep.mablScriptStepNames = [EndStep.stepName];
27
- EndStep.yamlMablScriptNames = ['End'];
37
+ EndStep.stepName = 'End';
38
+ EndStep.actionCode = 'conditional_end';
39
+ EndStep.mablScriptStepNames = [EndStep.actionCode];
40
+ EndStep.yamlMablScriptNames = [EndStep.stepName];
@@ -6,54 +6,56 @@ const domUtil_1 = require("../../domUtil");
6
6
  const ActionsUtils_1 = require("./ActionsUtils");
7
7
  const MablStepWithFindAction_1 = require("../MablStepWithFindAction");
8
8
  class EnterAuthCodeStep extends MablStepWithFindAction_1.MablStepWithFindAction {
9
- constructor(name, args, actions) {
10
- super(name, args, actions, EnterAuthCodeStep.stepName);
11
- this.findAction = ActionsUtils_1.ActionsUtils.validateSingleFindAction(this.actions);
9
+ constructor(descriptor, findAction) {
10
+ super(EnterAuthCodeStep.stepName, descriptor, EnterAuthCodeStep.actionCode, findAction);
12
11
  }
13
12
  getStepName() {
14
- return 'EnterAuthCode';
13
+ return EnterAuthCodeStep.stepName;
15
14
  }
16
15
  toStepDescriptor() {
17
- const find = this.findAction.toDescriptor();
18
- switch (find.findType) {
19
- case domUtil_1.FindType.FIND_FIRST:
20
- case domUtil_1.FindType.FIND_LAST:
21
- case domUtil_1.FindType.FIND_ANY:
22
- case domUtil_1.FindType.FIND_ONE:
23
- return {
24
- find,
25
- descriptorToActionMap: new Map().set(find, this.findAction),
26
- actionCode: this.actionCode,
27
- };
28
- default:
29
- throw new Error(`Error generating step descriptor for ${this.getStepName()}: Unexpected find type ${find.findType}`);
30
- }
31
- }
32
- getFormattedStep(_fullLocatorsOn) {
33
- const step = {
34
- EnterAuthCode: {
35
- ...super.annotationsAsYml(),
36
- ...this.findAction.toYaml(),
37
- },
38
- };
39
- if (this.stepId()) {
40
- step.EnterAuthCode.id = this.stepId();
41
- }
42
- return step;
16
+ return buildStepDescriptor(this.findAction);
43
17
  }
44
18
  static fromYaml(_stepName, stepArgs) {
45
- const step = new EnterAuthCodeStep(EnterAuthCodeStep.stepName, [], [FindAction_1.FindAction.findActionFromStepArgs(stepArgs)]);
19
+ const findAction = FindAction_1.FindAction.findActionFromStepArgs(stepArgs);
20
+ const stepDescriptor = buildStepDescriptor(findAction);
21
+ const step = new EnterAuthCodeStep(stepDescriptor, findAction);
46
22
  step.setStepId(stepArgs.id);
47
23
  return step;
48
24
  }
25
+ static fromLegacyMablscript(_args, actions) {
26
+ const findAction = ActionsUtils_1.ActionsUtils.validateSingleFindAction(actions);
27
+ const stepDescriptor = buildStepDescriptor(findAction);
28
+ return new EnterAuthCodeStep(stepDescriptor, findAction);
29
+ }
49
30
  toMablscript() {
50
31
  return `${this.findAction.toMablscript()}.enter_auth_code()`;
51
32
  }
52
33
  getInputVariables() {
53
34
  return this.findAction.getInputVariables();
54
35
  }
36
+ stepDescription() {
37
+ const elementDescription = this.humanizeFind();
38
+ return `Enter authentication code into ${elementDescription}`;
39
+ }
55
40
  }
56
41
  exports.EnterAuthCodeStep = EnterAuthCodeStep;
57
- EnterAuthCodeStep.stepName = 'enter_auth_code';
58
- EnterAuthCodeStep.mablScriptStepNames = [EnterAuthCodeStep.stepName];
59
- EnterAuthCodeStep.yamlMablScriptNames = ['EnterAuthCode'];
42
+ EnterAuthCodeStep.stepName = 'EnterAuthCode';
43
+ EnterAuthCodeStep.actionCode = 'enter_auth_code';
44
+ EnterAuthCodeStep.mablScriptStepNames = [EnterAuthCodeStep.actionCode];
45
+ EnterAuthCodeStep.yamlMablScriptNames = [EnterAuthCodeStep.stepName];
46
+ function buildStepDescriptor(findAction) {
47
+ const find = findAction.toDescriptor();
48
+ switch (find.findType) {
49
+ case domUtil_1.FindType.FIND_FIRST:
50
+ case domUtil_1.FindType.FIND_LAST:
51
+ case domUtil_1.FindType.FIND_ANY:
52
+ case domUtil_1.FindType.FIND_ONE:
53
+ return {
54
+ find,
55
+ descriptorToActionMap: new Map().set(find, findAction),
56
+ actionCode: EnterAuthCodeStep.actionCode,
57
+ };
58
+ default:
59
+ throw new Error(`Error generating step descriptor for EnterAuthCode: Unexpected find type ${find.findType}`);
60
+ }
61
+ }
@@ -3,80 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EnterTextStep = void 0;
4
4
  const FindAction_1 = require("../actions/FindAction");
5
5
  const MablAction_1 = require("../MablAction");
6
+ const MablSymbol_1 = require("../MablSymbol");
6
7
  const domUtil_1 = require("../../domUtil");
7
8
  const MablStepWithFindAction_1 = require("../MablStepWithFindAction");
9
+ const ActionsUtils_1 = require("./ActionsUtils");
8
10
  class EnterTextStep extends MablStepWithFindAction_1.MablStepWithFindAction {
9
- constructor(name, args, actions) {
10
- super(name, args, actions, 'enter_text');
11
- const arg = this.getActionArgs()[0];
12
- this.text = (0, MablAction_1.parseArgument)(arg);
13
- this.validate();
14
- if ((0, domUtil_1.isFindElementType)(this.actions[0].getActionName())) {
15
- this.findAction = this.actions[0];
16
- }
17
- else {
18
- throw new Error(`Unexpected find action for ${name} step: ${JSON.stringify(this.actions[0])}`);
19
- }
20
- }
21
- validate() {
22
- if (this.actions.length !== 1 && !(this.actions[0] instanceof FindAction_1.FindAction)) {
23
- throw new Error('Enter text steps should have exactly on sub action and it should be a find');
24
- }
11
+ constructor(descriptor, findAction) {
12
+ super(EnterTextStep.stepName, descriptor, EnterTextStep.actionCode, findAction);
13
+ this.text = descriptor.text;
25
14
  }
26
15
  getStepName() {
27
- return 'EnterText';
16
+ return EnterTextStep.stepName;
28
17
  }
29
18
  toStepDescriptor() {
30
- const find = this.findAction.toDescriptor();
31
- switch (find.findType) {
32
- case domUtil_1.FindType.FIND_FIRST:
33
- case domUtil_1.FindType.FIND_LAST:
34
- case domUtil_1.FindType.FIND_ANY:
35
- case domUtil_1.FindType.FIND_ONE:
36
- return {
37
- find,
38
- descriptorToActionMap: new Map().set(find, this.findAction),
39
- text: this.text,
40
- actionCode: this.actionCode,
41
- };
42
- default:
43
- throw new Error(`Error generating step descriptor for ${this.getStepName()}: Unexpected find type ${find.findType}`);
44
- }
45
- }
46
- getFormattedStep() {
47
- const step = this.toStepDescriptor();
48
- const stepName = this.getStepName();
49
- const formatted = {
50
- [stepName]: {},
51
- };
52
- if (this.annotationsOnStep()) {
53
- formatted[stepName].annotation = this.annotation;
54
- }
55
- if (this.description) {
56
- formatted[stepName].description = this.description;
57
- }
58
- if (step.find.findType === domUtil_1.FindType.FIND_ONE) {
59
- formatted[stepName].selector = step.find.findTarget.selector;
60
- if (step.find.findTarget.auxiliaryDescriptors?.length) {
61
- formatted[stepName].selectorAncestors =
62
- step.find.findTarget.auxiliaryDescriptors.map((descriptor) => descriptor.selector);
63
- }
64
- }
65
- else {
66
- formatted[stepName].selector = step.find.findTarget;
67
- }
68
- formatted[stepName].findType = FindAction_1.findTypesToFormattedType[step.find.findType];
69
- formatted[stepName].text = this.text.toString();
70
- if (this.stepId()) {
71
- formatted[stepName].id = this.stepId();
72
- }
73
- return formatted;
19
+ return buildStepDescriptor(this.findAction, this.text);
74
20
  }
75
21
  static fromYaml(_stepName, stepArgs) {
76
- const step = new EnterTextStep('enter_text', [stepArgs.text], [FindAction_1.FindAction.findActionFromStepArgs(stepArgs)]);
22
+ const findAction = FindAction_1.FindAction.findActionFromStepArgs(stepArgs);
23
+ const textArg = stepArgs.text;
24
+ const text = textArg?.name
25
+ ? new MablSymbol_1.MablSymbol(textArg.name)
26
+ : (0, MablAction_1.parseArgument)(textArg);
27
+ const stepDescriptor = buildStepDescriptor(findAction, text);
28
+ const step = new EnterTextStep(stepDescriptor, findAction);
77
29
  step.setStepId(stepArgs.id);
78
30
  return step;
79
31
  }
32
+ static fromLegacyMablscript(args, actions) {
33
+ const findAction = ActionsUtils_1.ActionsUtils.validateSingleFindAction(actions);
34
+ const textArg = args[0];
35
+ const text = textArg?.name
36
+ ? new MablSymbol_1.MablSymbol(textArg.name)
37
+ : (0, MablAction_1.parseArgument)(textArg);
38
+ const stepDescriptor = buildStepDescriptor(findAction, text);
39
+ return new EnterTextStep(stepDescriptor, findAction);
40
+ }
80
41
  toMablscript() {
81
42
  const enterText = typeof this.text === 'string'
82
43
  ? `"${(0, domUtil_1.escapeMablscriptString)(this.text)}"`
@@ -89,7 +50,33 @@ class EnterTextStep extends MablStepWithFindAction_1.MablStepWithFindAction {
89
50
  ...MablAction_1.MablAction.findUniqueVariableReferencesInValue(this.text),
90
51
  ]);
91
52
  }
53
+ stepDescription() {
54
+ const displayText = typeof this.text === 'string'
55
+ ? `"${this.text}"`
56
+ : `{{${this.text.name}}}`;
57
+ const elementDescription = this.humanizeFind();
58
+ return `Enter ${displayText} into ${elementDescription}`;
59
+ }
92
60
  }
93
61
  exports.EnterTextStep = EnterTextStep;
94
- EnterTextStep.mablScriptStepNames = ['enter_text'];
95
- EnterTextStep.yamlMablScriptNames = ['EnterText'];
62
+ EnterTextStep.stepName = 'EnterText';
63
+ EnterTextStep.actionCode = 'enter_text';
64
+ EnterTextStep.mablScriptStepNames = [EnterTextStep.actionCode];
65
+ EnterTextStep.yamlMablScriptNames = [EnterTextStep.stepName];
66
+ function buildStepDescriptor(findAction, text) {
67
+ const find = findAction.toDescriptor();
68
+ switch (find.findType) {
69
+ case domUtil_1.FindType.FIND_FIRST:
70
+ case domUtil_1.FindType.FIND_LAST:
71
+ case domUtil_1.FindType.FIND_ANY:
72
+ case domUtil_1.FindType.FIND_ONE:
73
+ return {
74
+ find,
75
+ descriptorToActionMap: new Map().set(find, findAction),
76
+ text,
77
+ actionCode: EnterTextStep.actionCode,
78
+ };
79
+ default:
80
+ throw new Error(`Error generating step descriptor for ${EnterTextStep.stepName}: Unexpected find type ${find.findType}`);
81
+ }
82
+ }