@fluxenginejp/sftest 0.0.0-stage → 1.0.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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/dist/auth/auth.setup.d.ts +1 -0
  3. package/dist/auth/auth.setup.js +22 -0
  4. package/dist/auth/auth.teardown.d.ts +1 -0
  5. package/dist/auth/auth.teardown.js +17 -0
  6. package/dist/cli/sftest.d.ts +2 -0
  7. package/dist/cli/sftest.js +190 -0
  8. package/dist/index.d.ts +12 -0
  9. package/dist/index.js +33 -0
  10. package/dist/pages/common/BrowserDialogs.d.ts +77 -0
  11. package/dist/pages/common/BrowserDialogs.js +114 -0
  12. package/dist/pages/common/DataImportWizard.d.ts +101 -0
  13. package/dist/pages/common/DataImportWizard.js +275 -0
  14. package/dist/pages/common/ListViewPage.d.ts +96 -0
  15. package/dist/pages/common/ListViewPage.js +205 -0
  16. package/dist/pages/common/LoginAsPage.d.ts +57 -0
  17. package/dist/pages/common/LoginAsPage.js +97 -0
  18. package/dist/pages/common/PageButtons.d.ts +86 -0
  19. package/dist/pages/common/PageButtons.js +160 -0
  20. package/dist/pages/common/RecordData.d.ts +22 -0
  21. package/dist/pages/common/RecordData.js +52 -0
  22. package/dist/pages/common/RecordDetailPage.d.ts +80 -0
  23. package/dist/pages/common/RecordDetailPage.js +149 -0
  24. package/dist/pages/common/RecordFields.d.ts +79 -0
  25. package/dist/pages/common/RecordFields.js +159 -0
  26. package/dist/pages/common/RecordFormDialog.d.ts +75 -0
  27. package/dist/pages/common/RecordFormDialog.js +137 -0
  28. package/dist/pages/common/RecordPage.d.ts +220 -0
  29. package/dist/pages/common/RecordPage.js +342 -0
  30. package/dist/pages/common/ScreenDialog.d.ts +48 -0
  31. package/dist/pages/common/ScreenDialog.js +65 -0
  32. package/dist/pages/common/saveErrors.d.ts +132 -0
  33. package/dist/pages/common/saveErrors.js +136 -0
  34. package/dist/pages/common/scrollCapture.d.ts +58 -0
  35. package/dist/pages/common/scrollCapture.js +94 -0
  36. package/dist/pages/index.d.ts +16 -0
  37. package/dist/pages/index.js +18 -0
  38. package/dist/steps/common/apex.steps.d.ts +1 -0
  39. package/dist/steps/common/apex.steps.js +66 -0
  40. package/dist/steps/common/button.steps.d.ts +1 -0
  41. package/dist/steps/common/button.steps.js +27 -0
  42. package/dist/steps/common/common.steps.d.ts +1 -0
  43. package/dist/steps/common/common.steps.js +191 -0
  44. package/dist/steps/common/dialog.steps.d.ts +1 -0
  45. package/dist/steps/common/dialog.steps.js +35 -0
  46. package/dist/steps/common/import.steps.d.ts +1 -0
  47. package/dist/steps/common/import.steps.js +71 -0
  48. package/dist/steps/common/record.steps.d.ts +1 -0
  49. package/dist/steps/common/record.steps.js +126 -0
  50. package/dist/support/apexBatch.d.ts +46 -0
  51. package/dist/support/apexBatch.js +226 -0
  52. package/dist/support/createdRecords.d.ts +37 -0
  53. package/dist/support/createdRecords.js +58 -0
  54. package/dist/support/evidenceId.d.ts +61 -0
  55. package/dist/support/evidenceId.js +76 -0
  56. package/dist/support/fixtures.d.ts +169 -0
  57. package/dist/support/fixtures.js +186 -0
  58. package/dist/support/playwrightConfig.d.ts +40 -0
  59. package/dist/support/playwrightConfig.js +114 -0
  60. package/dist/support/settings.d.ts +23 -0
  61. package/dist/support/settings.js +118 -0
  62. package/dist/support/sf.d.ts +53 -0
  63. package/dist/support/sf.js +106 -0
  64. package/dist/support/sobjects.d.ts +33 -0
  65. package/dist/support/sobjects.js +69 -0
  66. package/docs/CHANGELOG.md +91 -0
  67. package/docs/SPEC.html +2556 -0
  68. package/features/standard-readonly.feature +10 -0
  69. package/package.json +78 -4
  70. package/readme.md +90 -0
  71. package/scripts/backup-account.bat +43 -0
  72. package/sftest.config.jsonc +36 -0
  73. package/templates/env +8 -0
  74. package/templates/gitignore +7 -0
  75. package/templates/pages/customPages.ts +15 -0
  76. package/templates/playwright.config.ts +17 -0
  77. package/README.md +0 -3
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apexBatchCode = apexBatchCode;
4
+ exports.startApexBatch = startApexBatch;
5
+ exports.waitApexBatch = waitApexBatch;
6
+ /**
7
+ * Apex バッチの起動と完了待ちを扱う。
8
+ *
9
+ * 組織にあるバッチクラスを匿名 Apex(Database.executeBatch)で起動し、完了するまで AsyncApexJob を確認して待つ。
10
+ * 匿名 Apex はその場で1回実行されるだけで、組織にクラスやコードは残らない。
11
+ * 実行するには「Apex 開発」の権限が必要となる(Salesforce CLI でログインしているユーザで実行する)。
12
+ *
13
+ * @author Fluxengine.co.jp
14
+ */
15
+ const node_child_process_1 = require("node:child_process");
16
+ const node_fs_1 = require("node:fs");
17
+ const node_os_1 = require("node:os");
18
+ const node_path_1 = require("node:path");
19
+ const promises_1 = require("node:timers/promises");
20
+ const settings_1 = require("./settings");
21
+ const sf_1 = require("./sf");
22
+ /** 状態を確認する間隔(ミリ秒)。完了を待つ時間の上限は sftest.config.jsonc の apexBatch。 */
23
+ const POLL_INTERVAL_MS = 5_000;
24
+ /** ジョブ ID をデバッグログから取り出すための目印。 */
25
+ const JOB_ID_MARK = 'SFTEST_APEX_JOB_ID:';
26
+ /**
27
+ * 匿名 Apex を実行し、sf apex run の結果(result)を返す。
28
+ *
29
+ * sf apex run にはファイルで渡す(コマンドラインで渡すと引用符のエスケープが必要になるため)。
30
+ * 一時ファイルは実行後に削除する。
31
+ *
32
+ * @param code - 実行する匿名 Apex のコード。
33
+ * @returns sf apex run の結果(result)。logs にデバッグログを含む。
34
+ * @throws コンパイルエラー、または実行時エラーになった場合。
35
+ */
36
+ function runAnonymousApex(code) {
37
+ const dir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'sftest-apex-'));
38
+ const file = (0, node_path_1.join)(dir, 'run.apex');
39
+ (0, node_fs_1.writeFileSync)(file, code); // BOM を付けない(先頭に BOM があるとコンパイルエラーになる)。
40
+ let out;
41
+ try {
42
+ out = (0, node_child_process_1.execSync)(`sf apex run --file "${file}" --target-org ${(0, sf_1.orgAlias)()} --json`, { encoding: 'utf-8', env: (0, sf_1.sfEnv)() });
43
+ }
44
+ catch (e) {
45
+ // コンパイルエラーなどでは終了コードが 0 以外になるが、標準出力に JSON で内容が出るため、それを読んで理由を報告する。
46
+ out = e.stdout ?? '';
47
+ if (!out.includes('{'))
48
+ throw e;
49
+ }
50
+ finally {
51
+ (0, node_fs_1.rmSync)(dir, { recursive: true, force: true });
52
+ }
53
+ const json = JSON.parse(out.slice(out.indexOf('{'), out.lastIndexOf('}') + 1));
54
+ const result = json.result ?? json.data ?? {};
55
+ if (!result.compiled)
56
+ throw new Error(`匿名 Apex のコンパイルに失敗しました: ${result.compileProblem || json.message}`);
57
+ if (!result.success)
58
+ throw new Error(`匿名 Apex の実行に失敗しました: ${result.exceptionMessage}\n${result.exceptionStackTrace}`);
59
+ return result;
60
+ }
61
+ /**
62
+ * バッチクラスを起動する匿名 Apex のコードを作る。作ったコードはレポートに添付する。
63
+ *
64
+ * クラス名(名前空間付きも可)以外の文字列が Apex のコードとして実行されないよう、クラス名の形式を確認する。
65
+ *
66
+ * @param className - バッチクラスの名前(名前空間付きは 名前空間.クラス名)。
67
+ * @param args - コンストラクタの引数。省略時は引数なし。
68
+ * @param scopeSize - スコープ(1回の execute で処理する件数)。省略時は Salesforce の既定(200 件)。
69
+ * @returns 匿名 Apex のコード。
70
+ * @throws クラス名の形式が正しくない場合、引数の型・値が正しくない場合。
71
+ */
72
+ function apexBatchCode(className, args = [], scopeSize) {
73
+ if (!/^[A-Za-z]\w*(\.[A-Za-z]\w*)?$/.test(className))
74
+ throw new Error(`Apex バッチのクラス名が正しくありません: "${className}"`);
75
+ const params = args.map((a, i) => toApexValue(a, i + 1)).join(', ');
76
+ const scope = scopeSize === undefined ? '' : `, ${scopeSize}`;
77
+ return `System.debug('${JOB_ID_MARK}' + Database.executeBatch(new ${className}(${params})${scope}));`;
78
+ }
79
+ /**
80
+ * バッチクラスを起動し、ジョブ ID を返す。
81
+ *
82
+ * @param className - バッチクラスの名前(エラーメッセージに使う)。
83
+ * @param code - apexBatchCode で作った匿名 Apex のコード。
84
+ * @returns 起動したジョブの ID。
85
+ * @throws 匿名 Apex が失敗した場合、またはデバッグログからジョブ ID を取得できない場合。
86
+ */
87
+ function startApexBatch(className, code) {
88
+ const result = runAnonymousApex(code);
89
+ const jobId = String(result.logs ?? '').match(new RegExp(`\\|USER_DEBUG\\|.*${JOB_ID_MARK}(\\w{15,18})`))?.[1];
90
+ if (!jobId)
91
+ throw new Error(`Apex バッチ ${className} は起動しましたが、ジョブ ID を取得できませんでした`);
92
+ return jobId;
93
+ }
94
+ /**
95
+ * 型と値(シナリオに書いた文字列)を Apex の式にする。
96
+ *
97
+ * 値が null なら null とする。List<型>・Set<型> はカンマ区切りの値を要素にする。「式」は値をそのまま Apex の式として使う。
98
+ *
99
+ * @param type - シナリオの表に書いた型の名前(String、List<String>、式 など)。
100
+ * @param value - シナリオの表に書いた値。
101
+ * @param position - 引数の位置(1から)。エラーメッセージに使う。
102
+ * @returns Apex の式。
103
+ * @throws 型に対応していない場合、または値が型に合わない場合。
104
+ */
105
+ function toApexValue({ type, value }, position) {
106
+ const t = type.trim();
107
+ if (t === '式')
108
+ return value;
109
+ if (value.trim() === 'null')
110
+ return 'null';
111
+ const collection = t.match(/^(List|Set)\s*<\s*(\w+)\s*>$/i);
112
+ if (collection) {
113
+ const kind = collection[1].toLowerCase() === 'list' ? 'List' : 'Set';
114
+ const elementType = scalarType(collection[2], position);
115
+ const items = value.trim() === '' ? [] : value.split(',').map((v) => toScalar(elementType, v.trim(), position));
116
+ return `new ${kind}<${elementType}>{${items.join(', ')}}`;
117
+ }
118
+ return toScalar(scalarType(t, position), value, position);
119
+ }
120
+ /** 引数に使える型(List・Set の要素の型も同じ)。 */
121
+ const SCALAR_TYPES = ['String', 'Integer', 'Long', 'Decimal', 'Double', 'Boolean', 'Date', 'Datetime', 'Id'];
122
+ /**
123
+ * 型の名前を、大文字・小文字を区別せずに対応する型の正式な名前にする。
124
+ *
125
+ * @param type - シナリオに書いた型の名前。
126
+ * @param position - 引数の位置(1から)。エラーメッセージに使う。
127
+ * @returns 型の正式な名前(例: string → String)。
128
+ * @throws 対応していない型の場合。
129
+ */
130
+ function scalarType(type, position) {
131
+ const found = SCALAR_TYPES.find((s) => s.toLowerCase() === type.toLowerCase());
132
+ if (!found) {
133
+ throw new Error(`${position} 番目の引数の型 "${type}" には対応していません(${SCALAR_TYPES.join(' / ')}、List<型>、Set<型>、式 のいずれか)`);
134
+ }
135
+ return found;
136
+ }
137
+ /**
138
+ * 値の書式を型ごとに確認し、Apex の式にする。
139
+ *
140
+ * String は前後の空白を含めてそのまま使い、\・'・改行をエスケープする。それ以外の型は前後の空白を取り除いてから確認する。
141
+ * Datetime は、実行するユーザ(CLI でログインしているユーザ)のタイムゾーンの日時になる。
142
+ *
143
+ * @param type - 型の正式な名前(SCALAR_TYPES のいずれか)。
144
+ * @param value - シナリオに書いた値。
145
+ * @param position - 引数の位置(1から)。エラーメッセージに使う。
146
+ * @returns Apex の式。
147
+ * @throws 値が型の書式に合わない場合。
148
+ */
149
+ function toScalar(type, value, position) {
150
+ /** 値が型の書式に合わないことを示す例外を作る。 */
151
+ const bad = () => new Error(`${position} 番目の引数の値 "${value}" は ${type} として正しくありません`);
152
+ const v = type === 'String' ? value : value.trim();
153
+ switch (type) {
154
+ case 'String':
155
+ return `'${v.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\r?\n/g, '\\n')}'`;
156
+ case 'Integer':
157
+ if (!/^-?\d+$/.test(v))
158
+ throw bad();
159
+ return v;
160
+ case 'Long':
161
+ if (!/^-?\d+$/.test(v))
162
+ throw bad();
163
+ return `${v}L`;
164
+ case 'Decimal':
165
+ if (!/^-?\d+(\.\d+)?$/.test(v))
166
+ throw bad();
167
+ return v.includes('.') ? v : `${v}.0`;
168
+ case 'Double':
169
+ if (!/^-?\d+(\.\d+)?$/.test(v))
170
+ throw bad();
171
+ return `Double.valueOf('${v}')`;
172
+ case 'Boolean':
173
+ if (!/^(true|false)$/i.test(v))
174
+ throw bad();
175
+ return v.toLowerCase();
176
+ case 'Date': {
177
+ const m = v.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/);
178
+ if (!m)
179
+ throw bad();
180
+ return `Date.newInstance(${+m[1]}, ${+m[2]}, ${+m[3]})`;
181
+ }
182
+ case 'Datetime': {
183
+ const m = v.match(/^(\d{4})-(\d{1,2})-(\d{1,2})[ T](\d{1,2}):(\d{2})(?::(\d{2}))?$/);
184
+ if (!m)
185
+ throw bad();
186
+ return `Datetime.newInstance(${+m[1]}, ${+m[2]}, ${+m[3]}, ${+m[4]}, ${+m[5]}, ${+(m[6] ?? 0)})`;
187
+ }
188
+ case 'Id':
189
+ if (!/^[A-Za-z0-9]{15}([A-Za-z0-9]{3})?$/.test(v))
190
+ throw bad();
191
+ return `Id.valueOf('${v}')`;
192
+ }
193
+ throw bad();
194
+ }
195
+ /**
196
+ * ジョブが終わる(完了・失敗・中止)まで待ち、結果を返す。
197
+ *
198
+ * AsyncApexJob を POLL_INTERVAL_MS(5秒)ごとに SOQL で確認する。
199
+ *
200
+ * @param jobId - 起動したジョブの ID。
201
+ * @param timeoutMs - 待つ時間の上限(ミリ秒)。省略時は sftest.config.jsonc の apexBatch。
202
+ * @returns ジョブが Completed・Failed・Aborted のいずれかになった時点で、その結果を返す。
203
+ * @throws ジョブが見つからない場合、または上限までに終わらない場合。
204
+ */
205
+ async function waitApexBatch(jobId, timeoutMs = (0, settings_1.timeoutMs)('apexBatch')) {
206
+ const deadline = Date.now() + timeoutMs;
207
+ for (;;) {
208
+ const [job] = (0, sf_1.sfQuery)(`SELECT Status, TotalJobItems, JobItemsProcessed, NumberOfErrors, ExtendedStatus FROM AsyncApexJob WHERE Id = '${jobId}'`);
209
+ if (!job)
210
+ throw new Error(`Apex バッチのジョブ ${jobId} が見つかりません`);
211
+ const result = {
212
+ jobId,
213
+ status: job.Status,
214
+ totalJobItems: job.TotalJobItems ?? 0,
215
+ jobItemsProcessed: job.JobItemsProcessed ?? 0,
216
+ numberOfErrors: job.NumberOfErrors ?? 0,
217
+ extendedStatus: job.ExtendedStatus ?? '',
218
+ };
219
+ if (['Completed', 'Failed', 'Aborted'].includes(result.status))
220
+ return result;
221
+ if (Date.now() >= deadline) {
222
+ throw new Error(`Apex バッチのジョブ ${jobId} が ${timeoutMs / 1000} 秒以内に終わりませんでした(状態: ${result.status})`);
223
+ }
224
+ await (0, promises_1.setTimeout)(POLL_INTERVAL_MS);
225
+ }
226
+ }
@@ -0,0 +1,37 @@
1
+ /** シナリオ全体の片付けを指示するタグ。 */
2
+ export declare const CLEANUP_TAG = "@\u7247\u4ED8\u3051";
3
+ /** 作成したレコード。sobject はオブジェクトの API 名、id はレコード ID である。 */
4
+ export type CreatedRecord = {
5
+ sobject: string;
6
+ id: string;
7
+ };
8
+ /** 1件の削除結果。削除に失敗した場合は error に理由を持つ。 */
9
+ export type DeleteResult = CreatedRecord & {
10
+ error?: string;
11
+ };
12
+ /**
13
+ * シナリオで作成したレコードを記録し、シナリオ終了時に削除する。
14
+ *
15
+ * シナリオごとに生成し、記録は別のシナリオへ引き継がない。
16
+ */
17
+ export declare class CreatedRecords {
18
+ /** 記録したレコード(作成した順)。 */
19
+ private records;
20
+ /**
21
+ * 作成したレコードを記録する。同じ ID がすでに記録されている場合は何もしない。
22
+ *
23
+ * @param sobject - オブジェクトの API 名。
24
+ * @param id - レコード ID。
25
+ */
26
+ add(sobject: string, id: string): void;
27
+ /**
28
+ * 記録したレコードを、後に作成したものから順に削除する。
29
+ *
30
+ * 取引先責任者 → 取引先 のように、子レコードを先に削除するためである。
31
+ * 削除は Salesforce CLI のユーザ(システム管理者)で行うため、代理ログイン中でも削除できる。
32
+ * 1件の削除に失敗しても残りの削除を続け、結果をまとめて返す。終了後、記録は空になる。
33
+ *
34
+ * @returns 記録した各レコードの削除結果。失敗したレコードは error に理由を持つ。
35
+ */
36
+ deleteAll(): DeleteResult[];
37
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreatedRecords = exports.CLEANUP_TAG = void 0;
4
+ /**
5
+ * シナリオ内で作成したレコードの記録と片付け(@片付け)を扱う。
6
+ *
7
+ * 記録は、作成後の詳細画面の URL などから取得したレコード ID で行う(RecordPage・DataImportWizard)。
8
+ * 片付けは、@片付け タグを付けたシナリオだけ、シナリオ終了時(失敗した場合も)に行う(support/fixtures.ts)。
9
+ *
10
+ * @author Fluxengine.co.jp
11
+ */
12
+ const sf_1 = require("./sf");
13
+ /** シナリオ全体の片付けを指示するタグ。 */
14
+ exports.CLEANUP_TAG = '@片付け';
15
+ /**
16
+ * シナリオで作成したレコードを記録し、シナリオ終了時に削除する。
17
+ *
18
+ * シナリオごとに生成し、記録は別のシナリオへ引き継がない。
19
+ */
20
+ class CreatedRecords {
21
+ /** 記録したレコード(作成した順)。 */
22
+ records = [];
23
+ /**
24
+ * 作成したレコードを記録する。同じ ID がすでに記録されている場合は何もしない。
25
+ *
26
+ * @param sobject - オブジェクトの API 名。
27
+ * @param id - レコード ID。
28
+ */
29
+ add(sobject, id) {
30
+ if (!this.records.some((r) => r.id === id))
31
+ this.records.push({ sobject, id });
32
+ }
33
+ /**
34
+ * 記録したレコードを、後に作成したものから順に削除する。
35
+ *
36
+ * 取引先責任者 → 取引先 のように、子レコードを先に削除するためである。
37
+ * 削除は Salesforce CLI のユーザ(システム管理者)で行うため、代理ログイン中でも削除できる。
38
+ * 1件の削除に失敗しても残りの削除を続け、結果をまとめて返す。終了後、記録は空になる。
39
+ *
40
+ * @returns 記録した各レコードの削除結果。失敗したレコードは error に理由を持つ。
41
+ */
42
+ deleteAll() {
43
+ const results = [];
44
+ for (const record of [...this.records].reverse()) {
45
+ try {
46
+ (0, sf_1.sfJson)(`data delete record --sobject ${record.sobject} --record-id ${record.id}`);
47
+ results.push(record);
48
+ }
49
+ catch (e) {
50
+ // 複数件の結果をまとめて報告するため、1件の失敗で止めずに理由を記録して続ける。
51
+ results.push({ ...record, error: String(e.message ?? e).split('\n')[0] });
52
+ }
53
+ }
54
+ this.records = [];
55
+ return results;
56
+ }
57
+ }
58
+ exports.CreatedRecords = CreatedRecords;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * エビデンス名の先頭に付けるテスト仕様書の ID と、エビデンスのファイルの保存先を扱う。
3
+ *
4
+ * @author Fluxengine.co.jp
5
+ */
6
+ import { TestInfo } from '@playwright/test';
7
+ /**
8
+ * 画面キャプチャーなどのエビデンス名に付けるテスト仕様書の ID を管理する。
9
+ *
10
+ * シナリオごとに生成し、前のシナリオの ID は引き継がない。
11
+ * 「ID "…"」のステップで設定した ID は、次の「ID」のステップで置き換えるまで保持する。
12
+ */
13
+ export declare class EvidenceId {
14
+ /** 設定中の ID。未設定の場合は undefined である。 */
15
+ private current?;
16
+ /**
17
+ * エビデンス名に付ける ID を設定する。
18
+ *
19
+ * ID の形式(桁数などはテスト仕様書による)は検証せず、前後の空白を取り除いて保持する。
20
+ * 空文字列の場合は設定を解除する。
21
+ *
22
+ * @param id - テスト仕様書の ID。
23
+ */
24
+ set(id: string): void;
25
+ /**
26
+ * 現在設定されている ID を取得する。
27
+ *
28
+ * @returns 設定中の ID。未設定の場合は undefined。
29
+ */
30
+ get value(): string | undefined;
31
+ /**
32
+ * エビデンス名の先頭に、設定中の ID を付ける。
33
+ *
34
+ * @param label - ID を付ける前のエビデンス名。
35
+ * @returns ID がある場合は「ID_名前」、ない場合は label の値。
36
+ */
37
+ prefix(label: string): string;
38
+ }
39
+ /**
40
+ * 文字列をファイル名・フォルダ名に使える形にする。
41
+ *
42
+ * Windows のファイル名に使えない文字と、バッチファイルで特別な意味を持つ文字(% & ^ !)を "_" に置き換える。
43
+ * 末尾のピリオド・空白を取り除き、最大の長さで切り詰める。
44
+ *
45
+ * @param name - 変換する名前。
46
+ * @param maxLength - 最大の文字数。省略時は 80。
47
+ * @returns 変換後の名前。空になった場合は "_"。
48
+ */
49
+ export declare function safeFileName(name: string, maxLength?: number): string;
50
+ /**
51
+ * シナリオのエビデンスを保存するフォルダの絶対パスを返す。
52
+ *
53
+ * パスは results/evidence/<実行日時>/<機能ファイル名>/<シナリオ名> である。
54
+ * 実行日時は playwright.config.ts が実行ごとに決め、環境変数 SFTEST_RUN_ID で渡す。
55
+ * フォルダは作成しない。
56
+ *
57
+ * @param testInfo - 対象のシナリオのテスト情報。
58
+ * @returns エビデンスのフォルダの絶対パス。
59
+ * @throws SFTEST_RUN_ID が設定されていない場合。
60
+ */
61
+ export declare function evidenceDirOf(testInfo: TestInfo): string;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EvidenceId = void 0;
4
+ exports.safeFileName = safeFileName;
5
+ exports.evidenceDirOf = evidenceDirOf;
6
+ const node_path_1 = require("node:path");
7
+ /**
8
+ * 画面キャプチャーなどのエビデンス名に付けるテスト仕様書の ID を管理する。
9
+ *
10
+ * シナリオごとに生成し、前のシナリオの ID は引き継がない。
11
+ * 「ID "…"」のステップで設定した ID は、次の「ID」のステップで置き換えるまで保持する。
12
+ */
13
+ class EvidenceId {
14
+ /** 設定中の ID。未設定の場合は undefined である。 */
15
+ current;
16
+ /**
17
+ * エビデンス名に付ける ID を設定する。
18
+ *
19
+ * ID の形式(桁数などはテスト仕様書による)は検証せず、前後の空白を取り除いて保持する。
20
+ * 空文字列の場合は設定を解除する。
21
+ *
22
+ * @param id - テスト仕様書の ID。
23
+ */
24
+ set(id) {
25
+ this.current = id.trim() || undefined;
26
+ }
27
+ /**
28
+ * 現在設定されている ID を取得する。
29
+ *
30
+ * @returns 設定中の ID。未設定の場合は undefined。
31
+ */
32
+ get value() {
33
+ return this.current;
34
+ }
35
+ /**
36
+ * エビデンス名の先頭に、設定中の ID を付ける。
37
+ *
38
+ * @param label - ID を付ける前のエビデンス名。
39
+ * @returns ID がある場合は「ID_名前」、ない場合は label の値。
40
+ */
41
+ prefix(label) {
42
+ return this.current ? `${this.current}_${label}` : label;
43
+ }
44
+ }
45
+ exports.EvidenceId = EvidenceId;
46
+ /**
47
+ * 文字列をファイル名・フォルダ名に使える形にする。
48
+ *
49
+ * Windows のファイル名に使えない文字と、バッチファイルで特別な意味を持つ文字(% & ^ !)を "_" に置き換える。
50
+ * 末尾のピリオド・空白を取り除き、最大の長さで切り詰める。
51
+ *
52
+ * @param name - 変換する名前。
53
+ * @param maxLength - 最大の文字数。省略時は 80。
54
+ * @returns 変換後の名前。空になった場合は "_"。
55
+ */
56
+ function safeFileName(name, maxLength = 80) {
57
+ return name.replace(/[\\/:*?"<>|%&^!\x00-\x1f]/g, '_').replace(/[. ]+$/, '').slice(0, maxLength) || '_';
58
+ }
59
+ /**
60
+ * シナリオのエビデンスを保存するフォルダの絶対パスを返す。
61
+ *
62
+ * パスは results/evidence/<実行日時>/<機能ファイル名>/<シナリオ名> である。
63
+ * 実行日時は playwright.config.ts が実行ごとに決め、環境変数 SFTEST_RUN_ID で渡す。
64
+ * フォルダは作成しない。
65
+ *
66
+ * @param testInfo - 対象のシナリオのテスト情報。
67
+ * @returns エビデンスのフォルダの絶対パス。
68
+ * @throws SFTEST_RUN_ID が設定されていない場合。
69
+ */
70
+ function evidenceDirOf(testInfo) {
71
+ const feature = (0, node_path_1.basename)(testInfo.file).replace(/\.feature\.spec\.js$/, '');
72
+ const runId = process.env.SFTEST_RUN_ID;
73
+ if (!runId)
74
+ throw new Error('SFTEST_RUN_ID が設定されていません(playwright.config.ts で設定するため、通常は起きない)');
75
+ return (0, node_path_1.resolve)('results', 'evidence', runId, safeFileName(feature), safeFileName(testInfo.title));
76
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * フィクスチャ(ステップから使う部品)を登録し、ステップ定義で使う Given・When・Then・BeforeStep を提供する。
3
+ *
4
+ * pages/ のページクラスと support/ の共通処理を、シナリオごとに組み立てる。
5
+ * pages/common/ : どのオブジェクトでも使う画面操作・共通処理(レコード画面は RecordPage)
6
+ * 標準と異なる画面のページクラス : 利用者が RecordPage を継承して作成し、設定(sfTestConfig の customPages)で渡す
7
+ * シナリオ終了時の片付け・未処理の保存エラーとブラウザ標準のダイアログの判定、各ステップ前の確認もここで行う。
8
+ *
9
+ * @author Fluxengine.co.jp
10
+ */
11
+ import { DataTable } from 'playwright-bdd';
12
+ import { BrowserDialogs } from '../pages/common/BrowserDialogs';
13
+ import { DataImportWizard } from '../pages/common/DataImportWizard';
14
+ import { ListViewPage } from '../pages/common/ListViewPage';
15
+ import { LoginAsPage } from '../pages/common/LoginAsPage';
16
+ import { PageButtons } from '../pages/common/PageButtons';
17
+ import { RecordData } from '../pages/common/RecordData';
18
+ import { RecordDetailPage } from '../pages/common/RecordDetailPage';
19
+ import { RecordFormDialog } from '../pages/common/RecordFormDialog';
20
+ import { RecordPageClass, RecordPages } from '../pages/common/RecordPage';
21
+ import { FieldValue } from '../pages/common/RecordFields';
22
+ import { SaveErrors } from '../pages/common/saveErrors';
23
+ import { ScreenDialog } from '../pages/common/ScreenDialog';
24
+ import { Evidence } from '../pages/common/scrollCapture';
25
+ import { CreatedRecords } from './createdRecords';
26
+ import { EvidenceId } from './evidenceId';
27
+ /** 設定(playwright.config.ts の use)で指定する sfTest のオプション。 */
28
+ export interface SfTestOptions {
29
+ /** 標準と異なる画面のページクラス(キーはオブジェクトの表示ラベルまたは API 名)。sfTestConfig の customPages から設定される。 */
30
+ customPages: Record<string, RecordPageClass>;
31
+ }
32
+ /**
33
+ * sfTest のフィクスチャを追加した test。
34
+ *
35
+ * フィクスチャはシナリオごとに作成され、同じシナリオの中では共有される。
36
+ */
37
+ export declare const test: import("playwright/test").TestType<import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & import("playwright-bdd").BddTestFixtures & SfTestOptions & {
38
+ evidenceId: EvidenceId;
39
+ evidenceDir: string;
40
+ createdRecords: CreatedRecords;
41
+ saveErrors: SaveErrors;
42
+ browserDialogs: BrowserDialogs;
43
+ screenDialog: ScreenDialog;
44
+ pageButtons: PageButtons;
45
+ dataImportWizard: DataImportWizard;
46
+ recordData: RecordData;
47
+ recordPages: RecordPages;
48
+ listViewPage: ListViewPage;
49
+ loginAsPage: LoginAsPage;
50
+ recordDetailPage: RecordDetailPage;
51
+ recordFormDialog: RecordFormDialog;
52
+ evidence: Evidence;
53
+ inAppGuidance: void;
54
+ }, import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & import("playwright-bdd").BddWorkerFixtures>;
55
+ /** sfTest のフィクスチャを使うステップ定義・フックの登録関数。 */
56
+ export declare const Given: import("playwright-bdd").PlaywrightStyleStepCtor<import("playwright-bdd").PlaywrightStyleStepFn<import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & import("playwright-bdd").BddTestFixtures & SfTestOptions & {
57
+ evidenceId: EvidenceId;
58
+ evidenceDir: string;
59
+ createdRecords: CreatedRecords;
60
+ saveErrors: SaveErrors;
61
+ browserDialogs: BrowserDialogs;
62
+ screenDialog: ScreenDialog;
63
+ pageButtons: PageButtons;
64
+ dataImportWizard: DataImportWizard;
65
+ recordData: RecordData;
66
+ recordPages: RecordPages;
67
+ listViewPage: ListViewPage;
68
+ loginAsPage: LoginAsPage;
69
+ recordDetailPage: RecordDetailPage;
70
+ recordFormDialog: RecordFormDialog;
71
+ evidence: Evidence;
72
+ inAppGuidance: void;
73
+ }, import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & import("playwright-bdd").BddWorkerFixtures>>, When: import("playwright-bdd").PlaywrightStyleStepCtor<import("playwright-bdd").PlaywrightStyleStepFn<import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & import("playwright-bdd").BddTestFixtures & SfTestOptions & {
74
+ evidenceId: EvidenceId;
75
+ evidenceDir: string;
76
+ createdRecords: CreatedRecords;
77
+ saveErrors: SaveErrors;
78
+ browserDialogs: BrowserDialogs;
79
+ screenDialog: ScreenDialog;
80
+ pageButtons: PageButtons;
81
+ dataImportWizard: DataImportWizard;
82
+ recordData: RecordData;
83
+ recordPages: RecordPages;
84
+ listViewPage: ListViewPage;
85
+ loginAsPage: LoginAsPage;
86
+ recordDetailPage: RecordDetailPage;
87
+ recordFormDialog: RecordFormDialog;
88
+ evidence: Evidence;
89
+ inAppGuidance: void;
90
+ }, import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & import("playwright-bdd").BddWorkerFixtures>>, Then: import("playwright-bdd").PlaywrightStyleStepCtor<import("playwright-bdd").PlaywrightStyleStepFn<import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & import("playwright-bdd").BddTestFixtures & SfTestOptions & {
91
+ evidenceId: EvidenceId;
92
+ evidenceDir: string;
93
+ createdRecords: CreatedRecords;
94
+ saveErrors: SaveErrors;
95
+ browserDialogs: BrowserDialogs;
96
+ screenDialog: ScreenDialog;
97
+ pageButtons: PageButtons;
98
+ dataImportWizard: DataImportWizard;
99
+ recordData: RecordData;
100
+ recordPages: RecordPages;
101
+ listViewPage: ListViewPage;
102
+ loginAsPage: LoginAsPage;
103
+ recordDetailPage: RecordDetailPage;
104
+ recordFormDialog: RecordFormDialog;
105
+ evidence: Evidence;
106
+ inAppGuidance: void;
107
+ }, import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & import("playwright-bdd").BddWorkerFixtures>>, BeforeStep: (...args: [(this: null, fixtures: import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & import("playwright-bdd").BddTestFixtures & SfTestOptions & {
108
+ evidenceId: EvidenceId;
109
+ evidenceDir: string;
110
+ createdRecords: CreatedRecords;
111
+ saveErrors: SaveErrors;
112
+ browserDialogs: BrowserDialogs;
113
+ screenDialog: ScreenDialog;
114
+ pageButtons: PageButtons;
115
+ dataImportWizard: DataImportWizard;
116
+ recordData: RecordData;
117
+ recordPages: RecordPages;
118
+ listViewPage: ListViewPage;
119
+ loginAsPage: LoginAsPage;
120
+ recordDetailPage: RecordDetailPage;
121
+ recordFormDialog: RecordFormDialog;
122
+ evidence: Evidence;
123
+ inAppGuidance: void;
124
+ } & import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & import("playwright-bdd").BddWorkerFixtures) => unknown] | [string, (this: null, fixtures: import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & import("playwright-bdd").BddTestFixtures & SfTestOptions & {
125
+ evidenceId: EvidenceId;
126
+ evidenceDir: string;
127
+ createdRecords: CreatedRecords;
128
+ saveErrors: SaveErrors;
129
+ browserDialogs: BrowserDialogs;
130
+ screenDialog: ScreenDialog;
131
+ pageButtons: PageButtons;
132
+ dataImportWizard: DataImportWizard;
133
+ recordData: RecordData;
134
+ recordPages: RecordPages;
135
+ listViewPage: ListViewPage;
136
+ loginAsPage: LoginAsPage;
137
+ recordDetailPage: RecordDetailPage;
138
+ recordFormDialog: RecordFormDialog;
139
+ evidence: Evidence;
140
+ inAppGuidance: void;
141
+ } & import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & import("playwright-bdd").BddWorkerFixtures) => unknown] | [{
142
+ name?: string;
143
+ tags?: string;
144
+ timeout?: number;
145
+ }, (this: null, fixtures: import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & import("playwright-bdd").BddTestFixtures & SfTestOptions & {
146
+ evidenceId: EvidenceId;
147
+ evidenceDir: string;
148
+ createdRecords: CreatedRecords;
149
+ saveErrors: SaveErrors;
150
+ browserDialogs: BrowserDialogs;
151
+ screenDialog: ScreenDialog;
152
+ pageButtons: PageButtons;
153
+ dataImportWizard: DataImportWizard;
154
+ recordData: RecordData;
155
+ recordPages: RecordPages;
156
+ listViewPage: ListViewPage;
157
+ loginAsPage: LoginAsPage;
158
+ recordDetailPage: RecordDetailPage;
159
+ recordFormDialog: RecordFormDialog;
160
+ evidence: Evidence;
161
+ inAppGuidance: void;
162
+ } & import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & import("playwright-bdd").BddWorkerFixtures) => unknown]) => void;
163
+ /**
164
+ * シナリオの表(| 項目 | 値 |)を、項目ラベルと値の組に変換する。
165
+ *
166
+ * @param table - 1行目が見出し(項目・値)の表。
167
+ * @returns 2行目以降の各行の項目ラベルと値。
168
+ */
169
+ export declare const fieldValues: (table: DataTable) => FieldValue[];