1+ const DebugRouterConnector = require ( "@lynx-js/debug-router-connector" ) . DebugRouterConnector ;
2+
3+ const util = require ( './util.js' ) ;
4+
5+ function sleep ( ms ) {
6+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
7+ }
8+
9+
10+ async function TryConnect ( driver , serial , num ) {
11+ console . log ( 'TryConnect start: ' , num ) ;
12+ await sleep ( 3000 ) ;
13+ const clients = await driver . connectUsbClients ( serial , 5000 ) ;
14+ if ( clients && clients . length > 0 ) {
15+ console . log ( clients [ 0 ] . info . query . raw_info ) ;
16+ if ( num < 10 ) {
17+ return ;
18+ }
19+ sleep ( 3000 ) ;
20+ console . log ( 'TryConnect check the last connect start: ' , num ) ;
21+ const message = 'a' . repeat ( 20 ) ;
22+ const result = await clients [ 0 ] . sendCustomizedMessage ( "App.GetCloseCoverageUploadSwitch" , { message : message } , - 1 , "App" ) ;
23+ console . log ( result ) ;
24+ if ( ! result ) {
25+ console . error ( 'sendCustomizedMessage failed' ) ;
26+ process . exit ( - 1 ) ;
27+ } else {
28+ console . log ( 'sendCustomizedMessage success' ) ;
29+ }
30+ } else {
31+ console . error ( 'no clients connected' ) ;
32+ }
33+ console . log ( 'TryConnect end: ' , num ) ;
34+ }
35+
36+ async function main ( ) {
37+ const startActivity = 'adb shell am start -n com.lynx.debugrouter.testapp/com.lynx.debugrouter.testapp.MainActivity'
38+ util . exec ( startActivity , 10000 ) . then ( ( data ) => {
39+ console . log ( "startActivity:" + data ) ;
40+ } ) . catch ( ( reason ) => {
41+ console . log ( "startActivity FAILED:" + reason ) ;
42+ process . exit ( - 1 ) ;
43+ } ) ;
44+
45+ const driver = new DebugRouterConnector ( {
46+ manualConnect : true ,
47+ enableWebSocket : false ,
48+ enableAndroid : true ,
49+ enableIOS : true ,
50+ enableDesktop : false ,
51+ websocketOption : { }
52+ } ) ;
53+
54+ try {
55+ const devicesArray = await driver . connectDevices ( 5000 ) ;
56+ if ( devicesArray . length === 0 ) {
57+ console . error ( 'no devices connected' ) ;
58+ return ;
59+ }
60+ var serial = devicesArray [ 0 ] . serial ;
61+ const Connect0 = TryConnect ( driver , serial , 1 ) ;
62+ const Connect1 = TryConnect ( driver , serial , 2 ) ;
63+ const Connect2 = TryConnect ( driver , serial , 3 ) ;
64+ const Connect3 = TryConnect ( driver , serial , 4 ) ;
65+ const Connect4 = TryConnect ( driver , serial , 5 ) ;
66+ const Connect5 = TryConnect ( driver , serial , 6 ) ;
67+ const Connect6 = TryConnect ( driver , serial , 7 ) ;
68+ const Connect7 = TryConnect ( driver , serial , 8 ) ;
69+ const Connect8 = TryConnect ( driver , serial , 9 ) ;
70+ const Connect9 = TryConnect ( driver , serial , 10 ) ;
71+ await Promise . all ( [ Connect0 , Connect1 , Connect2 , Connect3 , Connect4 , Connect5 , Connect6 , Connect7 , Connect8 , Connect9 ] ) ;
72+ console . log ( 'TryConnect test end.' ) ;
73+ } catch ( error ) {
74+ console . error ( 'Call tryConnect error: ' , error ) ;
75+ }
76+ process . exit ( 0 ) ;
77+ }
78+
79+ main ( ) ;
0 commit comments