@midscene/ios 0.30.6-beta-20251022061854.0 → 0.30.6-beta-20251022061949.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/bin.mjs +83 -65
- package/dist/es/index.mjs +12 -55
- package/dist/lib/bin.js +83 -65
- package/dist/lib/index.js +12 -55
- package/package.json +5 -5
- package/static/index.html +1 -1
- package/static/static/js/{index.694f8c4a.js → index.5c3c93e4.js} +3 -3
- package/static/static/js/{index.694f8c4a.js.map → index.5c3c93e4.js.map} +1 -1
- /package/static/static/js/{index.694f8c4a.js.LICENSE.txt → index.5c3c93e4.js.LICENSE.txt} +0 -0
package/dist/es/bin.mjs
CHANGED
|
@@ -11540,6 +11540,24 @@ class PlaygroundServer {
|
|
|
11540
11540
|
writeFileSync(tmpFile, context);
|
|
11541
11541
|
return tmpFile;
|
|
11542
11542
|
}
|
|
11543
|
+
async recreateAgent() {
|
|
11544
|
+
if (!this.pageFactory || !this.agentFactory) return void console.warn('Cannot recreate agent: factory functions not provided. Agent recreation is only available when using factory mode.');
|
|
11545
|
+
console.log('Recreating agent to cancel current task...');
|
|
11546
|
+
try {
|
|
11547
|
+
if (this.agent && 'function' == typeof this.agent.destroy) await this.agent.destroy();
|
|
11548
|
+
if (this.page && 'function' == typeof this.page.destroy) await this.page.destroy();
|
|
11549
|
+
} catch (error) {
|
|
11550
|
+
console.warn('Failed to destroy old agent/page:', error);
|
|
11551
|
+
}
|
|
11552
|
+
try {
|
|
11553
|
+
this.page = await this.pageFactory();
|
|
11554
|
+
this.agent = this.agentFactory(this.page);
|
|
11555
|
+
console.log('Agent recreated successfully');
|
|
11556
|
+
} catch (error) {
|
|
11557
|
+
console.error('Failed to recreate agent:', error);
|
|
11558
|
+
throw error;
|
|
11559
|
+
}
|
|
11560
|
+
}
|
|
11543
11561
|
setupRoutes() {
|
|
11544
11562
|
this._app.get('/status', async (req, res)=>{
|
|
11545
11563
|
res.send({
|
|
@@ -11616,7 +11634,12 @@ class PlaygroundServer {
|
|
|
11616
11634
|
if (!type) return res.status(400).json({
|
|
11617
11635
|
error: 'type is required'
|
|
11618
11636
|
});
|
|
11637
|
+
if (this.currentTaskId) return res.status(409).json({
|
|
11638
|
+
error: 'Another task is already running',
|
|
11639
|
+
currentTaskId: this.currentTaskId
|
|
11640
|
+
});
|
|
11619
11641
|
if (requestId) {
|
|
11642
|
+
this.currentTaskId = requestId;
|
|
11620
11643
|
this.taskProgressTips[requestId] = '';
|
|
11621
11644
|
this.agent.onTaskStartTip = (tip)=>{
|
|
11622
11645
|
this.taskProgressTips[requestId] = tip;
|
|
@@ -11658,7 +11681,10 @@ class PlaygroundServer {
|
|
|
11658
11681
|
const timeCost = Date.now() - startTime;
|
|
11659
11682
|
if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
|
|
11660
11683
|
else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
|
|
11661
|
-
if (requestId)
|
|
11684
|
+
if (requestId) {
|
|
11685
|
+
delete this.taskProgressTips[requestId];
|
|
11686
|
+
if (this.currentTaskId === requestId) this.currentTaskId = null;
|
|
11687
|
+
}
|
|
11662
11688
|
});
|
|
11663
11689
|
this._app.post('/cancel/:requestId', async (req, res)=>{
|
|
11664
11690
|
const { requestId } = req.params;
|
|
@@ -11666,9 +11692,17 @@ class PlaygroundServer {
|
|
|
11666
11692
|
error: 'requestId is required'
|
|
11667
11693
|
});
|
|
11668
11694
|
try {
|
|
11669
|
-
if (this.
|
|
11695
|
+
if (this.currentTaskId !== requestId) return res.json({
|
|
11696
|
+
status: 'not_found',
|
|
11697
|
+
message: 'Task not found or already completed'
|
|
11698
|
+
});
|
|
11699
|
+
console.log(`Cancelling task: ${requestId}`);
|
|
11700
|
+
await this.recreateAgent();
|
|
11701
|
+
delete this.taskProgressTips[requestId];
|
|
11702
|
+
this.currentTaskId = null;
|
|
11670
11703
|
res.json({
|
|
11671
|
-
status: 'cancelled'
|
|
11704
|
+
status: 'cancelled',
|
|
11705
|
+
message: 'Task cancelled successfully by recreating agent'
|
|
11672
11706
|
});
|
|
11673
11707
|
} catch (error) {
|
|
11674
11708
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
@@ -11768,6 +11802,12 @@ class PlaygroundServer {
|
|
|
11768
11802
|
}
|
|
11769
11803
|
}
|
|
11770
11804
|
async launch(port) {
|
|
11805
|
+
if (this.pageFactory && this.agentFactory) {
|
|
11806
|
+
console.log('Initializing page and agent from factory functions...');
|
|
11807
|
+
this.page = await this.pageFactory();
|
|
11808
|
+
this.agent = this.agentFactory(this.page);
|
|
11809
|
+
console.log('Page and agent initialized successfully');
|
|
11810
|
+
}
|
|
11771
11811
|
this.initializeApp();
|
|
11772
11812
|
this.port = port || defaultPort;
|
|
11773
11813
|
return new Promise((resolve)=>{
|
|
@@ -11807,13 +11847,28 @@ class PlaygroundServer {
|
|
|
11807
11847
|
_define_property(this, "taskProgressTips", void 0);
|
|
11808
11848
|
_define_property(this, "id", void 0);
|
|
11809
11849
|
_define_property(this, "_initialized", false);
|
|
11850
|
+
_define_property(this, "pageFactory", void 0);
|
|
11851
|
+
_define_property(this, "agentFactory", void 0);
|
|
11852
|
+
_define_property(this, "currentTaskId", null);
|
|
11810
11853
|
this._app = express_default()();
|
|
11811
11854
|
this.tmpDir = getTmpDir();
|
|
11812
|
-
this.page = page;
|
|
11813
|
-
this.agent = agent;
|
|
11814
11855
|
this.staticPath = staticPath;
|
|
11815
11856
|
this.taskProgressTips = {};
|
|
11816
11857
|
this.id = id || utils_uuid();
|
|
11858
|
+
if ('function' == typeof page) {
|
|
11859
|
+
this.pageFactory = page;
|
|
11860
|
+
this.page = null;
|
|
11861
|
+
} else {
|
|
11862
|
+
this.page = page;
|
|
11863
|
+
this.pageFactory = null;
|
|
11864
|
+
}
|
|
11865
|
+
if ('function' == typeof agent) {
|
|
11866
|
+
this.agentFactory = agent;
|
|
11867
|
+
this.agent = null;
|
|
11868
|
+
} else {
|
|
11869
|
+
this.agent = agent;
|
|
11870
|
+
this.agentFactory = null;
|
|
11871
|
+
}
|
|
11817
11872
|
}
|
|
11818
11873
|
}
|
|
11819
11874
|
__webpack_require__("../../node_modules/.pnpm/cors@2.8.5/node_modules/cors/lib/index.js");
|
|
@@ -12003,60 +12058,17 @@ class IOSWebDriverClient extends WebDriverClient {
|
|
|
12003
12058
|
async swipe(fromX, fromY, toX, toY, duration = 500) {
|
|
12004
12059
|
this.ensureSession();
|
|
12005
12060
|
try {
|
|
12006
|
-
|
|
12007
|
-
|
|
12008
|
-
|
|
12009
|
-
|
|
12010
|
-
|
|
12011
|
-
|
|
12012
|
-
|
|
12013
|
-
|
|
12014
|
-
actions: [
|
|
12015
|
-
{
|
|
12016
|
-
type: 'pointerMove',
|
|
12017
|
-
duration: 0,
|
|
12018
|
-
x: fromX,
|
|
12019
|
-
y: fromY
|
|
12020
|
-
},
|
|
12021
|
-
{
|
|
12022
|
-
type: 'pointerDown',
|
|
12023
|
-
button: 0
|
|
12024
|
-
},
|
|
12025
|
-
{
|
|
12026
|
-
type: 'pause',
|
|
12027
|
-
duration: 100
|
|
12028
|
-
},
|
|
12029
|
-
{
|
|
12030
|
-
type: 'pointerMove',
|
|
12031
|
-
duration,
|
|
12032
|
-
x: toX,
|
|
12033
|
-
y: toY
|
|
12034
|
-
},
|
|
12035
|
-
{
|
|
12036
|
-
type: 'pointerUp',
|
|
12037
|
-
button: 0
|
|
12038
|
-
}
|
|
12039
|
-
]
|
|
12040
|
-
}
|
|
12041
|
-
]
|
|
12042
|
-
};
|
|
12043
|
-
await this.makeRequest('POST', `/session/${this.sessionId}/actions`, actions);
|
|
12044
|
-
debugIOS(`Swiped using W3C Actions from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
12061
|
+
await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
|
|
12062
|
+
fromX,
|
|
12063
|
+
fromY,
|
|
12064
|
+
toX,
|
|
12065
|
+
toY,
|
|
12066
|
+
duration: duration / 1000
|
|
12067
|
+
});
|
|
12068
|
+
debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
12045
12069
|
} catch (error) {
|
|
12046
|
-
debugIOS(`
|
|
12047
|
-
|
|
12048
|
-
await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
|
|
12049
|
-
fromX,
|
|
12050
|
-
fromY,
|
|
12051
|
-
toX,
|
|
12052
|
-
toY,
|
|
12053
|
-
duration: duration / 1000
|
|
12054
|
-
});
|
|
12055
|
-
debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
12056
|
-
} catch (error2) {
|
|
12057
|
-
debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error2}`);
|
|
12058
|
-
throw new Error(`Failed to swipe: ${error2}`);
|
|
12059
|
-
}
|
|
12070
|
+
debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error}`);
|
|
12071
|
+
throw new Error(`Failed to swipe: ${error}`);
|
|
12060
12072
|
}
|
|
12061
12073
|
}
|
|
12062
12074
|
async longPress(x, y, duration = 1000) {
|
|
@@ -12429,7 +12441,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
12429
12441
|
x: width / 2,
|
|
12430
12442
|
y: height / 2
|
|
12431
12443
|
};
|
|
12432
|
-
const scrollDistance = distance ||
|
|
12444
|
+
const scrollDistance = distance || width / 3;
|
|
12433
12445
|
await this.swipe(start.x, start.y, start.x + scrollDistance, start.y);
|
|
12434
12446
|
}
|
|
12435
12447
|
async scrollRight(distance, startPoint) {
|
|
@@ -12441,7 +12453,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
12441
12453
|
x: width / 2,
|
|
12442
12454
|
y: height / 2
|
|
12443
12455
|
};
|
|
12444
|
-
const scrollDistance = distance ||
|
|
12456
|
+
const scrollDistance = distance || width / 3;
|
|
12445
12457
|
await this.swipe(start.x, start.y, start.x - scrollDistance, start.y);
|
|
12446
12458
|
}
|
|
12447
12459
|
async scrollUntilTop(startPoint) {
|
|
@@ -12759,17 +12771,14 @@ const main = async ()=>{
|
|
|
12759
12771
|
host: 'localhost',
|
|
12760
12772
|
port: DEFAULT_WDA_PORT
|
|
12761
12773
|
};
|
|
12762
|
-
let device;
|
|
12763
|
-
let agent;
|
|
12764
12774
|
let connected = false;
|
|
12765
12775
|
while(!connected)try {
|
|
12766
|
-
device = new device_IOSDevice({
|
|
12776
|
+
const device = new device_IOSDevice({
|
|
12767
12777
|
wdaHost: wdaConfig.host,
|
|
12768
12778
|
wdaPort: wdaConfig.port
|
|
12769
12779
|
});
|
|
12770
12780
|
console.log(`\u{1F50C} Connecting to WebDriverAgent at ${wdaConfig.host}:${wdaConfig.port}...`);
|
|
12771
12781
|
await device.connect();
|
|
12772
|
-
agent = new IOSAgent(device);
|
|
12773
12782
|
connected = true;
|
|
12774
12783
|
const deviceInfo = await device.getConnectedDeviceInfo();
|
|
12775
12784
|
console.log("\u2705 Connected to WebDriverAgent successfully!");
|
|
@@ -12821,7 +12830,16 @@ const main = async ()=>{
|
|
|
12821
12830
|
`);
|
|
12822
12831
|
else if ('configure' === action) wdaConfig = await configureWebDriverAgent();
|
|
12823
12832
|
}
|
|
12824
|
-
const
|
|
12833
|
+
const deviceFactory = async ()=>{
|
|
12834
|
+
const newDevice = new device_IOSDevice({
|
|
12835
|
+
wdaHost: wdaConfig.host,
|
|
12836
|
+
wdaPort: wdaConfig.port
|
|
12837
|
+
});
|
|
12838
|
+
await newDevice.connect();
|
|
12839
|
+
return newDevice;
|
|
12840
|
+
};
|
|
12841
|
+
const agentFactory = (device)=>new IOSAgent(device);
|
|
12842
|
+
const playgroundServer = new PlaygroundServer(deviceFactory, agentFactory, staticDir);
|
|
12825
12843
|
console.log("\uD83D\uDE80 Starting server...");
|
|
12826
12844
|
const availablePlaygroundPort = await findAvailablePort(constants_PLAYGROUND_SERVER_PORT);
|
|
12827
12845
|
if (availablePlaygroundPort !== constants_PLAYGROUND_SERVER_PORT) console.log(`\u{26A0}\u{FE0F} Port ${constants_PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
|
package/dist/es/index.mjs
CHANGED
|
@@ -197,60 +197,17 @@ class IOSWebDriverClient extends WebDriverClient {
|
|
|
197
197
|
async swipe(fromX, fromY, toX, toY, duration = 500) {
|
|
198
198
|
this.ensureSession();
|
|
199
199
|
try {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
actions: [
|
|
209
|
-
{
|
|
210
|
-
type: 'pointerMove',
|
|
211
|
-
duration: 0,
|
|
212
|
-
x: fromX,
|
|
213
|
-
y: fromY
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
type: 'pointerDown',
|
|
217
|
-
button: 0
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
type: 'pause',
|
|
221
|
-
duration: 100
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
type: 'pointerMove',
|
|
225
|
-
duration,
|
|
226
|
-
x: toX,
|
|
227
|
-
y: toY
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
type: 'pointerUp',
|
|
231
|
-
button: 0
|
|
232
|
-
}
|
|
233
|
-
]
|
|
234
|
-
}
|
|
235
|
-
]
|
|
236
|
-
};
|
|
237
|
-
await this.makeRequest('POST', `/session/${this.sessionId}/actions`, actions);
|
|
238
|
-
debugIOS(`Swiped using W3C Actions from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
200
|
+
await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
|
|
201
|
+
fromX,
|
|
202
|
+
fromY,
|
|
203
|
+
toX,
|
|
204
|
+
toY,
|
|
205
|
+
duration: duration / 1000
|
|
206
|
+
});
|
|
207
|
+
debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
239
208
|
} catch (error) {
|
|
240
|
-
debugIOS(`
|
|
241
|
-
|
|
242
|
-
await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
|
|
243
|
-
fromX,
|
|
244
|
-
fromY,
|
|
245
|
-
toX,
|
|
246
|
-
toY,
|
|
247
|
-
duration: duration / 1000
|
|
248
|
-
});
|
|
249
|
-
debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
250
|
-
} catch (error2) {
|
|
251
|
-
debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error2}`);
|
|
252
|
-
throw new Error(`Failed to swipe: ${error2}`);
|
|
253
|
-
}
|
|
209
|
+
debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error}`);
|
|
210
|
+
throw new Error(`Failed to swipe: ${error}`);
|
|
254
211
|
}
|
|
255
212
|
}
|
|
256
213
|
async longPress(x, y, duration = 1000) {
|
|
@@ -623,7 +580,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
623
580
|
x: width / 2,
|
|
624
581
|
y: height / 2
|
|
625
582
|
};
|
|
626
|
-
const scrollDistance = distance ||
|
|
583
|
+
const scrollDistance = distance || width / 3;
|
|
627
584
|
await this.swipe(start.x, start.y, start.x + scrollDistance, start.y);
|
|
628
585
|
}
|
|
629
586
|
async scrollRight(distance, startPoint) {
|
|
@@ -635,7 +592,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
635
592
|
x: width / 2,
|
|
636
593
|
y: height / 2
|
|
637
594
|
};
|
|
638
|
-
const scrollDistance = distance ||
|
|
595
|
+
const scrollDistance = distance || width / 3;
|
|
639
596
|
await this.swipe(start.x, start.y, start.x - scrollDistance, start.y);
|
|
640
597
|
}
|
|
641
598
|
async scrollUntilTop(startPoint) {
|
package/dist/lib/bin.js
CHANGED
|
@@ -11669,6 +11669,24 @@ var __webpack_exports__ = {};
|
|
|
11669
11669
|
(0, external_node_fs_namespaceObject.writeFileSync)(tmpFile, context);
|
|
11670
11670
|
return tmpFile;
|
|
11671
11671
|
}
|
|
11672
|
+
async recreateAgent() {
|
|
11673
|
+
if (!this.pageFactory || !this.agentFactory) return void console.warn('Cannot recreate agent: factory functions not provided. Agent recreation is only available when using factory mode.');
|
|
11674
|
+
console.log('Recreating agent to cancel current task...');
|
|
11675
|
+
try {
|
|
11676
|
+
if (this.agent && 'function' == typeof this.agent.destroy) await this.agent.destroy();
|
|
11677
|
+
if (this.page && 'function' == typeof this.page.destroy) await this.page.destroy();
|
|
11678
|
+
} catch (error) {
|
|
11679
|
+
console.warn('Failed to destroy old agent/page:', error);
|
|
11680
|
+
}
|
|
11681
|
+
try {
|
|
11682
|
+
this.page = await this.pageFactory();
|
|
11683
|
+
this.agent = this.agentFactory(this.page);
|
|
11684
|
+
console.log('Agent recreated successfully');
|
|
11685
|
+
} catch (error) {
|
|
11686
|
+
console.error('Failed to recreate agent:', error);
|
|
11687
|
+
throw error;
|
|
11688
|
+
}
|
|
11689
|
+
}
|
|
11672
11690
|
setupRoutes() {
|
|
11673
11691
|
this._app.get('/status', async (req, res)=>{
|
|
11674
11692
|
res.send({
|
|
@@ -11745,7 +11763,12 @@ var __webpack_exports__ = {};
|
|
|
11745
11763
|
if (!type) return res.status(400).json({
|
|
11746
11764
|
error: 'type is required'
|
|
11747
11765
|
});
|
|
11766
|
+
if (this.currentTaskId) return res.status(409).json({
|
|
11767
|
+
error: 'Another task is already running',
|
|
11768
|
+
currentTaskId: this.currentTaskId
|
|
11769
|
+
});
|
|
11748
11770
|
if (requestId) {
|
|
11771
|
+
this.currentTaskId = requestId;
|
|
11749
11772
|
this.taskProgressTips[requestId] = '';
|
|
11750
11773
|
this.agent.onTaskStartTip = (tip)=>{
|
|
11751
11774
|
this.taskProgressTips[requestId] = tip;
|
|
@@ -11787,7 +11810,10 @@ var __webpack_exports__ = {};
|
|
|
11787
11810
|
const timeCost = Date.now() - startTime;
|
|
11788
11811
|
if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
|
|
11789
11812
|
else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
|
|
11790
|
-
if (requestId)
|
|
11813
|
+
if (requestId) {
|
|
11814
|
+
delete this.taskProgressTips[requestId];
|
|
11815
|
+
if (this.currentTaskId === requestId) this.currentTaskId = null;
|
|
11816
|
+
}
|
|
11791
11817
|
});
|
|
11792
11818
|
this._app.post('/cancel/:requestId', async (req, res)=>{
|
|
11793
11819
|
const { requestId } = req.params;
|
|
@@ -11795,9 +11821,17 @@ var __webpack_exports__ = {};
|
|
|
11795
11821
|
error: 'requestId is required'
|
|
11796
11822
|
});
|
|
11797
11823
|
try {
|
|
11798
|
-
if (this.
|
|
11824
|
+
if (this.currentTaskId !== requestId) return res.json({
|
|
11825
|
+
status: 'not_found',
|
|
11826
|
+
message: 'Task not found or already completed'
|
|
11827
|
+
});
|
|
11828
|
+
console.log(`Cancelling task: ${requestId}`);
|
|
11829
|
+
await this.recreateAgent();
|
|
11830
|
+
delete this.taskProgressTips[requestId];
|
|
11831
|
+
this.currentTaskId = null;
|
|
11799
11832
|
res.json({
|
|
11800
|
-
status: 'cancelled'
|
|
11833
|
+
status: 'cancelled',
|
|
11834
|
+
message: 'Task cancelled successfully by recreating agent'
|
|
11801
11835
|
});
|
|
11802
11836
|
} catch (error) {
|
|
11803
11837
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
@@ -11897,6 +11931,12 @@ var __webpack_exports__ = {};
|
|
|
11897
11931
|
}
|
|
11898
11932
|
}
|
|
11899
11933
|
async launch(port) {
|
|
11934
|
+
if (this.pageFactory && this.agentFactory) {
|
|
11935
|
+
console.log('Initializing page and agent from factory functions...');
|
|
11936
|
+
this.page = await this.pageFactory();
|
|
11937
|
+
this.agent = this.agentFactory(this.page);
|
|
11938
|
+
console.log('Page and agent initialized successfully');
|
|
11939
|
+
}
|
|
11900
11940
|
this.initializeApp();
|
|
11901
11941
|
this.port = port || defaultPort;
|
|
11902
11942
|
return new Promise((resolve)=>{
|
|
@@ -11936,13 +11976,28 @@ var __webpack_exports__ = {};
|
|
|
11936
11976
|
_define_property(this, "taskProgressTips", void 0);
|
|
11937
11977
|
_define_property(this, "id", void 0);
|
|
11938
11978
|
_define_property(this, "_initialized", false);
|
|
11979
|
+
_define_property(this, "pageFactory", void 0);
|
|
11980
|
+
_define_property(this, "agentFactory", void 0);
|
|
11981
|
+
_define_property(this, "currentTaskId", null);
|
|
11939
11982
|
this._app = express_default()();
|
|
11940
11983
|
this.tmpDir = (0, utils_namespaceObject.getTmpDir)();
|
|
11941
|
-
this.page = page;
|
|
11942
|
-
this.agent = agent;
|
|
11943
11984
|
this.staticPath = staticPath;
|
|
11944
11985
|
this.taskProgressTips = {};
|
|
11945
11986
|
this.id = id || (0, shared_utils_namespaceObject.uuid)();
|
|
11987
|
+
if ('function' == typeof page) {
|
|
11988
|
+
this.pageFactory = page;
|
|
11989
|
+
this.page = null;
|
|
11990
|
+
} else {
|
|
11991
|
+
this.page = page;
|
|
11992
|
+
this.pageFactory = null;
|
|
11993
|
+
}
|
|
11994
|
+
if ('function' == typeof agent) {
|
|
11995
|
+
this.agentFactory = agent;
|
|
11996
|
+
this.agent = null;
|
|
11997
|
+
} else {
|
|
11998
|
+
this.agent = agent;
|
|
11999
|
+
this.agentFactory = null;
|
|
12000
|
+
}
|
|
11946
12001
|
}
|
|
11947
12002
|
}
|
|
11948
12003
|
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
@@ -12141,60 +12196,17 @@ var __webpack_exports__ = {};
|
|
|
12141
12196
|
async swipe(fromX, fromY, toX, toY, duration = 500) {
|
|
12142
12197
|
this.ensureSession();
|
|
12143
12198
|
try {
|
|
12144
|
-
|
|
12145
|
-
|
|
12146
|
-
|
|
12147
|
-
|
|
12148
|
-
|
|
12149
|
-
|
|
12150
|
-
|
|
12151
|
-
|
|
12152
|
-
actions: [
|
|
12153
|
-
{
|
|
12154
|
-
type: 'pointerMove',
|
|
12155
|
-
duration: 0,
|
|
12156
|
-
x: fromX,
|
|
12157
|
-
y: fromY
|
|
12158
|
-
},
|
|
12159
|
-
{
|
|
12160
|
-
type: 'pointerDown',
|
|
12161
|
-
button: 0
|
|
12162
|
-
},
|
|
12163
|
-
{
|
|
12164
|
-
type: 'pause',
|
|
12165
|
-
duration: 100
|
|
12166
|
-
},
|
|
12167
|
-
{
|
|
12168
|
-
type: 'pointerMove',
|
|
12169
|
-
duration,
|
|
12170
|
-
x: toX,
|
|
12171
|
-
y: toY
|
|
12172
|
-
},
|
|
12173
|
-
{
|
|
12174
|
-
type: 'pointerUp',
|
|
12175
|
-
button: 0
|
|
12176
|
-
}
|
|
12177
|
-
]
|
|
12178
|
-
}
|
|
12179
|
-
]
|
|
12180
|
-
};
|
|
12181
|
-
await this.makeRequest('POST', `/session/${this.sessionId}/actions`, actions);
|
|
12182
|
-
debugIOS(`Swiped using W3C Actions from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
12199
|
+
await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
|
|
12200
|
+
fromX,
|
|
12201
|
+
fromY,
|
|
12202
|
+
toX,
|
|
12203
|
+
toY,
|
|
12204
|
+
duration: duration / 1000
|
|
12205
|
+
});
|
|
12206
|
+
debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
12183
12207
|
} catch (error) {
|
|
12184
|
-
debugIOS(`
|
|
12185
|
-
|
|
12186
|
-
await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
|
|
12187
|
-
fromX,
|
|
12188
|
-
fromY,
|
|
12189
|
-
toX,
|
|
12190
|
-
toY,
|
|
12191
|
-
duration: duration / 1000
|
|
12192
|
-
});
|
|
12193
|
-
debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
12194
|
-
} catch (error2) {
|
|
12195
|
-
debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error2}`);
|
|
12196
|
-
throw new Error(`Failed to swipe: ${error2}`);
|
|
12197
|
-
}
|
|
12208
|
+
debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error}`);
|
|
12209
|
+
throw new Error(`Failed to swipe: ${error}`);
|
|
12198
12210
|
}
|
|
12199
12211
|
}
|
|
12200
12212
|
async longPress(x, y, duration = 1000) {
|
|
@@ -12567,7 +12579,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
12567
12579
|
x: width / 2,
|
|
12568
12580
|
y: height / 2
|
|
12569
12581
|
};
|
|
12570
|
-
const scrollDistance = distance ||
|
|
12582
|
+
const scrollDistance = distance || width / 3;
|
|
12571
12583
|
await this.swipe(start.x, start.y, start.x + scrollDistance, start.y);
|
|
12572
12584
|
}
|
|
12573
12585
|
async scrollRight(distance, startPoint) {
|
|
@@ -12579,7 +12591,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
12579
12591
|
x: width / 2,
|
|
12580
12592
|
y: height / 2
|
|
12581
12593
|
};
|
|
12582
|
-
const scrollDistance = distance ||
|
|
12594
|
+
const scrollDistance = distance || width / 3;
|
|
12583
12595
|
await this.swipe(start.x, start.y, start.x - scrollDistance, start.y);
|
|
12584
12596
|
}
|
|
12585
12597
|
async scrollUntilTop(startPoint) {
|
|
@@ -12899,17 +12911,14 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
12899
12911
|
host: 'localhost',
|
|
12900
12912
|
port: constants_namespaceObject.DEFAULT_WDA_PORT
|
|
12901
12913
|
};
|
|
12902
|
-
let device;
|
|
12903
|
-
let agent;
|
|
12904
12914
|
let connected = false;
|
|
12905
12915
|
while(!connected)try {
|
|
12906
|
-
device = new device_IOSDevice({
|
|
12916
|
+
const device = new device_IOSDevice({
|
|
12907
12917
|
wdaHost: wdaConfig.host,
|
|
12908
12918
|
wdaPort: wdaConfig.port
|
|
12909
12919
|
});
|
|
12910
12920
|
console.log(`\u{1F50C} Connecting to WebDriverAgent at ${wdaConfig.host}:${wdaConfig.port}...`);
|
|
12911
12921
|
await device.connect();
|
|
12912
|
-
agent = new IOSAgent(device);
|
|
12913
12922
|
connected = true;
|
|
12914
12923
|
const deviceInfo = await device.getConnectedDeviceInfo();
|
|
12915
12924
|
console.log("\u2705 Connected to WebDriverAgent successfully!");
|
|
@@ -12961,7 +12970,16 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
12961
12970
|
`);
|
|
12962
12971
|
else if ('configure' === action) wdaConfig = await configureWebDriverAgent();
|
|
12963
12972
|
}
|
|
12964
|
-
const
|
|
12973
|
+
const deviceFactory = async ()=>{
|
|
12974
|
+
const newDevice = new device_IOSDevice({
|
|
12975
|
+
wdaHost: wdaConfig.host,
|
|
12976
|
+
wdaPort: wdaConfig.port
|
|
12977
|
+
});
|
|
12978
|
+
await newDevice.connect();
|
|
12979
|
+
return newDevice;
|
|
12980
|
+
};
|
|
12981
|
+
const agentFactory = (device)=>new IOSAgent(device);
|
|
12982
|
+
const playgroundServer = new PlaygroundServer(deviceFactory, agentFactory, staticDir);
|
|
12965
12983
|
console.log("\uD83D\uDE80 Starting server...");
|
|
12966
12984
|
const availablePlaygroundPort = await findAvailablePort(constants_namespaceObject.PLAYGROUND_SERVER_PORT);
|
|
12967
12985
|
if (availablePlaygroundPort !== constants_namespaceObject.PLAYGROUND_SERVER_PORT) console.log(`\u{26A0}\u{FE0F} Port ${constants_namespaceObject.PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
|
package/dist/lib/index.js
CHANGED
|
@@ -235,60 +235,17 @@ class IOSWebDriverClient extends webdriver_namespaceObject.WebDriverClient {
|
|
|
235
235
|
async swipe(fromX, fromY, toX, toY, duration = 500) {
|
|
236
236
|
this.ensureSession();
|
|
237
237
|
try {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
actions: [
|
|
247
|
-
{
|
|
248
|
-
type: 'pointerMove',
|
|
249
|
-
duration: 0,
|
|
250
|
-
x: fromX,
|
|
251
|
-
y: fromY
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
type: 'pointerDown',
|
|
255
|
-
button: 0
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
type: 'pause',
|
|
259
|
-
duration: 100
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
type: 'pointerMove',
|
|
263
|
-
duration,
|
|
264
|
-
x: toX,
|
|
265
|
-
y: toY
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
type: 'pointerUp',
|
|
269
|
-
button: 0
|
|
270
|
-
}
|
|
271
|
-
]
|
|
272
|
-
}
|
|
273
|
-
]
|
|
274
|
-
};
|
|
275
|
-
await this.makeRequest('POST', `/session/${this.sessionId}/actions`, actions);
|
|
276
|
-
debugIOS(`Swiped using W3C Actions from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
238
|
+
await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
|
|
239
|
+
fromX,
|
|
240
|
+
fromY,
|
|
241
|
+
toX,
|
|
242
|
+
toY,
|
|
243
|
+
duration: duration / 1000
|
|
244
|
+
});
|
|
245
|
+
debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
277
246
|
} catch (error) {
|
|
278
|
-
debugIOS(`
|
|
279
|
-
|
|
280
|
-
await this.makeRequest('POST', `/session/${this.sessionId}/wda/dragfromtoforduration`, {
|
|
281
|
-
fromX,
|
|
282
|
-
fromY,
|
|
283
|
-
toX,
|
|
284
|
-
toY,
|
|
285
|
-
duration: duration / 1000
|
|
286
|
-
});
|
|
287
|
-
debugIOS(`Swiped from (${fromX}, ${fromY}) to (${toX}, ${toY}) in ${duration}ms`);
|
|
288
|
-
} catch (error2) {
|
|
289
|
-
debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error2}`);
|
|
290
|
-
throw new Error(`Failed to swipe: ${error2}`);
|
|
291
|
-
}
|
|
247
|
+
debugIOS(`Failed to swipe from (${fromX}, ${fromY}) to (${toX}, ${toY}): ${error}`);
|
|
248
|
+
throw new Error(`Failed to swipe: ${error}`);
|
|
292
249
|
}
|
|
293
250
|
}
|
|
294
251
|
async longPress(x, y, duration = 1000) {
|
|
@@ -661,7 +618,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
661
618
|
x: width / 2,
|
|
662
619
|
y: height / 2
|
|
663
620
|
};
|
|
664
|
-
const scrollDistance = distance ||
|
|
621
|
+
const scrollDistance = distance || width / 3;
|
|
665
622
|
await this.swipe(start.x, start.y, start.x + scrollDistance, start.y);
|
|
666
623
|
}
|
|
667
624
|
async scrollRight(distance, startPoint) {
|
|
@@ -673,7 +630,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
|
|
|
673
630
|
x: width / 2,
|
|
674
631
|
y: height / 2
|
|
675
632
|
};
|
|
676
|
-
const scrollDistance = distance ||
|
|
633
|
+
const scrollDistance = distance || width / 3;
|
|
677
634
|
await this.swipe(start.x, start.y, start.x - scrollDistance, start.y);
|
|
678
635
|
}
|
|
679
636
|
async scrollUntilTop(startPoint) {
|