@midscene/ios 1.12.4-beta-20260903111111.0 → 1.12.4
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/dist/es/bin.mjs +104 -0
- package/dist/es/cli.mjs +105 -1
- package/dist/es/index.mjs +105 -1
- package/dist/es/test-runner.mjs +99 -0
- package/dist/lib/bin.js +1940 -1817
- package/dist/lib/cli.js +1920 -1797
- package/dist/lib/index.js +2091 -1949
- package/dist/lib/test-runner.js +145 -0
- package/dist/types/index.d.ts +50 -2
- package/dist/types/test-runner.d.ts +48 -0
- package/package.json +12 -7
- package/static/index.html +1 -1
- package/static/static/js/{226.9d4ca7e4.js → 415.bee53531.js} +55 -32
- package/static/static/js/415.bee53531.js.map +1 -0
- package/static/static/js/{index.426f1940.js → index.7d684402.js} +62 -100
- package/static/static/js/index.7d684402.js.map +1 -0
- package/static/static/js/226.9d4ca7e4.js.map +0 -1
- package/static/static/js/index.426f1940.js.map +0 -1
- /package/static/static/js/{226.9d4ca7e4.js.LICENSE.txt → 415.bee53531.js.LICENSE.txt} +0 -0
- /package/static/static/js/{index.426f1940.js.LICENSE.txt → index.7d684402.js.LICENSE.txt} +0 -0
package/dist/es/bin.mjs
CHANGED
|
@@ -12,6 +12,8 @@ import { createDefaultMobileActions, defineAction, resolveTextInputOptions, send
|
|
|
12
12
|
import { sleep } from "@midscene/core/utils";
|
|
13
13
|
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
14
14
|
import { WDAManager, WebDriverClient } from "@midscene/webdriver";
|
|
15
|
+
import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test-runner";
|
|
16
|
+
import { z as v4_z } from "zod/v4";
|
|
15
17
|
const defaultAppNameMapping = {
|
|
16
18
|
微信: 'com.tencent.xin',
|
|
17
19
|
企业微信: 'com.tencent.ww',
|
|
@@ -1724,6 +1726,102 @@ const createPlatformActions = (device)=>({
|
|
|
1724
1726
|
}
|
|
1725
1727
|
})
|
|
1726
1728
|
});
|
|
1729
|
+
const defineIOSAgentNode = createAgentTestRunnerNodeDefinition('an iOS Agent');
|
|
1730
|
+
const nonBlankText = (description)=>v4_z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
|
|
1731
|
+
const launchInputSchema = v4_z.strictObject({
|
|
1732
|
+
uri: nonBlankText('The app, URL, URI, or bundle identifier to launch.')
|
|
1733
|
+
});
|
|
1734
|
+
const terminateInputSchema = v4_z.strictObject({
|
|
1735
|
+
uri: nonBlankText('The bundle identifier or app name to terminate.')
|
|
1736
|
+
});
|
|
1737
|
+
const test_runner_nodes_WDA_HTTP_METHODS = [
|
|
1738
|
+
'GET',
|
|
1739
|
+
'POST',
|
|
1740
|
+
'DELETE',
|
|
1741
|
+
'PUT'
|
|
1742
|
+
];
|
|
1743
|
+
const wdaRequestInputSchema = v4_z.strictObject({
|
|
1744
|
+
method: v4_z["enum"](test_runner_nodes_WDA_HTTP_METHODS).describe('The WebDriverAgent HTTP method.'),
|
|
1745
|
+
endpoint: v4_z.string().regex(/^\/\S*$/, 'endpoint must start with / and contain no whitespace').describe('The WebDriverAgent API endpoint.'),
|
|
1746
|
+
data: v4_z.record(v4_z.string(), v4_z.unknown()).optional().describe('An optional JSON request body.')
|
|
1747
|
+
});
|
|
1748
|
+
const runWdaRequestInputSchema = v4_z.strictObject({
|
|
1749
|
+
request: wdaRequestInputSchema
|
|
1750
|
+
});
|
|
1751
|
+
const emptyInputSchema = v4_z.strictObject({});
|
|
1752
|
+
const launchNode = defineIOSAgentNode({
|
|
1753
|
+
method: 'launch',
|
|
1754
|
+
description: 'Launch an application through the current iOS Agent.',
|
|
1755
|
+
stringInputKey: 'uri',
|
|
1756
|
+
inputSchema: launchInputSchema,
|
|
1757
|
+
toArgs: (input)=>[
|
|
1758
|
+
input.uri
|
|
1759
|
+
],
|
|
1760
|
+
toResult: (_output, input)=>({
|
|
1761
|
+
summary: `Launched ${input.uri}`
|
|
1762
|
+
})
|
|
1763
|
+
});
|
|
1764
|
+
const terminateNode = defineIOSAgentNode({
|
|
1765
|
+
method: 'terminate',
|
|
1766
|
+
description: 'Terminate an application through the current iOS Agent.',
|
|
1767
|
+
stringInputKey: 'uri',
|
|
1768
|
+
inputSchema: terminateInputSchema,
|
|
1769
|
+
toArgs: (input)=>[
|
|
1770
|
+
input.uri
|
|
1771
|
+
],
|
|
1772
|
+
toResult: (_output, input)=>({
|
|
1773
|
+
summary: `Terminated ${input.uri}`
|
|
1774
|
+
})
|
|
1775
|
+
});
|
|
1776
|
+
const runWdaRequestNode = defineIOSAgentNode({
|
|
1777
|
+
method: 'runWdaRequest',
|
|
1778
|
+
title: 'Run a WebDriverAgent request',
|
|
1779
|
+
description: 'Execute a WebDriverAgent HTTP request through the current iOS Agent and return its JSON-serializable response.',
|
|
1780
|
+
stringInputKey: false,
|
|
1781
|
+
inputSchema: runWdaRequestInputSchema,
|
|
1782
|
+
toArgs (input, context) {
|
|
1783
|
+
context.signal.throwIfAborted();
|
|
1784
|
+
return [
|
|
1785
|
+
input.request
|
|
1786
|
+
];
|
|
1787
|
+
},
|
|
1788
|
+
toResult (response, input) {
|
|
1789
|
+
const summary = `Executed WDA ${input.request.method} ${input.request.endpoint}`;
|
|
1790
|
+
return void 0 === response ? {
|
|
1791
|
+
summary
|
|
1792
|
+
} : {
|
|
1793
|
+
summary,
|
|
1794
|
+
data: response
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
});
|
|
1798
|
+
const homeNode = defineIOSAgentNode({
|
|
1799
|
+
method: 'home',
|
|
1800
|
+
description: 'Trigger the iOS system home operation.',
|
|
1801
|
+
stringInputKey: false,
|
|
1802
|
+
inputSchema: emptyInputSchema,
|
|
1803
|
+
toArgs: ()=>[],
|
|
1804
|
+
toResult: ()=>({
|
|
1805
|
+
summary: 'Triggered iOS home'
|
|
1806
|
+
})
|
|
1807
|
+
});
|
|
1808
|
+
const appSwitcherNode = defineIOSAgentNode({
|
|
1809
|
+
method: 'appSwitcher',
|
|
1810
|
+
description: 'Trigger the iOS system app switcher operation.',
|
|
1811
|
+
stringInputKey: false,
|
|
1812
|
+
inputSchema: emptyInputSchema,
|
|
1813
|
+
toArgs: ()=>[],
|
|
1814
|
+
toResult: ()=>({
|
|
1815
|
+
summary: 'Triggered iOS appSwitcher'
|
|
1816
|
+
})
|
|
1817
|
+
});
|
|
1818
|
+
const iosAgentTestRunnerNodeDefinitions = [
|
|
1819
|
+
launchNode,
|
|
1820
|
+
terminateNode,
|
|
1821
|
+
runWdaRequestNode,
|
|
1822
|
+
homeNode,
|
|
1823
|
+
appSwitcherNode
|
|
1824
|
+
];
|
|
1727
1825
|
function agent_define_property(obj, key, value) {
|
|
1728
1826
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1729
1827
|
value: value,
|
|
@@ -1736,6 +1834,12 @@ function agent_define_property(obj, key, value) {
|
|
|
1736
1834
|
}
|
|
1737
1835
|
const debugAgent = getDebug('ios:agent');
|
|
1738
1836
|
class IOSAgent extends Agent {
|
|
1837
|
+
static getTestRunnerNodeDefinitions() {
|
|
1838
|
+
return [
|
|
1839
|
+
...Agent.getTestRunnerNodeDefinitions(),
|
|
1840
|
+
...iosAgentTestRunnerNodeDefinitions
|
|
1841
|
+
];
|
|
1842
|
+
}
|
|
1739
1843
|
async launch(uri) {
|
|
1740
1844
|
const action = this.wrapActionInActionSpace('Launch');
|
|
1741
1845
|
return action({
|
package/dist/es/cli.mjs
CHANGED
|
@@ -12,6 +12,8 @@ import { sleep } from "@midscene/core/utils";
|
|
|
12
12
|
import { DEFAULT_WDA_PORT } from "@midscene/shared/constants";
|
|
13
13
|
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
14
14
|
import { WDAManager, WebDriverClient } from "@midscene/webdriver";
|
|
15
|
+
import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test-runner";
|
|
16
|
+
import { z as v4_z } from "zod/v4";
|
|
15
17
|
const defaultAppNameMapping = {
|
|
16
18
|
微信: 'com.tencent.xin',
|
|
17
19
|
企业微信: 'com.tencent.ww',
|
|
@@ -1724,6 +1726,102 @@ const createPlatformActions = (device)=>({
|
|
|
1724
1726
|
}
|
|
1725
1727
|
})
|
|
1726
1728
|
});
|
|
1729
|
+
const defineIOSAgentNode = createAgentTestRunnerNodeDefinition('an iOS Agent');
|
|
1730
|
+
const nonBlankText = (description)=>v4_z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
|
|
1731
|
+
const launchInputSchema = v4_z.strictObject({
|
|
1732
|
+
uri: nonBlankText('The app, URL, URI, or bundle identifier to launch.')
|
|
1733
|
+
});
|
|
1734
|
+
const terminateInputSchema = v4_z.strictObject({
|
|
1735
|
+
uri: nonBlankText('The bundle identifier or app name to terminate.')
|
|
1736
|
+
});
|
|
1737
|
+
const test_runner_nodes_WDA_HTTP_METHODS = [
|
|
1738
|
+
'GET',
|
|
1739
|
+
'POST',
|
|
1740
|
+
'DELETE',
|
|
1741
|
+
'PUT'
|
|
1742
|
+
];
|
|
1743
|
+
const wdaRequestInputSchema = v4_z.strictObject({
|
|
1744
|
+
method: v4_z["enum"](test_runner_nodes_WDA_HTTP_METHODS).describe('The WebDriverAgent HTTP method.'),
|
|
1745
|
+
endpoint: v4_z.string().regex(/^\/\S*$/, 'endpoint must start with / and contain no whitespace').describe('The WebDriverAgent API endpoint.'),
|
|
1746
|
+
data: v4_z.record(v4_z.string(), v4_z.unknown()).optional().describe('An optional JSON request body.')
|
|
1747
|
+
});
|
|
1748
|
+
const runWdaRequestInputSchema = v4_z.strictObject({
|
|
1749
|
+
request: wdaRequestInputSchema
|
|
1750
|
+
});
|
|
1751
|
+
const emptyInputSchema = v4_z.strictObject({});
|
|
1752
|
+
const launchNode = defineIOSAgentNode({
|
|
1753
|
+
method: 'launch',
|
|
1754
|
+
description: 'Launch an application through the current iOS Agent.',
|
|
1755
|
+
stringInputKey: 'uri',
|
|
1756
|
+
inputSchema: launchInputSchema,
|
|
1757
|
+
toArgs: (input)=>[
|
|
1758
|
+
input.uri
|
|
1759
|
+
],
|
|
1760
|
+
toResult: (_output, input)=>({
|
|
1761
|
+
summary: `Launched ${input.uri}`
|
|
1762
|
+
})
|
|
1763
|
+
});
|
|
1764
|
+
const terminateNode = defineIOSAgentNode({
|
|
1765
|
+
method: 'terminate',
|
|
1766
|
+
description: 'Terminate an application through the current iOS Agent.',
|
|
1767
|
+
stringInputKey: 'uri',
|
|
1768
|
+
inputSchema: terminateInputSchema,
|
|
1769
|
+
toArgs: (input)=>[
|
|
1770
|
+
input.uri
|
|
1771
|
+
],
|
|
1772
|
+
toResult: (_output, input)=>({
|
|
1773
|
+
summary: `Terminated ${input.uri}`
|
|
1774
|
+
})
|
|
1775
|
+
});
|
|
1776
|
+
const runWdaRequestNode = defineIOSAgentNode({
|
|
1777
|
+
method: 'runWdaRequest',
|
|
1778
|
+
title: 'Run a WebDriverAgent request',
|
|
1779
|
+
description: 'Execute a WebDriverAgent HTTP request through the current iOS Agent and return its JSON-serializable response.',
|
|
1780
|
+
stringInputKey: false,
|
|
1781
|
+
inputSchema: runWdaRequestInputSchema,
|
|
1782
|
+
toArgs (input, context) {
|
|
1783
|
+
context.signal.throwIfAborted();
|
|
1784
|
+
return [
|
|
1785
|
+
input.request
|
|
1786
|
+
];
|
|
1787
|
+
},
|
|
1788
|
+
toResult (response, input) {
|
|
1789
|
+
const summary = `Executed WDA ${input.request.method} ${input.request.endpoint}`;
|
|
1790
|
+
return void 0 === response ? {
|
|
1791
|
+
summary
|
|
1792
|
+
} : {
|
|
1793
|
+
summary,
|
|
1794
|
+
data: response
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
});
|
|
1798
|
+
const homeNode = defineIOSAgentNode({
|
|
1799
|
+
method: 'home',
|
|
1800
|
+
description: 'Trigger the iOS system home operation.',
|
|
1801
|
+
stringInputKey: false,
|
|
1802
|
+
inputSchema: emptyInputSchema,
|
|
1803
|
+
toArgs: ()=>[],
|
|
1804
|
+
toResult: ()=>({
|
|
1805
|
+
summary: 'Triggered iOS home'
|
|
1806
|
+
})
|
|
1807
|
+
});
|
|
1808
|
+
const appSwitcherNode = defineIOSAgentNode({
|
|
1809
|
+
method: 'appSwitcher',
|
|
1810
|
+
description: 'Trigger the iOS system app switcher operation.',
|
|
1811
|
+
stringInputKey: false,
|
|
1812
|
+
inputSchema: emptyInputSchema,
|
|
1813
|
+
toArgs: ()=>[],
|
|
1814
|
+
toResult: ()=>({
|
|
1815
|
+
summary: 'Triggered iOS appSwitcher'
|
|
1816
|
+
})
|
|
1817
|
+
});
|
|
1818
|
+
const iosAgentTestRunnerNodeDefinitions = [
|
|
1819
|
+
launchNode,
|
|
1820
|
+
terminateNode,
|
|
1821
|
+
runWdaRequestNode,
|
|
1822
|
+
homeNode,
|
|
1823
|
+
appSwitcherNode
|
|
1824
|
+
];
|
|
1727
1825
|
function agent_define_property(obj, key, value) {
|
|
1728
1826
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1729
1827
|
value: value,
|
|
@@ -1736,6 +1834,12 @@ function agent_define_property(obj, key, value) {
|
|
|
1736
1834
|
}
|
|
1737
1835
|
const debugAgent = getDebug('ios:agent');
|
|
1738
1836
|
class IOSAgent extends Agent {
|
|
1837
|
+
static getTestRunnerNodeDefinitions() {
|
|
1838
|
+
return [
|
|
1839
|
+
...Agent.getTestRunnerNodeDefinitions(),
|
|
1840
|
+
...iosAgentTestRunnerNodeDefinitions
|
|
1841
|
+
];
|
|
1842
|
+
}
|
|
1739
1843
|
async launch(uri) {
|
|
1740
1844
|
const action = this.wrapActionInActionSpace('Launch');
|
|
1741
1845
|
return action({
|
|
@@ -1892,7 +1996,7 @@ class IOSMidsceneTools extends BaseMidsceneTools {
|
|
|
1892
1996
|
const tools = new IOSMidsceneTools();
|
|
1893
1997
|
runToolsCLI(tools, 'midscene-ios', {
|
|
1894
1998
|
stripPrefix: 'ios_',
|
|
1895
|
-
version: "1.12.4
|
|
1999
|
+
version: "1.12.4",
|
|
1896
2000
|
extraCommands: createReportCliCommands()
|
|
1897
2001
|
}).catch((e)=>{
|
|
1898
2002
|
process.exit(reportCLIError(e));
|
package/dist/es/index.mjs
CHANGED
|
@@ -9,6 +9,8 @@ import { mergeAndNormalizeAppNameMapping, normalizeForComparison } from "@midsce
|
|
|
9
9
|
import { WDAManager, WebDriverClient } from "@midscene/webdriver";
|
|
10
10
|
import { Agent } from "@midscene/core/agent";
|
|
11
11
|
import { MIDSCENE_IOS_DEVICE_CLASS_OVERRIDE, overrideAIConfig } from "@midscene/shared/env";
|
|
12
|
+
import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test-runner";
|
|
13
|
+
import { z as v4_z } from "zod/v4";
|
|
12
14
|
import { agentBehaviorInitArgShape, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/agent-tools/agent-behavior-init-args";
|
|
13
15
|
import { BaseMidsceneTools } from "@midscene/shared/agent-tools/base-tools";
|
|
14
16
|
import { exec } from "node:child_process";
|
|
@@ -1729,6 +1731,102 @@ const defaultAppNameMapping = {
|
|
|
1729
1731
|
Keynote: 'com.apple.Keynote',
|
|
1730
1732
|
'Keynote 讲演': 'com.apple.Keynote'
|
|
1731
1733
|
};
|
|
1734
|
+
const defineIOSAgentNode = createAgentTestRunnerNodeDefinition('an iOS Agent');
|
|
1735
|
+
const nonBlankText = (description)=>v4_z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
|
|
1736
|
+
const launchInputSchema = v4_z.strictObject({
|
|
1737
|
+
uri: nonBlankText('The app, URL, URI, or bundle identifier to launch.')
|
|
1738
|
+
});
|
|
1739
|
+
const terminateInputSchema = v4_z.strictObject({
|
|
1740
|
+
uri: nonBlankText('The bundle identifier or app name to terminate.')
|
|
1741
|
+
});
|
|
1742
|
+
const test_runner_nodes_WDA_HTTP_METHODS = [
|
|
1743
|
+
'GET',
|
|
1744
|
+
'POST',
|
|
1745
|
+
'DELETE',
|
|
1746
|
+
'PUT'
|
|
1747
|
+
];
|
|
1748
|
+
const wdaRequestInputSchema = v4_z.strictObject({
|
|
1749
|
+
method: v4_z["enum"](test_runner_nodes_WDA_HTTP_METHODS).describe('The WebDriverAgent HTTP method.'),
|
|
1750
|
+
endpoint: v4_z.string().regex(/^\/\S*$/, 'endpoint must start with / and contain no whitespace').describe('The WebDriverAgent API endpoint.'),
|
|
1751
|
+
data: v4_z.record(v4_z.string(), v4_z.unknown()).optional().describe('An optional JSON request body.')
|
|
1752
|
+
});
|
|
1753
|
+
const runWdaRequestInputSchema = v4_z.strictObject({
|
|
1754
|
+
request: wdaRequestInputSchema
|
|
1755
|
+
});
|
|
1756
|
+
const emptyInputSchema = v4_z.strictObject({});
|
|
1757
|
+
const launchNode = defineIOSAgentNode({
|
|
1758
|
+
method: 'launch',
|
|
1759
|
+
description: 'Launch an application through the current iOS Agent.',
|
|
1760
|
+
stringInputKey: 'uri',
|
|
1761
|
+
inputSchema: launchInputSchema,
|
|
1762
|
+
toArgs: (input)=>[
|
|
1763
|
+
input.uri
|
|
1764
|
+
],
|
|
1765
|
+
toResult: (_output, input)=>({
|
|
1766
|
+
summary: `Launched ${input.uri}`
|
|
1767
|
+
})
|
|
1768
|
+
});
|
|
1769
|
+
const terminateNode = defineIOSAgentNode({
|
|
1770
|
+
method: 'terminate',
|
|
1771
|
+
description: 'Terminate an application through the current iOS Agent.',
|
|
1772
|
+
stringInputKey: 'uri',
|
|
1773
|
+
inputSchema: terminateInputSchema,
|
|
1774
|
+
toArgs: (input)=>[
|
|
1775
|
+
input.uri
|
|
1776
|
+
],
|
|
1777
|
+
toResult: (_output, input)=>({
|
|
1778
|
+
summary: `Terminated ${input.uri}`
|
|
1779
|
+
})
|
|
1780
|
+
});
|
|
1781
|
+
const runWdaRequestNode = defineIOSAgentNode({
|
|
1782
|
+
method: 'runWdaRequest',
|
|
1783
|
+
title: 'Run a WebDriverAgent request',
|
|
1784
|
+
description: 'Execute a WebDriverAgent HTTP request through the current iOS Agent and return its JSON-serializable response.',
|
|
1785
|
+
stringInputKey: false,
|
|
1786
|
+
inputSchema: runWdaRequestInputSchema,
|
|
1787
|
+
toArgs (input, context) {
|
|
1788
|
+
context.signal.throwIfAborted();
|
|
1789
|
+
return [
|
|
1790
|
+
input.request
|
|
1791
|
+
];
|
|
1792
|
+
},
|
|
1793
|
+
toResult (response, input) {
|
|
1794
|
+
const summary = `Executed WDA ${input.request.method} ${input.request.endpoint}`;
|
|
1795
|
+
return void 0 === response ? {
|
|
1796
|
+
summary
|
|
1797
|
+
} : {
|
|
1798
|
+
summary,
|
|
1799
|
+
data: response
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
});
|
|
1803
|
+
const homeNode = defineIOSAgentNode({
|
|
1804
|
+
method: 'home',
|
|
1805
|
+
description: 'Trigger the iOS system home operation.',
|
|
1806
|
+
stringInputKey: false,
|
|
1807
|
+
inputSchema: emptyInputSchema,
|
|
1808
|
+
toArgs: ()=>[],
|
|
1809
|
+
toResult: ()=>({
|
|
1810
|
+
summary: 'Triggered iOS home'
|
|
1811
|
+
})
|
|
1812
|
+
});
|
|
1813
|
+
const appSwitcherNode = defineIOSAgentNode({
|
|
1814
|
+
method: 'appSwitcher',
|
|
1815
|
+
description: 'Trigger the iOS system app switcher operation.',
|
|
1816
|
+
stringInputKey: false,
|
|
1817
|
+
inputSchema: emptyInputSchema,
|
|
1818
|
+
toArgs: ()=>[],
|
|
1819
|
+
toResult: ()=>({
|
|
1820
|
+
summary: 'Triggered iOS appSwitcher'
|
|
1821
|
+
})
|
|
1822
|
+
});
|
|
1823
|
+
const iosAgentTestRunnerNodeDefinitions = [
|
|
1824
|
+
launchNode,
|
|
1825
|
+
terminateNode,
|
|
1826
|
+
runWdaRequestNode,
|
|
1827
|
+
homeNode,
|
|
1828
|
+
appSwitcherNode
|
|
1829
|
+
];
|
|
1732
1830
|
function agent_define_property(obj, key, value) {
|
|
1733
1831
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1734
1832
|
value: value,
|
|
@@ -1741,6 +1839,12 @@ function agent_define_property(obj, key, value) {
|
|
|
1741
1839
|
}
|
|
1742
1840
|
const debugAgent = getDebug('ios:agent');
|
|
1743
1841
|
class IOSAgent extends Agent {
|
|
1842
|
+
static getTestRunnerNodeDefinitions() {
|
|
1843
|
+
return [
|
|
1844
|
+
...Agent.getTestRunnerNodeDefinitions(),
|
|
1845
|
+
...iosAgentTestRunnerNodeDefinitions
|
|
1846
|
+
];
|
|
1847
|
+
}
|
|
1744
1848
|
async launch(uri) {
|
|
1745
1849
|
const action = this.wrapActionInActionSpace('Launch');
|
|
1746
1850
|
return action({
|
|
@@ -2055,4 +2159,4 @@ const iosPlaygroundPlatform = definePlaygroundPlatform({
|
|
|
2055
2159
|
};
|
|
2056
2160
|
}
|
|
2057
2161
|
});
|
|
2058
|
-
export { IOSAgent, IOSDevice, IOSMidsceneTools, IOSWebDriverClient, agentFromWebDriverAgent, checkIOSEnvironment, iosPlaygroundPlatform, overrideAIConfig };
|
|
2162
|
+
export { IOSAgent, IOSDevice, IOSMidsceneTools, IOSWebDriverClient, agentFromWebDriverAgent, checkIOSEnvironment, iosAgentTestRunnerNodeDefinitions, iosPlaygroundPlatform, launchInputSchema, overrideAIConfig, runWdaRequestInputSchema, terminateInputSchema, wdaRequestInputSchema };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test-runner";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
const defineIOSAgentNode = createAgentTestRunnerNodeDefinition('an iOS Agent');
|
|
4
|
+
const nonBlankText = (description)=>z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
|
|
5
|
+
const launchInputSchema = z.strictObject({
|
|
6
|
+
uri: nonBlankText('The app, URL, URI, or bundle identifier to launch.')
|
|
7
|
+
});
|
|
8
|
+
const terminateInputSchema = z.strictObject({
|
|
9
|
+
uri: nonBlankText('The bundle identifier or app name to terminate.')
|
|
10
|
+
});
|
|
11
|
+
const WDA_HTTP_METHODS = [
|
|
12
|
+
'GET',
|
|
13
|
+
'POST',
|
|
14
|
+
'DELETE',
|
|
15
|
+
'PUT'
|
|
16
|
+
];
|
|
17
|
+
const wdaRequestInputSchema = z.strictObject({
|
|
18
|
+
method: z["enum"](WDA_HTTP_METHODS).describe('The WebDriverAgent HTTP method.'),
|
|
19
|
+
endpoint: z.string().regex(/^\/\S*$/, 'endpoint must start with / and contain no whitespace').describe('The WebDriverAgent API endpoint.'),
|
|
20
|
+
data: z.record(z.string(), z.unknown()).optional().describe('An optional JSON request body.')
|
|
21
|
+
});
|
|
22
|
+
const runWdaRequestInputSchema = z.strictObject({
|
|
23
|
+
request: wdaRequestInputSchema
|
|
24
|
+
});
|
|
25
|
+
const emptyInputSchema = z.strictObject({});
|
|
26
|
+
const launchNode = defineIOSAgentNode({
|
|
27
|
+
method: 'launch',
|
|
28
|
+
description: 'Launch an application through the current iOS Agent.',
|
|
29
|
+
stringInputKey: 'uri',
|
|
30
|
+
inputSchema: launchInputSchema,
|
|
31
|
+
toArgs: (input)=>[
|
|
32
|
+
input.uri
|
|
33
|
+
],
|
|
34
|
+
toResult: (_output, input)=>({
|
|
35
|
+
summary: `Launched ${input.uri}`
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
const terminateNode = defineIOSAgentNode({
|
|
39
|
+
method: 'terminate',
|
|
40
|
+
description: 'Terminate an application through the current iOS Agent.',
|
|
41
|
+
stringInputKey: 'uri',
|
|
42
|
+
inputSchema: terminateInputSchema,
|
|
43
|
+
toArgs: (input)=>[
|
|
44
|
+
input.uri
|
|
45
|
+
],
|
|
46
|
+
toResult: (_output, input)=>({
|
|
47
|
+
summary: `Terminated ${input.uri}`
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
const runWdaRequestNode = defineIOSAgentNode({
|
|
51
|
+
method: 'runWdaRequest',
|
|
52
|
+
title: 'Run a WebDriverAgent request',
|
|
53
|
+
description: 'Execute a WebDriverAgent HTTP request through the current iOS Agent and return its JSON-serializable response.',
|
|
54
|
+
stringInputKey: false,
|
|
55
|
+
inputSchema: runWdaRequestInputSchema,
|
|
56
|
+
toArgs (input, context) {
|
|
57
|
+
context.signal.throwIfAborted();
|
|
58
|
+
return [
|
|
59
|
+
input.request
|
|
60
|
+
];
|
|
61
|
+
},
|
|
62
|
+
toResult (response, input) {
|
|
63
|
+
const summary = `Executed WDA ${input.request.method} ${input.request.endpoint}`;
|
|
64
|
+
return void 0 === response ? {
|
|
65
|
+
summary
|
|
66
|
+
} : {
|
|
67
|
+
summary,
|
|
68
|
+
data: response
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const homeNode = defineIOSAgentNode({
|
|
73
|
+
method: 'home',
|
|
74
|
+
description: 'Trigger the iOS system home operation.',
|
|
75
|
+
stringInputKey: false,
|
|
76
|
+
inputSchema: emptyInputSchema,
|
|
77
|
+
toArgs: ()=>[],
|
|
78
|
+
toResult: ()=>({
|
|
79
|
+
summary: 'Triggered iOS home'
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
const appSwitcherNode = defineIOSAgentNode({
|
|
83
|
+
method: 'appSwitcher',
|
|
84
|
+
description: 'Trigger the iOS system app switcher operation.',
|
|
85
|
+
stringInputKey: false,
|
|
86
|
+
inputSchema: emptyInputSchema,
|
|
87
|
+
toArgs: ()=>[],
|
|
88
|
+
toResult: ()=>({
|
|
89
|
+
summary: 'Triggered iOS appSwitcher'
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
const iosAgentTestRunnerNodeDefinitions = [
|
|
93
|
+
launchNode,
|
|
94
|
+
terminateNode,
|
|
95
|
+
runWdaRequestNode,
|
|
96
|
+
homeNode,
|
|
97
|
+
appSwitcherNode
|
|
98
|
+
];
|
|
99
|
+
export { iosAgentTestRunnerNodeDefinitions, launchInputSchema, runWdaRequestInputSchema, terminateInputSchema, wdaRequestInputSchema };
|