forked from BrowserStackCE/browserstack-now
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac.sh
More file actions
executable file
·1778 lines (1492 loc) · 54.8 KB
/
mac.sh
File metadata and controls
executable file
·1778 lines (1492 loc) · 54.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
set -o pipefail
# ===== Global Variables =====
WORKSPACE_DIR="$HOME/.browserstack"
PROJECT_FOLDER="NOW"
BROWSERSTACK_USERNAME=""
BROWSERSTACK_ACCESS_KEY=""
TEST_TYPE="" # Web / App / Both
TECH_STACK="" # Java / Python / JS
PARALLEL_PERCENTAGE=1.00
WEB_PLAN_FETCHED=false
MOBILE_PLAN_FETCHED=false
TEAM_PARALLELS_MAX_ALLOWED_WEB=0
TEAM_PARALLELS_MAX_ALLOWED_MOBILE=0
# URL handling
DEFAULT_TEST_URL="https://bstackdemo.com"
CX_TEST_URL="$DEFAULT_TEST_URL"
# Global vars
APP_URL=""
APP_PLATFORM="" # ios | android | all
# ===== Error Patterns =====
WEB_SETUP_ERRORS=("")
WEB_LOCAL_ERRORS=("")
MOBILE_SETUP_ERRORS=("")
MOBILE_LOCAL_ERRORS=("")
# ===== Example Platform Templates (replace with your full lists if available) =====
WEB_PLATFORM_TEMPLATES=(
"Windows|10|Chrome"
"Windows|10|Firefox"
"Windows|11|Edge"
"Windows|11|Chrome"
"Windows|8|Chrome"
"OS X|Monterey|Safari"
"OS X|Monterey|Chrome"
"OS X|Ventura|Chrome"
"OS X|Big Sur|Safari"
"OS X|Catalina|Firefox"
)
MOBILE_TIER1=(
"ios|iPhone 15|17"
"ios|iPhone 15 Pro|17"
"ios|iPhone 16|18"
"android|Samsung Galaxy S25|15"
"android|Samsung Galaxy S24|14"
)
# Tier 2 – Up to 40 parallels
MOBILE_TIER2=(
"ios|iPhone 14 Pro|16"
"ios|iPhone 14|16"
"ios|iPad Air 13 2025|18"
"android|Samsung Galaxy S23|13"
"android|Samsung Galaxy S22|12"
"android|Samsung Galaxy S21|11"
"android|Samsung Galaxy Tab S10 Plus|15"
)
# Tier 3 – Up to 16 parallels
MOBILE_TIER3=(
"ios|iPhone 13 Pro Max|15"
"ios|iPhone 13|15"
"ios|iPhone 12 Pro|14"
"ios|iPhone 12 Pro|17"
"ios|iPhone 12|17"
"ios|iPhone 12|14"
"ios|iPhone 12 Pro Max|16"
"ios|iPhone 13 Pro|15"
"ios|iPhone 13 Mini|15"
"ios|iPhone 16 Pro|18"
"ios|iPad 9th|15"
"ios|iPad Pro 12.9 2020|14"
"ios|iPad Pro 12.9 2020|16"
"ios|iPad 8th|16"
"android|Samsung Galaxy S22 Ultra|12"
"android|Samsung Galaxy S21|12"
"android|Samsung Galaxy S21 Ultra|11"
"android|Samsung Galaxy S20|10"
"android|Samsung Galaxy M32|11"
"android|Samsung Galaxy Note 20|10"
"android|Samsung Galaxy S10|9"
"android|Samsung Galaxy Note 9|8"
"android|Samsung Galaxy Tab S8|12"
"android|Google Pixel 9|15"
"android|Google Pixel 6 Pro|13"
"android|Google Pixel 8|14"
"android|Google Pixel 7|13"
"android|Google Pixel 6|12"
"android|Vivo Y21|11"
"android|Vivo Y50|10"
"android|Oppo Reno 6|11"
)
# Tier 4 – Up to 5 parallels
MOBILE_TIER4=(
"ios|iPhone 15 Pro Max|17"
"ios|iPhone 15 Pro Max|26"
"ios|iPhone 15|26"
"ios|iPhone 15 Plus|17"
"ios|iPhone 14 Pro|26"
"ios|iPhone 14|18"
"ios|iPhone 14|26"
"ios|iPhone 13 Pro Max|18"
"ios|iPhone 13|16"
"ios|iPhone 13|17"
"ios|iPhone 13|18"
"ios|iPhone 12 Pro|18"
"ios|iPhone 14 Pro Max|16"
"ios|iPhone 14 Plus|16"
"ios|iPhone 11|13"
"ios|iPhone 8|11"
"ios|iPhone 7|10"
"ios|iPhone 17 Pro Max|26"
"ios|iPhone 17 Pro|26"
"ios|iPhone 17 Air|26"
"ios|iPhone 17|26"
"ios|iPhone 16e|18"
"ios|iPhone 16 Pro Max|18"
"ios|iPhone 16 Plus|18"
"ios|iPhone SE 2020|16"
"ios|iPhone SE 2022|15"
"ios|iPad Air 4|14"
"ios|iPad 9th|18"
"ios|iPad Air 5|26"
"ios|iPad Pro 11 2021|18"
"ios|iPad Pro 13 2024|17"
"ios|iPad Pro 12.9 2021|14"
"ios|iPad Pro 12.9 2021|17"
"ios|iPad Pro 11 2024|17"
"ios|iPad Air 6|17"
"ios|iPad Pro 12.9 2022|16"
"ios|iPad Pro 11 2022|16"
"ios|iPad 10th|16"
"ios|iPad Air 13 2025|26"
"ios|iPad Pro 11 2020|13"
"ios|iPad Pro 11 2020|16"
"ios|iPad 8th|14"
"ios|iPad Mini 2021|15"
"ios|iPad Pro 12.9 2018|12"
"ios|iPad 6th|11"
"android|Samsung Galaxy S23 Ultra|13"
"android|Samsung Galaxy S22 Plus|12"
"android|Samsung Galaxy S21 Plus|11"
"android|Samsung Galaxy S20 Ultra|10"
"android|Samsung Galaxy S25 Ultra|15"
"android|Samsung Galaxy S24 Ultra|14"
"android|Samsung Galaxy M52|11"
"android|Samsung Galaxy A52|11"
"android|Samsung Galaxy A51|10"
"android|Samsung Galaxy A11|10"
"android|Samsung Galaxy A10|9"
"android|Samsung Galaxy Tab A9 Plus|14"
"android|Samsung Galaxy Tab S9|13"
"android|Samsung Galaxy Tab S7|10"
"android|Samsung Galaxy Tab S7|11"
"android|Samsung Galaxy Tab S6|9"
"android|Google Pixel 9|16"
"android|Google Pixel 10 Pro XL|16"
"android|Google Pixel 10 Pro|16"
"android|Google Pixel 10|16"
"android|Google Pixel 9 Pro XL|15"
"android|Google Pixel 9 Pro|15"
"android|Google Pixel 6 Pro|12"
"android|Google Pixel 6 Pro|15"
"android|Google Pixel 8 Pro|14"
"android|Google Pixel 7 Pro|13"
"android|Google Pixel 5|11"
"android|OnePlus 13R|15"
"android|OnePlus 12R|14"
"android|OnePlus 11R|13"
"android|OnePlus 9|11"
"android|OnePlus 8|10"
"android|Motorola Moto G71 5G|11"
"android|Motorola Moto G9 Play|10"
"android|Vivo V21|11"
"android|Oppo A96|11"
"android|Oppo Reno 3 Pro|10"
"android|Xiaomi Redmi Note 11|11"
"android|Xiaomi Redmi Note 9|10"
"android|Huawei P30|9"
)
MOBILE_ALL=(
# Tier 1
"ios|iPhone 15|17"
"ios|iPhone 15 Pro|17"
"ios|iPhone 16|18"
"android|Samsung Galaxy S25|15"
"android|Samsung Galaxy S24|14"
# Tier 2
"ios|iPhone 14 Pro|16"
"ios|iPhone 14|16"
"ios|iPad Air 13 2025|18"
"android|Samsung Galaxy S23|13"
"android|Samsung Galaxy S22|12"
"android|Samsung Galaxy S21|11"
"android|Samsung Galaxy Tab S10 Plus|15"
# Tier 3
"ios|iPhone 13 Pro Max|15"
"ios|iPhone 13|15"
"ios|iPhone 12 Pro|14"
"ios|iPhone 12 Pro|17"
"ios|iPhone 12|17"
"ios|iPhone 12|14"
"ios|iPhone 12 Pro Max|16"
"ios|iPhone 13 Pro|15"
"ios|iPhone 13 Mini|15"
"ios|iPhone 16 Pro|18"
"ios|iPad 9th|15"
"ios|iPad Pro 12.9 2020|14"
"ios|iPad Pro 12.9 2020|16"
"ios|iPad 8th|16"
"android|Samsung Galaxy S22 Ultra|12"
"android|Samsung Galaxy S21|12"
"android|Samsung Galaxy S21 Ultra|11"
"android|Samsung Galaxy S20|10"
"android|Samsung Galaxy M32|11"
"android|Samsung Galaxy Note 20|10"
"android|Samsung Galaxy S10|9"
"android|Samsung Galaxy Note 9|8"
"android|Samsung Galaxy Tab S8|12"
"android|Google Pixel 9|15"
"android|Google Pixel 6 Pro|13"
"android|Google Pixel 8|14"
"android|Google Pixel 7|13"
"android|Google Pixel 6|12"
"android|Vivo Y21|11"
"android|Vivo Y50|10"
"android|Oppo Reno 6|11"
# Tier 4
"ios|iPhone 15 Pro Max|17"
"ios|iPhone 15 Pro Max|26"
"ios|iPhone 15|26"
"ios|iPhone 15 Plus|17"
"ios|iPhone 14 Pro|26"
"ios|iPhone 14|18"
"ios|iPhone 14|26"
"ios|iPhone 13 Pro Max|18"
"ios|iPhone 13|16"
"ios|iPhone 13|17"
"ios|iPhone 13|18"
"ios|iPhone 12 Pro|18"
"ios|iPhone 14 Pro Max|16"
"ios|iPhone 14 Plus|16"
"ios|iPhone 11|13"
"ios|iPhone 8|11"
"ios|iPhone 7|10"
"ios|iPhone 17 Pro Max|26"
"ios|iPhone 17 Pro|26"
"ios|iPhone 17 Air|26"
"ios|iPhone 17|26"
"ios|iPhone 16e|18"
"ios|iPhone 16 Pro Max|18"
"ios|iPhone 16 Plus|18"
"ios|iPhone SE 2020|16"
"ios|iPhone SE 2022|15"
"ios|iPad Air 4|14"
"ios|iPad 9th|18"
"ios|iPad Air 5|26"
"ios|iPad Pro 11 2021|18"
"ios|iPad Pro 13 2024|17"
"ios|iPad Pro 12.9 2021|14"
"ios|iPad Pro 12.9 2021|17"
"ios|iPad Pro 11 2024|17"
"ios|iPad Air 6|17"
"ios|iPad Pro 12.9 2022|16"
"ios|iPad Pro 11 2022|16"
"ios|iPad 10th|16"
"ios|iPad Air 13 2025|26"
"ios|iPad Pro 11 2020|13"
"ios|iPad Pro 11 2020|16"
"ios|iPad 8th|14"
"ios|iPad Mini 2021|15"
"ios|iPad Pro 12.9 2018|12"
"ios|iPad 6th|11"
"android|Samsung Galaxy S23 Ultra|13"
"android|Samsung Galaxy S22 Plus|12"
"android|Samsung Galaxy S21 Plus|11"
"android|Samsung Galaxy S20 Ultra|10"
"android|Samsung Galaxy S25 Ultra|15"
"android|Samsung Galaxy S24 Ultra|14"
"android|Samsung Galaxy M52|11"
"android|Samsung Galaxy A52|11"
"android|Samsung Galaxy A51|10"
"android|Samsung Galaxy A11|10"
"android|Samsung Galaxy A10|9"
"android|Samsung Galaxy Tab A9 Plus|14"
"android|Samsung Galaxy Tab S9|13"
"android|Samsung Galaxy Tab S7|10"
"android|Samsung Galaxy Tab S7|11"
"android|Samsung Galaxy Tab S6|9"
"android|Google Pixel 9|16"
"android|Google Pixel 10 Pro XL|16"
"android|Google Pixel 10 Pro|16"
"android|Google Pixel 10|16"
"android|Google Pixel 9 Pro XL|15"
"android|Google Pixel 9 Pro|15"
"android|Google Pixel 6 Pro|12"
"android|Google Pixel 6 Pro|15"
"android|Google Pixel 8 Pro|14"
"android|Google Pixel 7 Pro|13"
"android|Google Pixel 5|11"
"android|OnePlus 13R|15"
"android|OnePlus 12R|14"
"android|OnePlus 11R|13"
"android|OnePlus 9|11"
"android|OnePlus 8|10"
"android|Motorola Moto G71 5G|11"
"android|Motorola Moto G9 Play|10"
"android|Vivo V21|11"
"android|Oppo A96|11"
"android|Oppo Reno 3 Pro|10"
"android|Xiaomi Redmi Note 11|11"
"android|Xiaomi Redmi Note 9|10"
"android|Huawei P30|9"
)
APP_URL=""
APP_PLATFORM="" # ios | android | all
# ===== Log files (runtime only; created on first write) =====
# ===== Log files (per-run) =====
LOG_DIR="$WORKSPACE_DIR/$PROJECT_FOLDER/logs"
GLOBAL="$LOG_DIR/global.log"
WEB_LOG_FILE="$LOG_DIR/web_run_result.log"
MOBILE_LOG_FILE="$LOG_DIR/mobile_run_result.log"
# Ensure log directory exists
mkdir -p "$LOG_DIR"
# Clear old logs to start fresh
: > "$GLOBAL"
: > "$WEB_LOG_FILE"
: > "$MOBILE_LOG_FILE"
# ===== Logging helper (runtime timestamped logging) =====
# Usage: log_msg_to "message" "$DEST_FILE" (DEST_FILE optional; prints to console always)
log_msg_to() {
local message="$1"
local dest_file="$2" # optional
local ts
ts="$(date +"%Y-%m-%d %H:%M:%S")"
local line="[$ts] $message"
# print to console
echo "$line"
# write to dest file if provided
if [ -n "$dest_file" ]; then
mkdir -p "$(dirname "$dest_file")"
echo "$line" >> "$dest_file"
fi
}
# ===== validate_prereqs shim (keeps compatibility with older code) =====
validate_prereqs() {
# For backwards compatibility call validate_tech_stack_installed
validate_tech_stack_installed
}
# ===== Functions: baseline interactions =====
setup_workspace() {
local full_path="$WORKSPACE_DIR/$PROJECT_FOLDER"
if [ ! -d "$full_path" ]; then
mkdir -p "$full_path"
log_msg_to "✅ Created Onboarding workspace: $full_path" "$GLOBAL"
else
log_msg_to "ℹ️ Onboarding Workspace already exists: $full_path" "$GLOBAL"
fi
}
ask_browserstack_credentials() {
# Prompt username
BROWSERSTACK_USERNAME=$(osascript -e 'Tell application "System Events" to display dialog "Enter your BrowserStack Username:" default answer "" with title "BrowserStack Setup" buttons {"OK"} default button "OK"' \
-e 'text returned of result')
if [ -z "$BROWSERSTACK_USERNAME" ]; then
log_msg_to "❌ Username empty" "$GLOBAL"
exit 1
fi
# Prompt access key (hidden)
BROWSERSTACK_ACCESS_KEY=$(osascript -e 'Tell application "System Events" to display dialog "Enter your BrowserStack Access Key:" default answer "" with hidden answer with title "BrowserStack Setup" buttons {"OK"} default button "OK"' \
-e 'text returned of result')
if [ -z "$BROWSERSTACK_ACCESS_KEY" ]; then
log_msg_to "❌ Access Key empty" "$GLOBAL"
exit 1
fi
log_msg_to "✅ BrowserStack credentials captured (access key hidden)" "$GLOBAL"
}
# ask_test_type() {
# TEST_TYPE=$(osascript -e 'Tell application "System Events" to display dialog "Select testing type:" buttons {"Web", "App", "Both"} default button "Web" with title "Testing Type"' \
# -e 'button returned of result')
# log_msg_to "✅ Selected Testing Type: $TEST_TYPE" "$GLOBAL"
# }
ask_tech_stack() {
TECH_STACK=$(osascript -e 'Tell application "System Events" to display dialog "Select installed tech stack:" buttons {"Java", "Python"} default button "Java" with title "Tech Stack"' \
-e 'button returned of result')
log_msg_to "✅ Selected Tech Stack: $TECH_STACK" "$GLOBAL"
}
# ask_tech_stack() {
# TECH_STACK=$(osascript -e 'Tell application "System Events" to display dialog "Select installed tech stack:" buttons {"Java", "Python"} default button "Java" with title "Tech Stack"' \
# -e 'button returned of result')
# log_msg_to "✅ Selected Tech Stack: $TECH_STACK" "$GLOBAL"
# }
validate_tech_stack_installed() {
log_msg_to "ℹ️ Checking prerequisites for $TECH_STACK" "$GLOBAL"
case "$TECH_STACK" in
Java)
log_msg_to "🔍 Checking if 'java' command exists..." "$GLOBAL"
if ! command -v java >/dev/null 2>&1; then
log_msg_to "❌ Java command not found in PATH." "$GLOBAL"
exit 1
fi
log_msg_to "🔍 Checking if Java runs correctly..." "$GLOBAL"
if ! JAVA_VERSION_OUTPUT=$(java -version 2>&1); then
log_msg_to "❌ Java exists but failed to run." "$GLOBAL"
exit 1
fi
log_msg_to "✅ Java is installed. Version details:" "$GLOBAL"
echo "$JAVA_VERSION_OUTPUT" | while read -r l; do log_msg_to " $l" "$GLOBAL"; done
;;
Python)
log_msg_to "🔍 Checking if 'python3' command exists..." "$GLOBAL"
if ! command -v python3 >/dev/null 2>&1; then
log_msg_to "❌ Python3 command not found in PATH." "$GLOBAL"
exit 1
fi
log_msg_to "🔍 Checking if Python3 runs correctly..." "$GLOBAL"
if ! PYTHON_VERSION_OUTPUT=$(python3 --version 2>&1); then
log_msg_to "❌ Python3 exists but failed to run." "$GLOBAL"
exit 1
fi
log_msg_to "✅ Python3 is installed: $PYTHON_VERSION_OUTPUT" "$GLOBAL"
;;
JS|JavaScript)
log_msg_to "🔍 Checking if 'node' command exists..." "$GLOBAL"
if ! command -v node >/dev/null 2>&1; then
log_msg_to "❌ Node.js command not found in PATH." "$GLOBAL"
exit 1
fi
log_msg_to "🔍 Checking if 'npm' command exists..." "$GLOBAL"
if ! command -v npm >/dev/null 2>&1; then
log_msg_to "❌ npm command not found in PATH." "$GLOBAL"
exit 1
fi
log_msg_to "🔍 Checking if Node.js runs correctly..." "$GLOBAL"
if ! NODE_VERSION_OUTPUT=$(node -v 2>&1); then
log_msg_to "❌ Node.js exists but failed to run." "$GLOBAL"
exit 1
fi
log_msg_to "🔍 Checking if npm runs correctly..." "$GLOBAL"
if ! NPM_VERSION_OUTPUT=$(npm -v 2>&1); then
log_msg_to "❌ npm exists but failed to run." "$GLOBAL"
exit 1
fi
log_msg_to "✅ Node.js is installed: $NODE_VERSION_OUTPUT" "$GLOBAL"
log_msg_to "✅ npm is installed: $NPM_VERSION_OUTPUT" "$GLOBAL"
;;
*)
log_msg_to "❌ Unknown tech stack selected: $TECH_STACK" "$GLOBAL"
exit 1
;;
esac
log_msg_to "✅ Prerequisites validated for $TECH_STACK" "$GLOBAL"
}
# ===== Ask user for test URL via UI prompt =====
ask_user_for_test_url() {
CX_TEST_URL=$(osascript -e 'Tell application "System Events" to display dialog "Enter the URL you want to test with BrowserStack:\n(Leave blank for default: '"$DEFAULT_TEST_URL"')" default answer "" with title "Test URL Setup" buttons {"OK"} default button "OK"' \
-e 'text returned of result')
if [ -n "$CX_TEST_URL" ]; then
log_msg_to "🌐 Using custom test URL: $CX_TEST_URL" "$PRE_RUN_LOG_FILE"
else
CX_TEST_URL="$DEFAULT_TEST_URL"
log_msg_to "⚠️ No URL entered. Falling back to default: $CX_TEST_URL" "$PRE_RUN_LOG_FILE"
fi
}
ask_and_upload_app() {
APP_FILE_PATH=$(osascript -e 'POSIX path of (choose file with prompt "📱 Please select your .apk or .ipa app file to upload to BrowserStack, If No App Selected then Defualt Browserstack app will be used automatically")')
if [ -z "$APP_FILE_PATH" ]; then
log_msg_to "⚠️ No app selected. Using default sample app: bs://sample.app" "$GLOBAL"
APP_URL="bs://sample.app"
APP_PLATFORM="all"
return
fi
# Detect platform
if [[ "$APP_FILE_PATH" == *.apk ]]; then
APP_PLATFORM="android"
elif [[ "$APP_FILE_PATH" == *.ipa ]]; then
APP_PLATFORM="ios"
else
log_msg_to "❌ Unsupported file type. Only .apk or .ipa allowed." "$GLOBAL"
exit 1
fi
# Upload app
log_msg_to "⬆️ Uploading $APP_FILE_PATH to BrowserStack..." "$GLOBAL"
UPLOAD_RESPONSE=$(curl -s -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@$APP_FILE_PATH")
APP_URL=$(echo "$UPLOAD_RESPONSE" | grep -o '"app_url":"[^"]*' | cut -d'"' -f4)
if [ -z "$APP_URL" ]; then
log_msg_to "❌ Upload failed. Response: $UPLOAD_RESPONSE" "$GLOBAL"
exit 1
fi
log_msg_to "✅ App uploaded successfully: $APP_URL" "$GLOBAL"
}
ask_test_type() {
TEST_TYPE=$(osascript -e 'Tell application "System Events" to display dialog "Select testing type:" buttons {"Web", "App", "Both"} default button "Web" with title "Testing Type"' \
-e 'button returned of result')
log_msg_to "✅ Selected Testing Type: $TEST_TYPE" "$GLOBAL"
case "$TEST_TYPE" in
"Web")
ask_user_for_test_url
;;
"App")
ask_and_upload_app
;;
"Both")
ask_user_for_test_url
ask_and_upload_app
;;
esac
}
# ===== Dynamic config generators =====
generate_web_platforms_yaml() {
local max_total_parallels=$1
local max
max=$(echo "$max_total_parallels * $PARALLEL_PERCENTAGE" | bc | cut -d'.' -f1)
[ -z "$max" ] && max=0
local yaml=""
local count=0
for template in "${WEB_PLATFORM_TEMPLATES[@]}"; do
IFS="|" read -r os osVersion browserName <<< "$template"
for version in latest latest-1 latest-2; do
yaml+=" - os: $os
osVersion: $osVersion
browserName: $browserName
browserVersion: $version
"
count=$((count + 1))
if [ "$count" -ge "$max" ]; then
echo "$yaml"
return
fi
done
done
echo "$yaml"
}
# generate_mobile_platforms_yaml() {
# local max_total_parallels=$1
# local max
# max=$(echo "$max_total_parallels * $PARALLEL_PERCENTAGE" | bc | cut -d'.' -f1)
# [ -z "$max" ] && max=0
# local yaml=""
# local count=0
# for template in "${MOBILE_DEVICE_TEMPLATES[@]}"; do
# IFS="|" read -r platformName deviceName platformVersion <<< "$template"
# yaml+=" - platformName: $platformName
# deviceName: $deviceName
# platformVersion: '${platformVersion}.0'
# "
# count=$((count + 1))
# if [ "$count" -ge "$max" ]; then
# echo "$yaml"
# return
# fi
# done
# echo "$yaml"
# }
# ask_and_upload_app() {
# APP_FILE_PATH=$(osascript -e 'POSIX path of (choose file with prompt "📱 Please select your .apk or .ipa app file to upload to BrowserStack")')
# if [ -z "$APP_FILE_PATH" ]; then
# log_msg_to "⚠️ No app selected. Using default sample app: bs://sample.app" "$GLOBAL"
# APP_URL="bs://sample.app"
# APP_PLATFORM="all"
# return
# fi
# # Detect platform
# if [[ "$APP_FILE_PATH" == *.apk ]]; then
# APP_PLATFORM="android"
# elif [[ "$APP_FILE_PATH" == *.ipa ]]; then
# APP_PLATFORM="ios"
# else
# log_msg_to "❌ Unsupported file type. Only .apk or .ipa allowed." "$GLOBAL"
# exit 1
# fi
# # Upload app
# log_msg_to "⬆️ Uploading $APP_FILE_PATH to BrowserStack..." "$GLOBAL"
# UPLOAD_RESPONSE=$(curl -s -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" \
# -X POST "https://api-cloud.browserstack.com/app-automate/upload" \
# -F "file=@$APP_FILE_PATH")
# APP_URL=$(echo "$UPLOAD_RESPONSE" | grep -o '"app_url":"[^"]*' | cut -d'"' -f4)
# if [ -z "$APP_URL" ]; then
# log_msg_to "❌ Upload failed. Response: $UPLOAD_RESPONSE" "$GLOBAL"
# exit 1
# fi
# log_msg_to "✅ App uploaded successfully: $APP_URL" "$GLOBAL"
# }
# generate_mobile_platforms_yaml() {
# local max_total_parallels=$1
# local yaml=""
# local count=0
# # Select tier based on parallel count
# if (( max_total_parallels >= 80 )); then
# devices=("${MOBILE_TIER1[@]}")
# elif (( max_total_parallels >= 40 )); then
# devices=("${MOBILE_TIER2[@]}")
# elif (( max_total_parallels >= 16 )); then
# devices=("${MOBILE_TIER3[@]}")
# else
# devices=("${MOBILE_TIER4[@]}")
# fi
# # Filter devices by platform and limit by max_total_parallels
# for template in "${devices[@]}"; do
# IFS="|" read -r platformName deviceName platformVersion <<< "$template"
# # Skip if platform mismatch
# if [[ "$APP_PLATFORM" == "ios" && "$platformName" != "ios" ]]; then
# continue
# fi
# if [[ "$APP_PLATFORM" == "android" && "$platformName" != "android" ]]; then
# continue
# fi
# yaml+=" - platformName: $platformName
# deviceName: $deviceName
# platformVersion: ${platformVersion}.0
# "
# count=$((count + 1))
# if (( count >= max_total_parallels )); then
# break
# fi
# done
# echo "$yaml"
# }
generate_mobile_platforms_yaml() {
local max_total_parallels=$1
local max=$(echo "$max_total_parallels * $PARALLEL_PERCENTAGE" | bc | cut -d'.' -f1)
# fallback if bc result is empty or zero
if [ -z "$max" ] || [ "$max" -lt 1 ]; then
max=1
fi
local yaml=""
local count=0
for template in "${MOBILE_ALL[@]}"; do
IFS="|" read -r platformName deviceName platformVersion <<< "$template"
# Apply platform filter
if [ -n "$APP_PLATFORM" ]; then
if [[ "$APP_PLATFORM" == "ios" && "$platformName" != "ios" ]]; then
continue
fi
if [[ "$APP_PLATFORM" == "android" && "$platformName" != "android" ]]; then
continue
fi
fi
yaml+=" - platformName: $platformName
deviceName: $deviceName
platformVersion: '${platformVersion}.0'
"
count=$((count + 1))
if [ "$count" -ge "$max" ]; then
echo "$yaml"
return
fi
done
echo "$yaml"
}
generate_web_caps_json() {
local max_total_parallels=$1
local max
max=$(echo "$max_total_parallels * $PARALLEL_PERCENTAGE" | bc | cut -d'.' -f1)
[ "$max" -lt 1 ] && max=1 # fallback to minimum 1
local json=""
local count=0
for template in "${WEB_PLATFORM_TEMPLATES[@]}"; do
IFS="|" read -r os osVersion browserName <<< "$template"
for version in latest latest-1 latest-2; do
json+="{
\"browserName\": \"$browserName\",
\"browserVersion\": \"$version\",
\"bstack:options\": {
\"os\": \"$os\",
\"osVersion\": \"$osVersion\"
}
},"
count=$((count + 1))
if [ "$count" -ge "$max" ]; then
json="${json%,}" # strip trailing comma
echo "$json"
return
fi
done
done
# Fallback in case not enough combinations
json="${json%,}"
echo "$json"
}
generate_mobile_caps_json() {
local max_total=$1
local count=0
local usage_file="/tmp/device_usage.txt"
: > "$usage_file"
local json="["
for template in "${MOBILE_DEVICE_TEMPLATES[@]}"; do
IFS="|" read -r platformName deviceName baseVersion <<< "$template"
local usage
usage=$(grep -Fxc "$deviceName" "$usage_file")
if [ "$usage" -ge 5 ]; then
continue
fi
json="${json}{
\"bstack:options\": {
\"deviceName\": \"${deviceName}\",
\"osVersion\": \"${baseVersion}.0\"
}
},"
echo "$deviceName" >> "$usage_file"
count=$((count + 1))
if [ "$count" -ge "$max_total" ]; then
break
fi
done
json="${json%,}]"
echo "$json"
rm -f "$usage_file"
}
# ===== Fetch plan details (writes to GLOBAL) =====
fetch_plan_details() {
log_msg_to "ℹ️ Fetching BrowserStack Plan Details..." "$GLOBAL"
local web_unauthorized=false
local mobile_unauthorized=false
if [[ "$TEST_TYPE" == "Web" || "$TEST_TYPE" == "Both" ]]; then
RESPONSE_WEB=$(curl -s -w "\n%{http_code}" -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" https://api.browserstack.com/automate/plan.json)
HTTP_CODE_WEB=$(echo "$RESPONSE_WEB" | tail -n1)
RESPONSE_WEB_BODY=$(echo "$RESPONSE_WEB" | sed '$d')
if [ "$HTTP_CODE_WEB" == "200" ]; then
WEB_PLAN_FETCHED=true
TEAM_PARALLELS_MAX_ALLOWED_WEB=$(echo "$RESPONSE_WEB_BODY" | grep -o '"parallel_sessions_max_allowed":[0-9]*' | grep -o '[0-9]*')
log_msg_to "✅ Web Testing Plan fetched: Team max parallel sessions = $TEAM_PARALLELS_MAX_ALLOWED_WEB" "$GLOBAL"
else
log_msg_to "❌ Web Testing Plan fetch failed ($HTTP_CODE_WEB)" "$GLOBAL"
[ "$HTTP_CODE_WEB" == "401" ] && web_unauthorized=true
fi
fi
if [[ "$TEST_TYPE" == "App" || "$TEST_TYPE" == "Both" ]]; then
RESPONSE_MOBILE=$(curl -s -w "\n%{http_code}" -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" https://api-cloud.browserstack.com/app-automate/plan.json)
HTTP_CODE_MOBILE=$(echo "$RESPONSE_MOBILE" | tail -n1)
RESPONSE_MOBILE_BODY=$(echo "$RESPONSE_MOBILE" | sed '$d')
if [ "$HTTP_CODE_MOBILE" == "200" ]; then
MOBILE_PLAN_FETCHED=true
TEAM_PARALLELS_MAX_ALLOWED_MOBILE=$(echo "$RESPONSE_MOBILE_BODY" | grep -o '"parallel_sessions_max_allowed":[0-9]*' | grep -o '[0-9]*')
log_msg_to "✅ Mobile App Testing Plan fetched: Team max parallel sessions = $TEAM_PARALLELS_MAX_ALLOWED_MOBILE" "$GLOBAL"
else
log_msg_to "❌ Mobile App Testing Plan fetch failed ($HTTP_CODE_MOBILE)" "$GLOBAL"
[ "$HTTP_CODE_MOBILE" == "401" ] && mobile_unauthorized=true
fi
fi
if [[ "$TEST_TYPE" == "Web" && "$web_unauthorized" == true ]] || \
[[ "$TEST_TYPE" == "App" && "$mobile_unauthorized" == true ]] || \
[[ "$TEST_TYPE" == "Both" && "$web_unauthorized" == true && "$mobile_unauthorized" == true ]]; then
log_msg_to "❌ Unauthorized to fetch required plan(s). Exiting." "$GLOBAL"
exit 1
fi
}
# setup_web_java_tested() {
# local local_flag=$1
# local parallels=$2
# local log_file=$3
# REPO="testng-browserstack"
# TARGET_DIR="$WORKSPACE_DIR/$PROJECT_FOLDER/$REPO"
# mkdir -p "$WORKSPACE_DIR/$PROJECT_FOLDER"
# # Clone repo if not present
# if [ ! -d "$TARGET_DIR" ]; then
# log_msg_to "📦 Cloning repo $REPO into $TARGET_DIR" "$GLOBAL"
# git clone https://github.com/browserstack/testng-browserstack.git "$TARGET_DIR"
# else
# log_msg_to "📂 Repo $REPO already exists at $TARGET_DIR, skipping clone." "$GLOBAL"
# fi
# cd "$TARGET_DIR" || return 1
# validate_prereqs || return 1
# # Export credentials for Maven to use
# export BROWSERSTACK_USERNAME="$BROWSERSTACK_USERNAME"
# export BROWSERSTACK_ACCESS_KEY="$BROWSERSTACK_ACCESS_KEY"
# # Run BrowserStack SDK archetype setup
# log_msg_to "⚙️ Setting up BrowserStack SDK project" "$GLOBAL"
# mvn archetype:generate -B \
# -DarchetypeGroupId=com.browserstack \
# -DarchetypeArtifactId=browserstack-sdk-archetype-setup \
# -DarchetypeVersion=1.1 \
# -DgroupId=com.browserstack \
# -DartifactId=testng-browserstack \
# -Dversion=1.0 \
# -DBROWSERSTACK_USERNAME="$BROWSERSTACK_USERNAME" \
# -DBROWSERSTACK_ACCESS_KEY="$BROWSERSTACK_ACCESS_KEY" \
# -DBROWSERSTACK_PROJECT_REPO="$REPO" >> "$log_file" 2>&1 || true
# # cd testng-browserstack || return 1
# # Update base URL in the Java code (replacing https://www.bstackdemo.com)
# sed -i.bak "s|https://www.bstackdemo.com|$CX_TEST_URL|g" $(grep -rl "https://www.bstackdemo.com" .)
# # Log local flag status
# if [ "$local_flag" = "true" ]; then
# log_msg_to "⚠️ BrowserStack Local is ENABLED for this run." "$GLOBAL"
# else
# log_msg_to "⚠️ BrowserStack Local is DISABLED for this run." "$GLOBAL"
# fi
# # Generate platforms YAML
# platform_yaml=$(generate_web_platforms_yaml "$TEAM_PARALLELS_MAX_ALLOWED_WEB")
# # Overwrite YAML config at the root level
# cat > browserstack.yml <<EOF
# userName: $BROWSERSTACK_USERNAME
# accessKey: $BROWSERSTACK_ACCESS_KEY
# framework: testng
# browserstackLocal: $local_flag
# buildName: browserstack-sample-java-web
# projectName: NOW-Web-Test
# percy: true
# accessibility: true
# platforms:
# $platform_yaml
# parallelsPerPlatform: $parallels
# EOF
# # Run Maven test
# log_msg_to "🚀 Running 'mvn test -P sample-test'" "$GLOBAL"
# mvn test -P sample-test >> "$log_file" 2>&1 || true
# cd "$WORKSPACE_DIR/$PROJECT_FOLDER"
# return 0
# }
setup_web_java() {
local local_flag=$1
local parallels=$2
REPO="testng-browserstack"
TARGET_DIR="$WORKSPACE_DIR/$PROJECT_FOLDER/$REPO"
mkdir -p "$WORKSPACE_DIR/$PROJECT_FOLDER"
# === 1️⃣ Clone Repo ===
if [ ! -d "$TARGET_DIR" ]; then
log_msg_to "📦 Cloning repo $REPO into $TARGET_DIR" "$GLOBAL" "$WEB_LOG_FILE"
git clone https://github.com/browserstack/testng-browserstack.git "$TARGET_DIR" >> "$WEB_LOG_FILE" 2>&1 || true
else
log_msg_to "📂 Repo $REPO already exists at $TARGET_DIR, skipping clone." "$GLOBAL" "$WEB_LOG_FILE"
fi
cd "$TARGET_DIR" || return 1
validate_prereqs || return 1
# === 2️⃣ SDK Setup ===
log_msg_to "⚙️ Setting up BrowserStack SDK project" "$GLOBAL" "$WEB_LOG_FILE"
mvn archetype:generate -B \
-DarchetypeGroupId=com.browserstack \
-DarchetypeArtifactId=browserstack-sdk-archetype-setup \
-DarchetypeVersion=1.1 \
-DgroupId=com.browserstack \
-DartifactId=testng-browserstack \
-Dversion=1.0 \
-DBROWSERSTACK_USERNAME="$BROWSERSTACK_USERNAME" \
-DBROWSERSTACK_ACCESS_KEY="$BROWSERSTACK_ACCESS_KEY" \
-DBROWSERSTACK_PROJECT_REPO="$REPO" >> "$WEB_LOG_FILE" 2>&1 || true
# cd testng-browserstack || return 1
# === 3️⃣ Update Base URL ===
if grep -qr "https://www.bstackdemo.com" .; then
log_msg_to "🌐 Updating base URL to $CX_TEST_URL" "$GLOBAL" "$WEB_LOG_FILE"
sed -i.bak "s|https://www.bstackdemo.com|$CX_TEST_URL|g" $(grep -rl "https://www.bstackdemo.com" .)
fi
# === 4️⃣ Local Flag ===
if [ "$local_flag" = "true" ]; then
log_msg_to "⚠️ BrowserStack Local is ENABLED for this run." "$GLOBAL" "$WEB_LOG_FILE"
else
log_msg_to "⚠️ BrowserStack Local is DISABLED for this run." "$GLOBAL" "$WEB_LOG_FILE"
fi
# === 5️⃣ YAML Setup ===
log_msg_to "🧩 Generating YAML config (bstack.yml)" "$GLOBAL" "$WEB_LOG_FILE"
platform_yaml=$(generate_web_platforms_yaml "$TEAM_PARALLELS_MAX_ALLOWED_WEB")
cat > browserstack.yml <<EOF
userName: $BROWSERSTACK_USERNAME
accessKey: $BROWSERSTACK_ACCESS_KEY
framework: testng
browserstackLocal: $local_flag
buildName: browserstack-sample-java-web
projectName: NOW-Web-Test
percy: true
accessibility: true
platforms:
$platform_yaml
parallelsPerPlatform: $parallels
EOF