android-midscene-automation 1.1.8 → 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 +62 -52
- package/README.md +61 -52
- 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/FlowCanvas.vue +52 -28
- package/src/appium-recorder/components/FlowNodeCard.vue +15 -4
- 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 +3 -2
- 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/components/config/AppiumConfigPanel.vue +22 -9
- 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: '长按指定元素或屏幕坐标,可设置按住时长,默认按元素定位。',
|
|
@@ -92,6 +92,7 @@ const measuredNodeHeights = shallowRef<Record<string, number>>({});
|
|
|
92
92
|
const { fitView, updateNodeInternals, findNode, setCenter, setViewport, viewport } = useVueFlow(props.id);
|
|
93
93
|
const paneReady = shallowRef(false);
|
|
94
94
|
let internalsFrame = 0;
|
|
95
|
+
const pendingInternals = new Set<string>();
|
|
95
96
|
let resizeFrame = 0;
|
|
96
97
|
let pendingNodeHeights: Record<string, number> = {};
|
|
97
98
|
let resetViewFrame = 0;
|
|
@@ -114,28 +115,41 @@ watch(() => [props.searchFocusToken, props.searchTargetId, props.searchActive, p
|
|
|
114
115
|
});
|
|
115
116
|
});
|
|
116
117
|
|
|
117
|
-
const graph = computed(() =>
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
118
|
+
const graph = computed<ReturnType<typeof buildFlowGraph>>((previous) => {
|
|
119
|
+
const next = buildFlowGraph(props.steps, {
|
|
120
|
+
layoutDirection: layoutDirection.value,
|
|
121
|
+
deleteMode: props.deleteMode,
|
|
122
|
+
mergeDisabled: props.mergeDisabled,
|
|
123
|
+
aiRecognitionModelConfigured: props.aiRecognitionModelConfigured,
|
|
124
|
+
// 展开先更新当前卡片,布局只响应随后测到的实际尺寸。
|
|
125
|
+
expandedStepIndex: null,
|
|
126
|
+
selectedCopyIndexes: props.selectedCopyIndexes,
|
|
127
|
+
copyMode: props.copyMode,
|
|
128
|
+
disabled: props.disabled,
|
|
129
|
+
removeDisabled: props.removeDisabled,
|
|
130
|
+
launchingStepId: props.launchingStepId,
|
|
131
|
+
clipboardCount: props.clipboardCount,
|
|
132
|
+
canOpenInsertMenu: props.canOpenInsertMenu,
|
|
133
|
+
isStartActionDisabled: props.isStartActionDisabled,
|
|
134
|
+
isInsertActionDisabled: props.isInsertActionDisabled,
|
|
135
|
+
isAppExecutionDisabled: props.isAppExecutionDisabled,
|
|
136
|
+
startActionGroups: props.startActionGroups,
|
|
137
|
+
mainActionGroups: props.mainActionGroups,
|
|
138
|
+
measuredNodeHeights: measuredNodeHeights.value,
|
|
139
|
+
labelStep: props.labelStep,
|
|
140
|
+
isCopySelected: props.isCopySelected,
|
|
141
|
+
});
|
|
142
|
+
const previousNodes = new Map(previous?.nodes.map(node => [node.id, node]));
|
|
143
|
+
for (const node of next.nodes) {
|
|
144
|
+
const old = previousNodes.get(node.id)?.data;
|
|
145
|
+
// 保持未修改节点的配置引用,避免一次展开让所有卡片重新渲染。
|
|
146
|
+
if (old && node.data && Object.keys(old).length === Object.keys(node.data).length
|
|
147
|
+
&& Object.entries(node.data).every(([key, value]) => Reflect.get(old, key) === value)) {
|
|
148
|
+
node.data = old;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return next;
|
|
152
|
+
});
|
|
139
153
|
|
|
140
154
|
function handleNodeResize(payload: { id: string; height: number }) {
|
|
141
155
|
const height = Math.ceil(payload.height) + 6;
|
|
@@ -181,11 +195,14 @@ function handleNodeClick(index: number) {
|
|
|
181
195
|
if (focusedNodeId) void nextTick(() => scheduleNodeFocus(focusedNodeId));
|
|
182
196
|
}
|
|
183
197
|
|
|
184
|
-
function scheduleNodeInternalsUpdate() {
|
|
185
|
-
|
|
198
|
+
function scheduleNodeInternalsUpdate(ids = graph.value.nodes.map(node => node.id)) {
|
|
199
|
+
ids.forEach(id => pendingInternals.add(id));
|
|
200
|
+
if (internalsFrame) return;
|
|
186
201
|
internalsFrame = window.requestAnimationFrame(() => {
|
|
187
202
|
internalsFrame = 0;
|
|
188
|
-
|
|
203
|
+
const changed = [...pendingInternals];
|
|
204
|
+
pendingInternals.clear();
|
|
205
|
+
if (changed.length) updateNodeInternals(changed);
|
|
189
206
|
preserveInsertionPosition();
|
|
190
207
|
});
|
|
191
208
|
}
|
|
@@ -260,11 +277,17 @@ watch(flowStructureKey, () => {
|
|
|
260
277
|
if (retained.length !== Object.keys(measuredNodeHeights.value).length) {
|
|
261
278
|
measuredNodeHeights.value = Object.fromEntries(retained);
|
|
262
279
|
}
|
|
263
|
-
void nextTick(scheduleNodeInternalsUpdate);
|
|
264
280
|
});
|
|
265
281
|
|
|
266
|
-
watch(graph, () => {
|
|
267
|
-
|
|
282
|
+
watch(graph, (next, previous) => {
|
|
283
|
+
const previousNodes = new Map(previous.nodes.map(node => [node.id, node]));
|
|
284
|
+
const changed = next.nodes.filter(node => {
|
|
285
|
+
const old = previousNodes.get(node.id);
|
|
286
|
+
return !old || old.data !== node.data || old.width !== node.width || old.height !== node.height
|
|
287
|
+
|| old.sourcePosition !== node.sourcePosition || old.targetPosition !== node.targetPosition;
|
|
288
|
+
}).map(node => node.id);
|
|
289
|
+
// 平移后的相对连接点不变,只测量新增或尺寸、内容发生变化的节点。
|
|
290
|
+
void nextTick(() => scheduleNodeInternalsUpdate(changed));
|
|
268
291
|
});
|
|
269
292
|
|
|
270
293
|
watch(layoutDirection, () => {
|
|
@@ -345,6 +368,7 @@ function handleInsert(payload: {
|
|
|
345
368
|
:steps="steps"
|
|
346
369
|
:node-id="nodeId"
|
|
347
370
|
:data="data"
|
|
371
|
+
:expanded="data.kind === 'step' && data.index === expandedStepIndex"
|
|
348
372
|
:readonly="props.readonly"
|
|
349
373
|
:search-highlighted="nodeId === `step:${searchTargetId}`"
|
|
350
374
|
@node-click="handleNodeClick"
|
|
@@ -17,6 +17,7 @@ const props = defineProps<{
|
|
|
17
17
|
nodeId: string;
|
|
18
18
|
data: FlowGraphNodeData;
|
|
19
19
|
steps: AppiumRecordedStep[];
|
|
20
|
+
expanded: boolean;
|
|
20
21
|
readonly?: boolean;
|
|
21
22
|
searchHighlighted?: boolean;
|
|
22
23
|
}>();
|
|
@@ -38,6 +39,11 @@ const layoutDirection = inject(flowLayoutDirectionKey, computed(() => normalizeF
|
|
|
38
39
|
const horizontal = computed(() => layoutDirection.value === 'horizontal');
|
|
39
40
|
|
|
40
41
|
const rootRef = shallowRef<HTMLElement | null>(null);
|
|
42
|
+
const cardRef = shallowRef<HTMLButtonElement | null>(null);
|
|
43
|
+
const cardHeight = shallowRef(0);
|
|
44
|
+
const handleStyle = computed(() => horizontal.value && props.data.kind === 'step'
|
|
45
|
+
? { top: `${(cardHeight.value || props.data.cardMinHeight) / 2}px` }
|
|
46
|
+
: undefined);
|
|
41
47
|
let resizeObserver: ResizeObserver | null = null;
|
|
42
48
|
|
|
43
49
|
const insertTitle = computed(() => {
|
|
@@ -72,6 +78,8 @@ onMounted(() => {
|
|
|
72
78
|
if (!rootRef.value || props.data.kind !== 'step') return;
|
|
73
79
|
resizeObserver = new ResizeObserver(([entry]) => {
|
|
74
80
|
if (!entry) return;
|
|
81
|
+
// 横向端点跟随卡片,展开的编辑区域不参与端点居中。
|
|
82
|
+
cardHeight.value = cardRef.value?.offsetHeight ?? 0;
|
|
75
83
|
emit('resize', {
|
|
76
84
|
id: props.nodeId,
|
|
77
85
|
height: entry.borderBoxSize[0]?.blockSize ?? rootRef.value!.offsetHeight,
|
|
@@ -96,10 +104,11 @@ onBeforeUnmount(() => {
|
|
|
96
104
|
@touchstart.stop
|
|
97
105
|
>
|
|
98
106
|
<Handle
|
|
99
|
-
id="
|
|
107
|
+
id="input"
|
|
100
108
|
type="target"
|
|
101
109
|
:position="horizontal ? Position.Left : Position.Top"
|
|
102
110
|
class="appium-flow-handle"
|
|
111
|
+
:style="handleStyle"
|
|
103
112
|
/>
|
|
104
113
|
|
|
105
114
|
<div v-if="data.kind === 'start'" class="appium-flow-start-card nodrag nopan">
|
|
@@ -158,7 +167,7 @@ onBeforeUnmount(() => {
|
|
|
158
167
|
:class="[
|
|
159
168
|
`appium-flow-step-shell--${data.flowKind}`,
|
|
160
169
|
{
|
|
161
|
-
'appium-flow-step-shell--expanded':
|
|
170
|
+
'appium-flow-step-shell--expanded': expanded,
|
|
162
171
|
'appium-flow-step-shell--selected': data.selected,
|
|
163
172
|
'appium-flow-step-shell--delete-selected': data.selected && data.deleteMode,
|
|
164
173
|
'appium-flow-step-shell--copying': data.copyMode,
|
|
@@ -167,6 +176,7 @@ onBeforeUnmount(() => {
|
|
|
167
176
|
]"
|
|
168
177
|
>
|
|
169
178
|
<button
|
|
179
|
+
ref="cardRef"
|
|
170
180
|
type="button"
|
|
171
181
|
class="appium-flow-step-card nodrag nopan"
|
|
172
182
|
:style="{ minHeight: `${data.cardMinHeight}px` }"
|
|
@@ -249,7 +259,7 @@ onBeforeUnmount(() => {
|
|
|
249
259
|
</span></el-tooltip>
|
|
250
260
|
</span>
|
|
251
261
|
<FlowStepEditor
|
|
252
|
-
v-if="!props.readonly &&
|
|
262
|
+
v-if="!props.readonly && expanded"
|
|
253
263
|
class="appium-flow-step-editor nodrag nopan"
|
|
254
264
|
:step="data.step"
|
|
255
265
|
:steps="steps"
|
|
@@ -260,10 +270,11 @@ onBeforeUnmount(() => {
|
|
|
260
270
|
</div>
|
|
261
271
|
|
|
262
272
|
<Handle
|
|
263
|
-
id="
|
|
273
|
+
id="output"
|
|
264
274
|
type="source"
|
|
265
275
|
:position="horizontal ? Position.Right : Position.Bottom"
|
|
266
276
|
class="appium-flow-handle"
|
|
277
|
+
:style="handleStyle"
|
|
267
278
|
/>
|
|
268
279
|
</div>
|
|
269
280
|
</template>
|
|
@@ -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[];
|