android-midscene-automation 1.1.9 → 1.1.10
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.
- package/CHANGELOG.md +58 -53
- package/README.md +57 -53
- package/package.json +1 -1
- package/server/appium-recorder/appium-runner.ts +14 -0
- package/server/appium-recorder/random-value-replay.test.ts +76 -0
- package/server/appium-recorder/random-value.test.ts +114 -0
- package/server/appium-recorder/random-value.ts +34 -0
- package/server/appium-recorder/repository.ts +4 -0
- package/server/appium-recorder/script-export.ts +6 -1
- package/src/appium-recorder/AppiumPage.vue +111 -5
- package/src/appium-recorder/action-descriptions.ts +1 -0
- package/src/appium-recorder/components/FlowStepEditor.vue +3 -1
- package/src/appium-recorder/components/NestedConditionBranches.vue +3 -0
- package/src/appium-recorder/components/PresetVariables.vue +6 -5
- package/src/appium-recorder/components/RandomValueSettings.vue +139 -0
- package/src/appium-recorder/components/RecordedSteps.vue +1 -0
- package/src/appium-recorder/flow-graph.ts +1 -0
- package/src/appium-recorder/flow-labels.ts +4 -1
- package/src/appium-recorder/random-value.ts +60 -0
- package/src/appium-recorder/types.ts +3 -0
- package/src/appium-recorder/variable-presets.ts +24 -0
- package/src/components/config/AiDeduplicationSettings.vue +21 -10
- package/src/pages/ConfigPage.vue +1 -1
|
@@ -12,6 +12,7 @@ import { validateLoopSteps } from '../../src/appium-recorder/bounded-loop';
|
|
|
12
12
|
import { validateVariables, validateExtraction, validateReturns, type TestVariable, type VariableExtraction, type ScriptReturn } from '../../src/appium-recorder/variables';
|
|
13
13
|
import { getPresetVariables, savePresetVariables, deleteScriptVariables } from './variable-store';
|
|
14
14
|
import { validateImageCheck, type ImageCheckConfig } from '../../src/appium-recorder/image-check';
|
|
15
|
+
import { validateRandomValue, type RandomValueConfig } from '../../src/appium-recorder/random-value';
|
|
15
16
|
|
|
16
17
|
export type AppiumRecordedStepRecord = {
|
|
17
18
|
mergeUndo?: import('../../src/appium-recorder/types').BranchMergeUndo;
|
|
@@ -53,6 +54,7 @@ export type AppiumRecordedStepRecord = {
|
|
|
53
54
|
| 'runScript'
|
|
54
55
|
| 'noop'
|
|
55
56
|
| 'extractVariable'
|
|
57
|
+
| 'randomValue'
|
|
56
58
|
| 'log'
|
|
57
59
|
| 'visualChange';
|
|
58
60
|
label: string;
|
|
@@ -97,6 +99,7 @@ export type AppiumRecordedStepRecord = {
|
|
|
97
99
|
logPrefix?: string;
|
|
98
100
|
imageCheck?: ImageCheckConfig;
|
|
99
101
|
extractVariable?: VariableExtraction;
|
|
102
|
+
randomValue?: RandomValueConfig;
|
|
100
103
|
parameters?: TestVariable[];
|
|
101
104
|
returns?: ScriptReturn[];
|
|
102
105
|
keyCode?: number;
|
|
@@ -389,6 +392,7 @@ export function saveAppiumRecordedScript(input: {
|
|
|
389
392
|
}
|
|
390
393
|
if (step.type === 'imageCheck') validateImageCheck(step.imageCheck);
|
|
391
394
|
if (step.type === 'extractVariable') validateExtraction(step.extractVariable);
|
|
395
|
+
if (step.type === 'randomValue') validateRandomValue(step.randomValue, { allowEmptySensitiveText: true });
|
|
392
396
|
if (step.type === 'runScript') { validateVariables(step.parameters); validateReturns(step.returns); }
|
|
393
397
|
}
|
|
394
398
|
validateLoopSteps(steps);
|
|
@@ -45,7 +45,12 @@ export async function createAppiumScriptExport(
|
|
|
45
45
|
appActivity: script.appActivity,
|
|
46
46
|
deviceId: script.deviceId,
|
|
47
47
|
variables: clearSecrets(script.variables),
|
|
48
|
-
steps: script.steps.map(step => ({ ...step, mergeUndo: undefined,
|
|
48
|
+
steps: script.steps.map(step => ({ ...step, mergeUndo: undefined,
|
|
49
|
+
...(step.parameters ? { parameters: clearSecrets(step.parameters) } : {}),
|
|
50
|
+
...(step.randomValue && (step.randomValue.sensitive || sensitiveVariableName(step.randomValue.name)
|
|
51
|
+
|| script.variables?.find(item => item.name === step.randomValue?.name)?.sensitive)
|
|
52
|
+
? { randomValue: { ...step.randomValue, text: '', sourceName: undefined, sensitive: true } } : {}),
|
|
53
|
+
})),
|
|
49
54
|
},
|
|
50
55
|
}), null, 2);
|
|
51
56
|
};
|
|
@@ -6,7 +6,7 @@ import { DEFAULT_NODE_TIMEOUT_MS } from './node-timeout';
|
|
|
6
6
|
import { aiPromptPresetsKey, DEFAULT_AI_PROMPT_PRESETS, type AiPromptPreset } from './ai-prompt-presets';
|
|
7
7
|
import AiRecognitionPromptInput from './components/AiRecognitionPromptInput.vue';
|
|
8
8
|
import { ElForm, ElFormItem, ElInputNumber, ElMessage, ElMessageBox, ElOption, ElSelect } from 'element-plus';
|
|
9
|
-
import { ArrowDown, Check, CircleClose, CopyDocument, Delete, Document, Download, Edit, FolderOpened, Plus, Refresh, Upload, VideoPlay, View, Clock } from '@element-plus/icons-vue';
|
|
9
|
+
import { ArrowDown, Check, CircleClose, CopyDocument, Delete, Document, Download, Edit, FolderOpened, Loading, Plus, Refresh, Upload, VideoPlay, View, Clock } from '@element-plus/icons-vue';
|
|
10
10
|
import RunHistoryDialog from './RunHistoryDialog.vue';
|
|
11
11
|
import type { AndroidDevice, AppPreset, DeviceAction } from '../types';
|
|
12
12
|
import DevicePreviewPanel from '../components/device/DevicePreviewPanel.vue';
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
getAppiumTree,
|
|
29
29
|
importAppiumScripts,
|
|
30
30
|
launchAppiumDeviceApp,
|
|
31
|
+
loadVariables,
|
|
31
32
|
replayAppiumScript,
|
|
32
33
|
saveAppiumScript,
|
|
33
34
|
saveVariables,
|
|
@@ -42,6 +43,9 @@ import StageLogSettings from './components/StageLogSettings.vue';
|
|
|
42
43
|
import TextClickSettings from './components/TextClickSettings.vue';
|
|
43
44
|
import { textClickSelector } from './text-click';
|
|
44
45
|
import { DEFAULT_LOG_PREFIX, validateStageLog } from './stage-log';
|
|
46
|
+
import RandomValueSettings from './components/RandomValueSettings.vue';
|
|
47
|
+
import { defaultRandomValue, validateRandomValue } from './random-value';
|
|
48
|
+
import { variablePresetKey, variablePresetOptions, type VariablePresetContext } from './variable-presets';
|
|
45
49
|
import RecordedSteps from './components/RecordedSteps.vue';
|
|
46
50
|
import NewScriptDialog from './components/NewScriptDialog.vue';
|
|
47
51
|
import VisualChangeDialog from './components/VisualChangeDialog.vue';
|
|
@@ -221,6 +225,55 @@ const form = reactive({
|
|
|
221
225
|
appActivity: '',
|
|
222
226
|
});
|
|
223
227
|
const scriptVariables = shallowRef<TestVariable[]>([]);
|
|
228
|
+
const globalVariables = shallowRef<TestVariable[]>([]);
|
|
229
|
+
const variablePresetsLoading = shallowRef(false);
|
|
230
|
+
const variablePresetsError = shallowRef('');
|
|
231
|
+
const availableVariablePresets = computed(() => variablePresetOptions(globalVariables.value, scriptVariables.value));
|
|
232
|
+
const pendingRandomValue = shallowRef<{ step: AppiumRecordedStep; index?: number; branchTarget?: BranchTarget } | null>(null);
|
|
233
|
+
let variablePresetsRequest: Promise<void> | undefined;
|
|
234
|
+
|
|
235
|
+
function refreshVariablePresets(): Promise<void> {
|
|
236
|
+
if (variablePresetsRequest) return variablePresetsRequest;
|
|
237
|
+
variablePresetsLoading.value = true;
|
|
238
|
+
variablePresetsError.value = '';
|
|
239
|
+
variablePresetsRequest = loadVariables('/api/appium-recorder/variables').then(result => {
|
|
240
|
+
globalVariables.value = result.variables;
|
|
241
|
+
}).catch(error => {
|
|
242
|
+
variablePresetsError.value = error instanceof Error ? error.message : '预设变量加载失败';
|
|
243
|
+
}).finally(() => {
|
|
244
|
+
variablePresetsLoading.value = false;
|
|
245
|
+
variablePresetsRequest = undefined;
|
|
246
|
+
});
|
|
247
|
+
return variablePresetsRequest;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const variablePresets: VariablePresetContext = {
|
|
251
|
+
options: availableVariablePresets, loading: variablePresetsLoading, error: variablePresetsError,
|
|
252
|
+
refresh: refreshVariablePresets, open: () => setActiveWorkbenchTab('variables'),
|
|
253
|
+
};
|
|
254
|
+
provide(variablePresetKey, variablePresets);
|
|
255
|
+
|
|
256
|
+
function validateRandomValueTarget(step: AppiumRecordedStep) {
|
|
257
|
+
if (!availableVariablePresets.value.some(variable => variable.name === step.randomValue?.name)) {
|
|
258
|
+
throw new Error(`节点「${step.label}」请选择已有预设变量;没有对应 key 时请先到“预设变量”添加`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async function validateRandomValueTargets() {
|
|
263
|
+
const randomSteps = steps.value.filter(step => step.type === 'randomValue');
|
|
264
|
+
if (!randomSteps.length) return;
|
|
265
|
+
await refreshVariablePresets();
|
|
266
|
+
randomSteps.forEach(validateRandomValueTarget);
|
|
267
|
+
steps.value = steps.value.map(step => step.randomValue && availableVariablePresets.value.some(variable => variable.name === step.randomValue!.name && variable.sensitive)
|
|
268
|
+
? { ...step, randomValue: { ...step.randomValue, sensitive: true } } : step);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function resumeRandomValue() {
|
|
272
|
+
const pending = pendingRandomValue.value;
|
|
273
|
+
if (!pending) return;
|
|
274
|
+
setActiveWorkbenchTab('recording');
|
|
275
|
+
void addAction('randomValue', pending.index, pending.branchTarget);
|
|
276
|
+
}
|
|
224
277
|
|
|
225
278
|
const savedDraftSnapshot = shallowRef('');
|
|
226
279
|
const currentDraftSnapshot = computed(() => JSON.stringify({
|
|
@@ -1578,6 +1631,36 @@ async function addAction(
|
|
|
1578
1631
|
if (result) return insertStep({ ...step }, index, branchTarget);
|
|
1579
1632
|
return;
|
|
1580
1633
|
}
|
|
1634
|
+
if (action === 'randomValue') {
|
|
1635
|
+
const step = reactive<AppiumRecordedStep>(pendingRandomValue.value?.step || {
|
|
1636
|
+
id: createStepId(), type: 'randomValue', label: '获取随机值', randomValue: { ...defaultRandomValue(), name: '' }, flow: { nodeKind: 'action' },
|
|
1637
|
+
});
|
|
1638
|
+
pendingRandomValue.value = null;
|
|
1639
|
+
const dialogPresets: VariablePresetContext = { ...variablePresets, open: () => {
|
|
1640
|
+
pendingRandomValue.value = { step: JSON.parse(JSON.stringify(step)), index, branchTarget };
|
|
1641
|
+
ElMessageBox.close();
|
|
1642
|
+
variablePresets.open();
|
|
1643
|
+
} };
|
|
1644
|
+
const result = await ElMessageBox({
|
|
1645
|
+
title: '添加获取随机值',
|
|
1646
|
+
message: h(ElForm, { labelPosition: 'top', style: { width: 'min(380px, calc(100vw - 64px))', maxHeight: '65vh', overflowY: 'auto', paddingRight: '4px' } }, () => h(RandomValueSettings, {
|
|
1647
|
+
step, presets: dialogPresets, onUpdate: patch => Object.assign(step, patch),
|
|
1648
|
+
})),
|
|
1649
|
+
showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
|
|
1650
|
+
beforeClose: (action, _instance, done) => {
|
|
1651
|
+
if (action === 'confirm') {
|
|
1652
|
+
try {
|
|
1653
|
+
validateRandomValueTarget(step);
|
|
1654
|
+
validateRandomValue(step.randomValue);
|
|
1655
|
+
if (availableVariablePresets.value.some(variable => variable.name === step.randomValue!.name && variable.sensitive)) step.randomValue!.sensitive = true;
|
|
1656
|
+
} catch (error) { ElMessage.warning(error instanceof Error ? error.message : '随机值配置无效'); return; }
|
|
1657
|
+
}
|
|
1658
|
+
done();
|
|
1659
|
+
},
|
|
1660
|
+
}).catch(() => null);
|
|
1661
|
+
if (result) return insertStep(JSON.parse(JSON.stringify(step)), index, branchTarget);
|
|
1662
|
+
return;
|
|
1663
|
+
}
|
|
1581
1664
|
if (action === 'launchApp') {
|
|
1582
1665
|
return insertStep({
|
|
1583
1666
|
id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
|
|
@@ -1863,6 +1946,7 @@ function setActiveWorkbenchTab(tab: string | number) {
|
|
|
1863
1946
|
}
|
|
1864
1947
|
|
|
1865
1948
|
function loadScript(script: AppiumRecordedScript) {
|
|
1949
|
+
pendingRandomValue.value = null;
|
|
1866
1950
|
setActiveWorkbenchTab('recording');
|
|
1867
1951
|
flowClipboard.value = null;
|
|
1868
1952
|
selectedScriptId.value = script.id;
|
|
@@ -1887,6 +1971,7 @@ function loadSelectedScript() {
|
|
|
1887
1971
|
}
|
|
1888
1972
|
|
|
1889
1973
|
function resetCurrentScript() {
|
|
1974
|
+
pendingRandomValue.value = null;
|
|
1890
1975
|
void saveVariables('/api/appium-recorder/variables?draft=1', []).catch(() => ElMessage.error('变量草稿清理失败'));
|
|
1891
1976
|
scriptVariables.value = [];
|
|
1892
1977
|
flowClipboard.value = null;
|
|
@@ -2135,6 +2220,7 @@ async function saveScript() {
|
|
|
2135
2220
|
saving.value = true;
|
|
2136
2221
|
try {
|
|
2137
2222
|
validateVariables(scriptVariables.value);
|
|
2223
|
+
await validateRandomValueTargets();
|
|
2138
2224
|
const payload = await saveAppiumScript({
|
|
2139
2225
|
id: selectedScriptId.value || undefined,
|
|
2140
2226
|
name: form.name,
|
|
@@ -2239,9 +2325,7 @@ async function stopReplay() {
|
|
|
2239
2325
|
stoppingReplay.value = true;
|
|
2240
2326
|
try {
|
|
2241
2327
|
const result = await stopAppiumReplay(activeReplayDeviceId.value);
|
|
2242
|
-
if (result.stopped) {
|
|
2243
|
-
ElMessage.info('正在终止回放并生成报告、日志和截图回放');
|
|
2244
|
-
} else {
|
|
2328
|
+
if (!result.stopped) {
|
|
2245
2329
|
stoppingReplay.value = false;
|
|
2246
2330
|
ElMessage.warning('当前没有可终止的回放任务');
|
|
2247
2331
|
}
|
|
@@ -2505,7 +2589,11 @@ watch(
|
|
|
2505
2589
|
</div>
|
|
2506
2590
|
</el-tab-pane>
|
|
2507
2591
|
<el-tab-pane label="预设变量" name="variables" lazy>
|
|
2508
|
-
<
|
|
2592
|
+
<div v-if="pendingRandomValue" class="random-value-return">
|
|
2593
|
+
<span>随机值节点配置已保留</span>
|
|
2594
|
+
<el-button type="primary" plain :disabled="recordingLocked" @click="resumeRandomValue">返回节点配置</el-button>
|
|
2595
|
+
</div>
|
|
2596
|
+
<PresetVariables :key="`${selectedScriptId}:${newScriptRevision}`" v-model:variables="scriptVariables" v-model:globals="globalVariables" :script-id="selectedScriptId" :script-name="form.name" :disabled="recordingBusy || saving" @saved="onVariablesSaved" />
|
|
2509
2597
|
</el-tab-pane>
|
|
2510
2598
|
</el-tabs>
|
|
2511
2599
|
</el-card>
|
|
@@ -2674,6 +2762,22 @@ watch(
|
|
|
2674
2762
|
</template>
|
|
2675
2763
|
</el-dialog>
|
|
2676
2764
|
|
|
2765
|
+
<el-dialog
|
|
2766
|
+
:model-value="stoppingReplay"
|
|
2767
|
+
title="报告正在生成中"
|
|
2768
|
+
width="420px"
|
|
2769
|
+
align-center
|
|
2770
|
+
append-to-body
|
|
2771
|
+
:show-close="false"
|
|
2772
|
+
:close-on-click-modal="false"
|
|
2773
|
+
:close-on-press-escape="false"
|
|
2774
|
+
>
|
|
2775
|
+
<div class="appium-report-progress" role="status" aria-live="polite">
|
|
2776
|
+
<el-icon class="is-loading" aria-hidden="true"><Loading /></el-icon>
|
|
2777
|
+
<span>正在终止回放并生成报告、日志和截图回放,请稍候。</span>
|
|
2778
|
+
</div>
|
|
2779
|
+
</el-dialog>
|
|
2780
|
+
|
|
2677
2781
|
<el-dialog
|
|
2678
2782
|
v-model="replayOutputDialogVisible"
|
|
2679
2783
|
title="回放输出"
|
|
@@ -2710,6 +2814,8 @@ watch(
|
|
|
2710
2814
|
</template>
|
|
2711
2815
|
|
|
2712
2816
|
<style scoped>
|
|
2817
|
+
.appium-report-progress { display: flex; align-items: center; gap: 12px; line-height: 1.6; }
|
|
2818
|
+
.random-value-return { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; color: var(--el-text-color-secondary); font-size: 13px; }
|
|
2713
2819
|
.appium-script-icon { display: inline-flex; }
|
|
2714
2820
|
.appium-script-icon .el-button { width: 30px; height: 30px; min-height: 30px; padding: 0; margin: 0; }
|
|
2715
2821
|
:deep(.appium-recorder-card--workbench > .el-card__body) { overflow: hidden; }
|
|
@@ -6,6 +6,7 @@ export const actionDescriptions: Record<InsertAction, string> = {
|
|
|
6
6
|
tap: '记录点击当前选中的组件,回放时重新定位后点击。',
|
|
7
7
|
input: '向当前选中的输入组件写入指定文字,支持 {{变量名}} 引用。',
|
|
8
8
|
extractVariable: '读取组件文字或属性,保存到当前脚本变量供后续节点引用。',
|
|
9
|
+
randomValue: '从预设文本或导入的 TXT 中抽取一条,或生成随机整数、UUID,写入脚本变量。每次执行抽取一次,放在循环体内可每轮重新取值。',
|
|
9
10
|
clearInput: '清空当前选中输入组件的内容。',
|
|
10
11
|
coordinateTap: '点击设备屏幕上的指定 X、Y 坐标。节点中可修改坐标,页面位置变化后需重新确认。',
|
|
11
12
|
longPress: '长按指定元素或屏幕坐标,可设置按住时长,默认按元素定位。',
|
|
@@ -13,6 +13,7 @@ import StageLogSettings from './StageLogSettings.vue';
|
|
|
13
13
|
import LoopSettings from './LoopSettings.vue';
|
|
14
14
|
import BreakLoopSettings from './BreakLoopSettings.vue';
|
|
15
15
|
import VariableExtractionSettings from './VariableExtractionSettings.vue';
|
|
16
|
+
import RandomValueSettings from './RandomValueSettings.vue';
|
|
16
17
|
import ScriptParameterSettings from './ScriptParameterSettings.vue';
|
|
17
18
|
import AiRecognitionSettings from './AiRecognitionSettings.vue';
|
|
18
19
|
|
|
@@ -59,7 +60,7 @@ const selectorSummary = computed(() => {
|
|
|
59
60
|
return `${selector.strategy} · ${value}${props.step.contextSelector ? ' · 含父级' : ''}`;
|
|
60
61
|
});
|
|
61
62
|
const supportsTimeout = computed(() => ![
|
|
62
|
-
'delay', 'longPress', 'stopApp', 'log', 'openGallery', 'endFlow', 'loop', 'breakLoop', 'continueLoop', 'aiRecognition',
|
|
63
|
+
'delay', 'longPress', 'stopApp', 'log', 'openGallery', 'endFlow', 'loop', 'breakLoop', 'continueLoop', 'aiRecognition', 'randomValue',
|
|
63
64
|
].includes(props.step.type));
|
|
64
65
|
|
|
65
66
|
function defaultKind(): FlowKind {
|
|
@@ -188,6 +189,7 @@ function patchSelector(patch: Partial<AppiumSelector>) {
|
|
|
188
189
|
</template>
|
|
189
190
|
<StageLogSettings v-if="step.type === 'log'" :step="step" :disabled="disabled" @update="patchStep" />
|
|
190
191
|
<VariableExtractionSettings v-if="step.type === 'extractVariable'" :step="step" :disabled="disabled" @update="patchStep" />
|
|
192
|
+
<RandomValueSettings v-if="step.type === 'randomValue'" :step="step" :disabled="disabled" @update="patchStep" />
|
|
191
193
|
<ScriptParameterSettings v-if="step.type === 'runScript'" :step="step" :disabled="disabled" @update="patchStep" />
|
|
192
194
|
<LoopSettings v-if="step.type === 'loop'" :step="step" :disabled="disabled" @update="patchStep" />
|
|
193
195
|
<BreakLoopSettings v-if="step.type === 'breakLoop' || step.type === 'continueLoop'" :step="step" :steps="steps" :disabled="disabled" :mode="step.type === 'continueLoop' ? 'continue' : 'break'" @update="patchStep" />
|
|
@@ -102,6 +102,7 @@ const actionGroups: FlowActionGroup[] = [
|
|
|
102
102
|
{
|
|
103
103
|
title: '流程控制',
|
|
104
104
|
actions: [
|
|
105
|
+
{ type: 'randomValue', label: '获取随机值' },
|
|
105
106
|
{ type: 'noop', label: '空节点' },
|
|
106
107
|
{ type: 'endFlow', label: '终止流程' },
|
|
107
108
|
{
|
|
@@ -131,6 +132,7 @@ function typeLabel(step: AppiumRecordedStep) {
|
|
|
131
132
|
coordinateTap: '坐标点击', swipe: '滑动', launchApp: '启动 APP', stopApp: '杀死 APP', clearAppData: '清理 APP 缓存', longPress: '长按',
|
|
132
133
|
pinch: '双指缩放', runScript: '连接脚本', screenshot: '截图', visualChange: '检测画面变化',
|
|
133
134
|
noop: '空节点',
|
|
135
|
+
randomValue: '获取随机值',
|
|
134
136
|
endFlow: '终止流程',
|
|
135
137
|
loop: '有界循环',
|
|
136
138
|
breakLoop: '退出循环',
|
|
@@ -148,6 +150,7 @@ function typeLabel(step: AppiumRecordedStep) {
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
function stepMeta(step: AppiumRecordedStep) {
|
|
153
|
+
if (step.type === 'randomValue') return flowStepMeta(step);
|
|
151
154
|
if (step.type === 'imageCheck') return flowStepMeta(step);
|
|
152
155
|
if (step.type === 'delay') return `${step.timeoutMs || 1000}ms`;
|
|
153
156
|
if (step.type === 'input' || step.type === 'inputIfExists') return `输入内容:${step.value || '空'}`;
|
|
@@ -4,9 +4,8 @@ import { QuestionFilled } from '@element-plus/icons-vue';
|
|
|
4
4
|
import { loadVariables, saveVariables } from '../api';
|
|
5
5
|
import VariableTable from './VariableTable.vue';
|
|
6
6
|
import { validateVariables, type TestVariable } from '../variables';
|
|
7
|
-
const props = defineProps<{ variables: TestVariable[]; disabled?: boolean; scriptName: string; scriptId: string }>();
|
|
8
|
-
const emit = defineEmits<{ 'update:variables': [TestVariable[]]; saved: [string, TestVariable[]] }>();
|
|
9
|
-
const globals = ref<TestVariable[]>([]);
|
|
7
|
+
const props = defineProps<{ variables: TestVariable[]; globals: TestVariable[]; disabled?: boolean; scriptName: string; scriptId: string }>();
|
|
8
|
+
const emit = defineEmits<{ 'update:variables': [TestVariable[]]; 'update:globals': [TestVariable[]]; saved: [string, TestVariable[]] }>();
|
|
10
9
|
const busy = ref(false);
|
|
11
10
|
const loaded = ref(false);
|
|
12
11
|
const error = ref('');
|
|
@@ -19,7 +18,9 @@ const privateUrl = props.scriptId ? `/api/appium-recorder/variables?scriptId=${e
|
|
|
19
18
|
async function load() {
|
|
20
19
|
busy.value = true; error.value = '';
|
|
21
20
|
try {
|
|
22
|
-
globals
|
|
21
|
+
const globals = (await loadVariables('/api/appium-recorder/variables')).variables;
|
|
22
|
+
if (mounted) emit('update:globals', globals);
|
|
23
|
+
loaded.value = true;
|
|
23
24
|
if (props.scriptId || !props.variables.length) {
|
|
24
25
|
const variables = (await loadVariables(privateUrl)).variables;
|
|
25
26
|
if (mounted) emit('update:variables', variables);
|
|
@@ -28,7 +29,7 @@ async function load() {
|
|
|
28
29
|
finally { busy.value = false; }
|
|
29
30
|
}
|
|
30
31
|
function update(scope: 'global' | 'private', values: TestVariable[]) {
|
|
31
|
-
if (scope === 'global') globals
|
|
32
|
+
if (scope === 'global') emit('update:globals', values);
|
|
32
33
|
else emit('update:variables', values);
|
|
33
34
|
const revision = ++revisions[scope];
|
|
34
35
|
let variables: TestVariable[];
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, inject, onMounted, shallowRef, useTemplateRef } from 'vue';
|
|
3
|
+
import { ElMessage } from 'element-plus';
|
|
4
|
+
import { Upload } from '@element-plus/icons-vue';
|
|
5
|
+
import type { AppiumRecordedStep } from '../types';
|
|
6
|
+
import { defaultRandomValue, MAX_RANDOM_FILE_BYTES, randomTextCandidates, type RandomValueConfig } from '../random-value';
|
|
7
|
+
import { sensitiveVariableName } from '../variables';
|
|
8
|
+
import { variablePresetKey, type VariablePresetContext } from '../variable-presets';
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{ step: AppiumRecordedStep; disabled?: boolean; presets?: VariablePresetContext }>();
|
|
11
|
+
const emit = defineEmits<{ update: [Partial<AppiumRecordedStep>] }>();
|
|
12
|
+
const config = computed(() => ({ ...defaultRandomValue(), ...props.step.randomValue }));
|
|
13
|
+
const fileInput = useTemplateRef<HTMLInputElement>('fileInput');
|
|
14
|
+
const importing = shallowRef(false);
|
|
15
|
+
const inheritedPresets = inject(variablePresetKey, undefined);
|
|
16
|
+
const presets = computed(() => props.presets || inheritedPresets);
|
|
17
|
+
const variableOptions = computed(() => presets.value?.options.value || []);
|
|
18
|
+
const variablesLoading = computed(() => presets.value?.loading.value || false);
|
|
19
|
+
const variablesError = computed(() => presets.value?.error.value || '');
|
|
20
|
+
const selectedVariable = computed(() => variableOptions.value.find(variable => variable.name === config.value.name));
|
|
21
|
+
const fixedSensitive = computed(() => Boolean(selectedVariable.value?.sensitive || sensitiveVariableName(config.value.name)));
|
|
22
|
+
const sensitive = computed(() => Boolean(config.value.sensitive || fixedSensitive.value));
|
|
23
|
+
const missingVariable = computed(() => Boolean(config.value.name && !selectedVariable.value && !variablesLoading.value));
|
|
24
|
+
const reference = computed(() => `{{${config.value.name || '变量名'}}}`);
|
|
25
|
+
const candidateCount = computed(() => {
|
|
26
|
+
try {
|
|
27
|
+
const candidates = randomTextCandidates(config.value.text);
|
|
28
|
+
return config.value.withoutReplacement ? new Set(candidates).size : candidates.length;
|
|
29
|
+
} catch { return 0; }
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function update(patch: Partial<RandomValueConfig>) {
|
|
33
|
+
emit('update', { randomValue: { ...config.value, ...patch } });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function refreshVariables(visible: boolean) {
|
|
37
|
+
if (visible) void presets.value?.refresh();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onMounted(() => { void presets.value?.refresh(); });
|
|
41
|
+
|
|
42
|
+
async function importText(event: Event) {
|
|
43
|
+
const input = event.target as HTMLInputElement;
|
|
44
|
+
const file = input.files?.[0];
|
|
45
|
+
input.value = '';
|
|
46
|
+
if (!file || props.disabled) return;
|
|
47
|
+
importing.value = true;
|
|
48
|
+
try {
|
|
49
|
+
if (file.size > MAX_RANDOM_FILE_BYTES) throw new Error('TXT 文件不能超过 1 MB');
|
|
50
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(await file.arrayBuffer());
|
|
51
|
+
randomTextCandidates(text);
|
|
52
|
+
update({ text, sourceName: file.name });
|
|
53
|
+
} catch (error) {
|
|
54
|
+
ElMessage.error(error instanceof TypeError ? '请导入 UTF-8 编码的 TXT 文件' : error instanceof Error ? error.message : 'TXT 导入失败');
|
|
55
|
+
} finally { importing.value = false; }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<div class="random-value-settings">
|
|
62
|
+
<el-form-item label="结果类型">
|
|
63
|
+
<el-select :model-value="config.mode" :disabled="disabled" aria-label="随机值类型" @update:model-value="update({ mode: $event })">
|
|
64
|
+
<el-option label="预设文本 / TXT" value="text" />
|
|
65
|
+
<el-option label="随机整数" value="integer" />
|
|
66
|
+
<el-option label="随机 ID(UUID)" value="uuid" />
|
|
67
|
+
</el-select>
|
|
68
|
+
</el-form-item>
|
|
69
|
+
<el-form-item label="保存到变量">
|
|
70
|
+
<div class="random-value-settings__field">
|
|
71
|
+
<el-select class="random-value-settings__variable-select" :model-value="config.name || undefined" :disabled="disabled" :loading="variablesLoading" filterable placeholder="选择预设变量 key" aria-label="随机值变量名" @visible-change="refreshVariables" @update:model-value="update({ name: String($event), sensitive: variableOptions.find(variable => variable.name === $event)?.sensitive || undefined })">
|
|
72
|
+
<el-option v-if="missingVariable" :label="`${config.name}(未预设)`" :value="config.name" disabled />
|
|
73
|
+
<el-option v-for="variable in variableOptions" :key="variable.name" :label="variable.name" :value="variable.name">
|
|
74
|
+
<span>{{ variable.name }}</span><small class="random-value-settings__scope">{{ variable.scope === 'private' ? '私有' : '全局' }}</small>
|
|
75
|
+
</el-option>
|
|
76
|
+
<template #empty><div class="random-value-settings__empty">暂无匹配的预设变量</div></template>
|
|
77
|
+
</el-select>
|
|
78
|
+
<div class="random-value-settings__variable-help">
|
|
79
|
+
<span class="random-value-settings__hint">{{ selectedVariable ? (selectedVariable.scope === 'private' ? '当前脚本私有变量' : '使用全局 key,结果保存在当前脚本') : '选择已有 key 保存结果' }}</span>
|
|
80
|
+
<el-button link type="primary" :disabled="disabled || !presets" @click="presets?.open()">去添加变量</el-button>
|
|
81
|
+
</div>
|
|
82
|
+
<span v-if="variablesError" class="random-value-settings__error" role="alert">变量加载失败 <el-button link type="primary" :disabled="variablesLoading" @click="presets?.refresh()">重试</el-button></span>
|
|
83
|
+
<span v-else-if="missingVariable" class="random-value-settings__error" role="alert">此 key 尚未预设,请先添加或重新选择。</span>
|
|
84
|
+
</div>
|
|
85
|
+
</el-form-item>
|
|
86
|
+
<template v-if="config.mode === 'text'">
|
|
87
|
+
<el-form-item label="候选内容">
|
|
88
|
+
<div class="random-value-settings__field">
|
|
89
|
+
<el-input type="textarea" :rows="4" :model-value="config.text || ''" :disabled="disabled" placeholder="每行一条候选内容" aria-label="随机候选内容" @update:model-value="update({ text: String($event), sourceName: undefined })" />
|
|
90
|
+
<div class="random-value-settings__import">
|
|
91
|
+
<input ref="fileInput" type="file" accept=".txt,text/plain" hidden aria-label="导入随机候选 TXT" :disabled="disabled || importing" @change="importText" />
|
|
92
|
+
<el-button :icon="Upload" :disabled="disabled" :loading="importing" @click="fileInput?.click()">导入 TXT</el-button>
|
|
93
|
+
<span class="random-value-settings__count">{{ candidateCount }} 条{{ config.withoutReplacement ? '不同' : '' }}候选</span>
|
|
94
|
+
</div>
|
|
95
|
+
<span v-if="config.sourceName" class="random-value-settings__hint random-value-settings__file" :title="config.sourceName">{{ config.sourceName }}</span>
|
|
96
|
+
<span class="random-value-settings__hint">UTF-8 · 每行一条,忽略空行和 # 注释。内容随脚本保存。</span>
|
|
97
|
+
</div>
|
|
98
|
+
</el-form-item>
|
|
99
|
+
<el-form-item label="抽取方式">
|
|
100
|
+
<div class="random-value-settings__field">
|
|
101
|
+
<el-select :model-value="config.withoutReplacement === true" :disabled="disabled" aria-label="随机抽取方式" @update:model-value="update({ withoutReplacement: $event === true })">
|
|
102
|
+
<el-option label="允许重复抽取" :value="false" />
|
|
103
|
+
<el-option label="本次运行不重复" :value="true" />
|
|
104
|
+
</el-select>
|
|
105
|
+
<span v-if="config.withoutReplacement" class="random-value-settings__hint">候选耗尽时停止,下次回放重新开始。</span>
|
|
106
|
+
</div>
|
|
107
|
+
</el-form-item>
|
|
108
|
+
</template>
|
|
109
|
+
<template v-if="config.mode === 'integer'">
|
|
110
|
+
<el-form-item label="最小值">
|
|
111
|
+
<el-input-number :model-value="config.min ?? 0" :disabled="disabled" :precision="0" controls-position="right" aria-label="随机整数最小值" @update:model-value="update({ min: $event ?? 0 })" />
|
|
112
|
+
</el-form-item>
|
|
113
|
+
<el-form-item label="最大值">
|
|
114
|
+
<el-input-number :model-value="config.max ?? 9999" :disabled="disabled" :precision="0" controls-position="right" aria-label="随机整数最大值" @update:model-value="update({ max: $event ?? 9999 })" />
|
|
115
|
+
</el-form-item>
|
|
116
|
+
<span class="random-value-settings__hint">包含最小值和最大值,结果以文本保存。</span>
|
|
117
|
+
</template>
|
|
118
|
+
<span v-if="config.mode === 'uuid'" class="random-value-settings__hint">每次执行生成一个 UUID,并以文本保存。</span>
|
|
119
|
+
<el-form-item label="敏感值">
|
|
120
|
+
<el-checkbox :model-value="sensitive" :disabled="disabled || fixedSensitive" @update:model-value="update({ sensitive: $event === true })">隐藏日志中的结果</el-checkbox>
|
|
121
|
+
</el-form-item>
|
|
122
|
+
<span v-if="sensitive && config.mode === 'text'" class="random-value-settings__hint">导出时清空敏感候选内容。</span>
|
|
123
|
+
<span class="random-value-settings__hint">后续通过 <code>{{ reference }}</code> 引用结果。</span>
|
|
124
|
+
</div>
|
|
125
|
+
</template>
|
|
126
|
+
|
|
127
|
+
<style scoped>
|
|
128
|
+
.random-value-settings { display: flex; flex-direction: column; gap: 12px; min-width: 0; text-align: left; }
|
|
129
|
+
.random-value-settings :deep(.el-form-item) { margin-bottom: 0; }
|
|
130
|
+
.random-value-settings__field { display: grid; gap: 8px; width: 100%; min-width: 0; }
|
|
131
|
+
.random-value-settings__import, .random-value-settings__variable-help { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
|
|
132
|
+
.random-value-settings__variable-help .el-button { padding: 0; font-size: 12px; }
|
|
133
|
+
.random-value-settings__count { font-size: 12px; color: var(--ui-text-secondary, #64748b); }
|
|
134
|
+
.random-value-settings__scope { float: right; margin-left: 16px; color: var(--el-text-color-secondary); }
|
|
135
|
+
.random-value-settings__empty { padding: 12px; color: var(--el-text-color-secondary); text-align: center; }
|
|
136
|
+
.random-value-settings__file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
137
|
+
.random-value-settings__error { color: var(--el-color-danger); font-size: 12px; line-height: 1.5; }
|
|
138
|
+
.random-value-settings__hint { color: var(--ui-text-secondary, #64748b); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
|
|
139
|
+
</style>
|
|
@@ -6,6 +6,7 @@ import { isNativeStateCondition } from './native-control-state';
|
|
|
6
6
|
import { DEFAULT_LOG_PREFIX } from './stage-log';
|
|
7
7
|
import { imageCheckSummary } from './image-check';
|
|
8
8
|
import { isAiBranchEnabled } from './ai-recognition';
|
|
9
|
+
import { randomValueSummary } from './random-value';
|
|
9
10
|
|
|
10
11
|
export function isBooleanCondition(step: Pick<AppiumRecordedStep, 'type' | 'aiBranchEnabled'>) {
|
|
11
12
|
return isNativeStateCondition(step) || (step.type === 'aiRecognition' && isAiBranchEnabled(step)) || step.type === 'textClick' || step.type === 'imageCheck';
|
|
@@ -13,7 +14,7 @@ export function isBooleanCondition(step: Pick<AppiumRecordedStep, 'type' | 'aiBr
|
|
|
13
14
|
|
|
14
15
|
export function defaultFlowKind(step: AppiumRecordedStep): FlowKind {
|
|
15
16
|
if (step.type === 'aiRecognition') return isAiBranchEnabled(step) ? 'condition' : 'action';
|
|
16
|
-
if (step.type === 'extractVariable') return 'action';
|
|
17
|
+
if (step.type === 'extractVariable' || step.type === 'randomValue') return 'action';
|
|
17
18
|
if (step.type === 'loop') return 'condition';
|
|
18
19
|
if (step.type === 'breakLoop' || step.type === 'continueLoop') return 'action';
|
|
19
20
|
if (step.type === 'log' || step.type === 'openGallery' || step.type === 'endFlow') return 'action';
|
|
@@ -73,12 +74,14 @@ export function flowTypeLabel(step: AppiumRecordedStep) {
|
|
|
73
74
|
noop: '空节点',
|
|
74
75
|
log: '输出日志',
|
|
75
76
|
extractVariable: '提取变量',
|
|
77
|
+
randomValue: '获取随机值',
|
|
76
78
|
visualChange: '检测画面变化',
|
|
77
79
|
};
|
|
78
80
|
return labelMap[step.type] || step.type;
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
export function flowStepMeta(step: AppiumRecordedStep) {
|
|
84
|
+
if (step.type === 'randomValue') return randomValueSummary(step.randomValue);
|
|
82
85
|
if (step.type === 'imageCheck') return imageCheckSummary(step.imageCheck);
|
|
83
86
|
if (step.type === 'extractVariable') return `${step.extractVariable?.attribute || 'text'} → ${step.extractVariable?.name || '未设置变量名'}`;
|
|
84
87
|
if (step.type === 'loop') return `最多 ${step.loop?.maxIterations ?? '?'} 次 · ${step.loop?.exitWhen === 'exists' ? '元素出现时退出' : step.loop?.exitWhen === 'notExists' ? '元素消失时退出' : '固定次数'}${step.loop?.exitWhen !== 'never' ? ` ${step.selector?.value || ''}` : ''}`;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { sensitiveVariableName, validateVariables } from './variables';
|
|
2
|
+
|
|
3
|
+
export type RandomValueConfig = {
|
|
4
|
+
name: string;
|
|
5
|
+
mode: 'text' | 'integer' | 'uuid';
|
|
6
|
+
text?: string;
|
|
7
|
+
sourceName?: string;
|
|
8
|
+
withoutReplacement?: boolean;
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
sensitive?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const MAX_RANDOM_TEXT_LENGTH = 200000;
|
|
15
|
+
export const MAX_RANDOM_FILE_BYTES = 1024 * 1024;
|
|
16
|
+
export const MAX_RANDOM_INTEGER_RANGE = 2 ** 48 - 1;
|
|
17
|
+
export const defaultRandomValue = (): RandomValueConfig => ({
|
|
18
|
+
name: 'RANDOM_VALUE', mode: 'text', text: '', min: 0, max: 9999, withoutReplacement: false,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export function randomTextCandidates(text: unknown): string[] {
|
|
22
|
+
if (typeof text !== 'string' || text.length > MAX_RANDOM_TEXT_LENGTH) throw new Error(`候选文本须为文本且不超过 ${MAX_RANDOM_TEXT_LENGTH} 字符`);
|
|
23
|
+
const candidates = text.replace(/^\uFEFF/, '').split(/\r?\n/u).map(line => line.trim())
|
|
24
|
+
.filter(line => line && !line.startsWith('#'));
|
|
25
|
+
if (!candidates.length) throw new Error('请填写候选文本或导入 TXT,每行一条');
|
|
26
|
+
if (candidates.length > 10000 || candidates.some(line => line.length > 20000)) throw new Error('候选最多 10000 条,每条不超过 20000 字符');
|
|
27
|
+
return candidates;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function validateRandomValue(input: RandomValueConfig | undefined, options: { allowEmptySensitiveText?: boolean } = {}): RandomValueConfig {
|
|
31
|
+
if (!input || typeof input !== 'object') throw new Error('请配置获取随机值节点');
|
|
32
|
+
validateVariables([{ name: input.name, value: '', sensitive: input.sensitive }]);
|
|
33
|
+
if (input.withoutReplacement !== undefined && typeof input.withoutReplacement !== 'boolean') throw new Error('不重复抽取选项须为布尔值');
|
|
34
|
+
if (input.sensitive !== undefined && typeof input.sensitive !== 'boolean') throw new Error('敏感值选项须为布尔值');
|
|
35
|
+
// 敏感池导出时清空;允许导入为待填写模板,实际预览和执行仍须有候选内容。
|
|
36
|
+
if (input.mode === 'text') {
|
|
37
|
+
if (!(options.allowEmptySensitiveText && input.text === '' && (input.sensitive || sensitiveVariableName(input.name)))) randomTextCandidates(input.text);
|
|
38
|
+
}
|
|
39
|
+
else if (input.mode === 'integer') {
|
|
40
|
+
if (!Number.isSafeInteger(input.min) || !Number.isSafeInteger(input.max) || input.min! > input.max!) throw new Error('最小值和最大值须为安全整数,且最小值不能大于最大值');
|
|
41
|
+
const range = input.max! - input.min! + 1;
|
|
42
|
+
if (!Number.isSafeInteger(range) || range > MAX_RANDOM_INTEGER_RANGE) throw new Error(`整数范围跨度不能超过 ${MAX_RANDOM_INTEGER_RANGE}`);
|
|
43
|
+
} else if (input.mode !== 'uuid') throw new Error('随机值类型无效');
|
|
44
|
+
return input;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function randomValueSummary(config: RandomValueConfig | undefined) {
|
|
48
|
+
if (!config) return '未配置随机值';
|
|
49
|
+
let source = '随机 ID(UUID)';
|
|
50
|
+
if (config.mode === 'integer') source = `随机整数 ${config.min ?? '?'}~${config.max ?? '?'}`;
|
|
51
|
+
if (config.mode === 'text') {
|
|
52
|
+
let count = 0;
|
|
53
|
+
try {
|
|
54
|
+
const candidates = randomTextCandidates(config.text);
|
|
55
|
+
count = config.withoutReplacement ? new Set(candidates).size : candidates.length;
|
|
56
|
+
} catch { /* 编辑中的空内容仍允许展示节点。 */ }
|
|
57
|
+
source = `${count} 条候选 · ${config.withoutReplacement ? '本次运行不重复' : '允许重复'}`;
|
|
58
|
+
}
|
|
59
|
+
return `${source} → ${config.name || '未设置变量名'}`;
|
|
60
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AiInvalidResultBranch, AiObservationConfig } from './ai-recognition';
|
|
2
2
|
import type { TestVariable, VariableExtraction, ScriptReturn } from './variables';
|
|
3
3
|
import type { ImageCheckConfig } from './image-check';
|
|
4
|
+
import type { RandomValueConfig } from './random-value';
|
|
4
5
|
|
|
5
6
|
export type AppiumBounds = {
|
|
6
7
|
left: number;
|
|
@@ -108,6 +109,7 @@ export type AppiumRecordedStep = {
|
|
|
108
109
|
| 'runScript'
|
|
109
110
|
| 'noop'
|
|
110
111
|
| 'extractVariable'
|
|
112
|
+
| 'randomValue'
|
|
111
113
|
| 'log'
|
|
112
114
|
| 'visualChange';
|
|
113
115
|
label: string;
|
|
@@ -119,6 +121,7 @@ export type AppiumRecordedStep = {
|
|
|
119
121
|
value?: string;
|
|
120
122
|
logPrefix?: string;
|
|
121
123
|
extractVariable?: VariableExtraction;
|
|
124
|
+
randomValue?: RandomValueConfig;
|
|
122
125
|
parameters?: TestVariable[];
|
|
123
126
|
returns?: ScriptReturn[];
|
|
124
127
|
keyCode?: number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InjectionKey, Ref } from 'vue';
|
|
2
|
+
import { sensitiveVariableName, VARIABLE_NAME, type TestVariable } from './variables';
|
|
3
|
+
|
|
4
|
+
export type VariablePresetOption = { name: string; sensitive: boolean; scope: 'global' | 'private' };
|
|
5
|
+
export type VariablePresetContext = {
|
|
6
|
+
options: Readonly<Ref<VariablePresetOption[]>>;
|
|
7
|
+
loading: Readonly<Ref<boolean>>;
|
|
8
|
+
error: Readonly<Ref<string>>;
|
|
9
|
+
refresh: () => Promise<void>;
|
|
10
|
+
open: () => void;
|
|
11
|
+
};
|
|
12
|
+
export const variablePresetKey: InjectionKey<VariablePresetContext> = Symbol('variable-presets');
|
|
13
|
+
|
|
14
|
+
export function variablePresetOptions(globals: TestVariable[], privateVariables: TestVariable[]): VariablePresetOption[] {
|
|
15
|
+
const options = new Map<string, VariablePresetOption>();
|
|
16
|
+
for (const [scope, variables] of [['global', globals], ['private', privateVariables]] as const) {
|
|
17
|
+
for (const variable of variables) {
|
|
18
|
+
if (!VARIABLE_NAME.test(variable.name) || variable.name.length > 80) continue;
|
|
19
|
+
options.set(variable.name, { name: variable.name, scope,
|
|
20
|
+
sensitive: Boolean(variable.sensitive || options.get(variable.name)?.sensitive || sensitiveVariableName(variable.name)) });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return [...options.values()];
|
|
24
|
+
}
|