yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
 
REM Flag for E2E Runner
SET E2E_MODE=true
SET E2E_TARGET=%~dp0\.\
 
REM e2e.bat version
SET E2E_BAT_VERSION=2.1.0-beta.1
 
REM Navigate to E2E_SETUP then E2E_START. E2E_UPDATE is on top to allow all attempts to abort the script
GOTO :E2E_SETUP
 
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
REM ===== This section are the default parameters and setup logic                                                     =====
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
 
 
:E2E_UPDATE_PROCESS
if not exist "%~dp0\e2e.update.bat" (
  GOTO :MISSING_UPDATE
)
 
call echo Updating e2e.bat since we managed to download the update
call move /Y "%~dp0\e2e.update.bat" "%~dp0\e2e.bat" & attrib -s -h -r "e2e.bat" /s /d
 
if "%~1" =="update" (
  GOTO :EXIT
)
 
GOTO :E2E_SETUPRESUME
 
:E2E_UPDATE
call echo Update e2e.bat
 
if exist "%~dp0\e2e.update.bat" (
  del /F /S /Q "%~dp0\e2e.update.bat"
)
 
call echo Processing copying of e2e.bat from "\\dsone.3ds.com\Quintiqbu$\R&D\Software\AutoTest\E2E\e2e.bat"
if exist "\\dsone.3ds.com\Quintiqbu$\R&D\Software\AutoTest\E2E\e2e.bat" (
  copy /B /V /Y /Z "\\dsone.3ds.com\Quintiqbu$\R&D\Software\AutoTest\E2E\e2e.bat" "%~dp0\e2e.update.bat"
)
 
if exist "%~dp0\e2e.update.bat" (
  GOTO :E2E_UPDATE_PROCESS
)
 
call echo Processing copying of e2e.bat from "\\dsone.3ds.com\Quintiqbu$\Global\Products\IndustrySolutions\Cross ISD\WebApp_E2E\E2E\e2e.bat"
if exist "\\dsone.3ds.com\Quintiqbu$\Global\Products\IndustrySolutions\Cross ISD\WebApp_E2E\E2E\e2e.bat" (
  copy /B /V /Y /Z "\\dsone.3ds.com\Quintiqbu$\Global\Products\IndustrySolutions\Cross ISD\WebApp_E2E\E2E\e2e.bat" "%~dp0\e2e.update.bat"
)
 
if exist "%~dp0\e2e.update.bat" (
  GOTO :E2E_UPDATE_PROCESS
)
 
call Ping widgetfactory.extranet.3ds.com  -n 1 -w 1000
if errorlevel 1 (
  call echo Internal network not found.
) else (
  call echo Processing downloading of e2e.bat from "https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/E2E/e2e.bat"
  powershell.exe -Command ^
  $WebClient = New-Object System.Net.WebClient ; ^
  $WebClient.DownloadFile('https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/E2E/e2e.bat', '%~dp0\e2e.update.bat')
 
  if exist "%~dp0\e2e.update.bat" (
    GOTO :E2E_UPDATE_PROCESS
  )
)
 
if not "%~1" =="update" (
  call echo Proceed execution
  GOTO :E2E_SETUPRESUME
)
 
 
 
 
 
REM Abort after update as the E2E_UPDATE will cause issues if there is a continuation
GOTO :MISSING_UPDATE
 
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
REM ===== This section are the default parameters and setup logic                                                     =====
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
 
:E2E_SETUP
  GOTO :E2E_UPDATE
:E2E_SETUPRESUME
SET E2E_ZIP_HANDLING_MODE=NULL
REM Check whether is E2ELib
for %%I in (.) do set CURRENT_FOLDER=%%~nxI
SET PUSH_PATH="%~dp0\e2elib"
 
REM set path for pointer
IF "%CURRENT_FOLDER%"=="e2elib" SET ISE2E=TRUE
IF "%CURRENT_FOLDER%"=="E2Elib" SET ISE2E=TRUE
 
IF "%ISE2E%"=="TRUE" SET PUSH_PATH="%~dp0"
 
 
REM These E2E_ARG* are designed to be usable by the Test executors by looking at the process.env.E2E_ARG...
REM  as there may be cases where the process.argv[?] is not passed along properly
SET E2E_ARG_1=%~1
SET E2E_ARG_2=%~2
SET E2E_ARG_3=%~3
SET E2E_ARG_4=%~4
SET E2E_ARG_5=%~5
SET E2E_ARG_6=%~6
SET E2E_ARG_7=%~7
SET E2E_ARG_8=%~8
SET E2E_ARG_9=%~9
SET E2E_ARGS=%*
 
REM Create this folder at root as this is the operating folder for the e2e.bat
if not exist "%CD:~0,2%\E2E-TOOLS" (
  mkdir "%CD:~0,2%\E2E-TOOLS"
)
 
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
REM ===== This section is the Start-up logic                                                                          =====
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
 
:E2E_START
REM If there are no arguments provided we will try to process the default behaviour
if "%~1" == "" (
  REM We support the e2elib.zip being placed in the same folder as the e2e.bat to allow immediate handling of the e2elib.zip extraction
  if exist "%~dp0\e2elib.zip" (
    call echo E2ELib.zip file is found, starting extraction before default run.
 
    REM Set the continuation of the ZIP handling
    SET E2E_ZIP_HANDLING_MODE=ZIP_LOCAL
    GOTO :ZIP_TOOL
  )
  if exist "%~dp0\e2elib" (
    REM Since the environment seems to be OK, we can trigger default run
    GOTO :RUN_DEFAULT
  )
 
  REM Go to missing start configuration
  GOTO :MISSING_START 
)
 
REM Convert argument to upper-case for comparison
SET FIRST_ARG=%~1
for %%a in ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I" "j=J" "k=K" "l=L"
            "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R" "s=S" "t=T" "u=U" "v=V" "w=W" "x=X"
            "y=Y" "z=Z" "ä=Ä" "ö=Ö" "ü=Ü") do (
  SET FIRST_ARG=!FIRST_ARG:%%~a!
)
 
REM If the first argument is RUN, we go to the RUN_COMMAND section
if "!FIRST_ARG!" == "RUN" (
  call echo Going to RUN command section
  GOTO :RUN_COMMAND
)
 
REM If the first argument is RUN, we go to the RUN_COMMAND section
if "!FIRST_ARG!" == "--RUN" (
  call echo Going to RUN command section
  GOTO :RUN_COMMAND
)
 
REM If the first argument is RUN, we go to the RUN_COMMAND section
if "!FIRST_ARG!" == "-R" (
  call echo Going to RUN command section
  GOTO :RUN_COMMAND
)
 
REM If the first argument is RUN, we go to the RUN_COMMAND section
if "!FIRST_ARG!" == "/RUN" (
  call echo Going to RUN command section
  GOTO :RUN_COMMAND
)
 
REM If the first argument is RUN, we go to the RUN_COMMAND section
if "!FIRST_ARG!" == "/R" (
  call echo Going to RUN command section
  GOTO :RUN_COMMAND
)
 
REM If the first argument is UPDATE, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "UPDATE" (
  GOTO :E2E_UPDATE
)
 
REM If the first argument is UPDATE, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "--UPDATE" (
  GOTO :E2E_UPDATE
)
 
REM If the first argument is UPDATE, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "-U" (
  GOTO :E2E_UPDATE
)
 
REM If the first argument is UPDATE, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "/UPDATE" (
  GOTO :E2E_UPDATE
)
 
REM If the first argument is UPDATE, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "/U" (
  GOTO :E2E_UPDATE
)
 
REM If the first argument is VERSION, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "VERSION" (
  GOTO :E2E_VERSION
)
 
REM If the first argument is VERSION, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "--VERSION" (
  GOTO :E2E_VERSION
)
 
REM If the first argument is VERSION, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "-V" (
  GOTO :E2E_VERSION
)
 
REM If the first argument is VERSION, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "/VERSION" (
  GOTO :E2E_VERSION
)
 
REM If the first argument is VERSION, we go to the E2E_UPDATE section
if "!FIRST_ARG!" == "/V" (
  GOTO :E2E_VERSION
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "HELP" (
  GOTO :E2E_HELP
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "--HELP" (
  GOTO :E2E_HELP
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "-H" (
  GOTO :E2E_HELP
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "/HELP" (
  GOTO :E2E_HELP
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "/H" (
  GOTO :E2E_HELP
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "?" (
  GOTO :E2E_HELP
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "--?" (
  GOTO :E2E_HELP
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "-?" (
  GOTO :E2E_HELP
)
 
REM If the first argument is HELP, we go to the E2E_HELP section
if "!FIRST_ARG!" == "/?" (
  GOTO :E2E_HELP
)
 
REM If the first argument is WEBDRIVER, we go to the WEBDRIVER section
if "!FIRST_ARG!" == "WEBDRIVER" (
  GOTO :WEBDRIVER
)
 
REM If the first argument is not a valid COMMAND, we check if it is the ZIP path for the e2elib.zip
if not exist "%CD:~0,2%\E2E-TOOLS\Download\" (
  mkdir "%CD:~0,2%\E2E-TOOLS\Download\"
)
if exist "%CD:~0,2%\E2E-TOOLS\Download\e2elib.zip" (
  del /F /S /Q "%CD:~0,2%\E2E-TOOLS\Download\e2elib.zip"
)
 
if exist "%~1" (
  if "%~nx1" == "e2elib.zip"  (
    call echo File path provided seems to exist, processing ZIP file handling
    GOTO :ZIP_TOOL
  ) 
  
  REM If the Path contain e2elib.zip, use it
  REM Enforce E2E.bat to update when extract new e2ezip
  if exist "%~1\e2elib.zip" (
 
    call echo Found e2elib.zip in given path "%~1"  , processing ZIP file handling
 
    call echo Copying e2elib to local drive to avoid issues for 7za at "%CD:~0,2%\E2E-TOOLS\Download\"
    REM Copy e2elib.zip to local drive to prevent issues as 7za.exe requires local file
    copy /B /V /Y /Z "%~1\e2elib.zip" "%CD:~0,2%\E2E-TOOLS\Download\"
    
    GOTO :ZIP_TOOL
  ) 
  
  REM IF the Path Exist but without e2elib.zip, we check it in latest directory
  For /F "Delims=" %%A In ('
    PowerShell -C "Get-ChildItem '%~1' | ?{ $_.PSIsContainer } | Select-Object -Expand Name | Sort-Object { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) } -Descending"
  ') Do (
    if exist "%~1\%%A\e2elib.zip" (
    call echo Found e2elib.zip in given path ="%~1"\%%A , processing ZIP file handling
 
    call echo Copying e2elib to local drive to avoid issues for 7za at "%CD:~0,2%\E2E-TOOLS\Download\"
    REM Copy e2elib.zip to local drive to prevent issues as 7za.exe requires local file
    copy /B /V /Y /Z "%~1\%%A\e2elib.zip" "%CD:~0,2%\E2E-TOOLS\Download\"
    
    GOTO :ZIP_TOOL
    )
  )
)
 
REM If we end up here we can assume the command in invalid
GOTO :INVALID_COMMAND
 
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
REM ===== This section is the ZIP handling logic                                                                      =====
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
 
:ZIP_TOOL
REM If the 7za folder is not available we need to create it
if not exist "%CD:~0,2%\E2E-TOOLS\7za1900" (
  mkdir "%CD:~0,2%\E2E-TOOLS\7za1900"
)
 
REM Check if we have 7za already
if exist "%CD:~0,2%\E2E-Tools\7za1900\7za.exe" (
  call echo Using existing copy of 7za.exe
  GOTO :ZIP_TOOL_DONE
)
call echo Processing copying of 7za to enable unzipping of resources from "\\dsone.3ds.com\Quintiqbu$\R&D\Software\AutoTest\7za1900"
 
REM Copy from Core Technology Department Shared Software directory, more restrictions
copy /B /V /Y /Z "\\dsone.3ds.com\Quintiqbu$\R&D\Software\AutoTest\7za1900" "%CD:~0,2%\E2E-Tools\7za1900"
 
REM Validate if copy is successful
if exist "%CD:~0,2%\E2E-Tools\7za1900\7za.exe" (
  GOTO :ZIP_TOOL_DONE
)
call echo Processing copying of 7za to enable unzipping of resources from "\\dsone.3ds.com\Quintiqbu$\Global\Products\IndustrySolutions\Cross ISD\WebApp_E2E\7za1900"
 
REM Copy from Application Development Team Shared directory, less restrictions
copy /B /V /Y /Z "\\dsone.3ds.com\Quintiqbu$\Global\Products\IndustrySolutions\Cross ISD\WebApp_E2E\7za1900" "%CD:~0,2%\E2E-Tools\7za1900"
 
REM Validate if copy is successful
if exist "%CD:~0,2%\E2E-Tools\7za1900\7za.exe" (
  GOTO :ZIP_TOOL_DONE
)
call echo Processing downloading of 7za to enable unzipping of resources from "https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/7za1900/"
 
REM We use PowerShell to process the download as this is the most universal approach
powershell.exe -Command ^
$WebClient = New-Object System.Net.WebClient ; ^
$WebClient.DownloadFile('https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/7za1900/7za.dll', '%CD:~0,2%\E2E-Tools\7za1900\7za.dll') ; ^
$WebClient.DownloadFile('https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/7za1900/7zxa.dll', '%CD:~0,2%\E2E-Tools\7za1900\7zxa.dll') ; ^
$WebClient.DownloadFile('https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/7za1900/7za.exe', '%CD:~0,2%\E2E-Tools\7za1900\7za.exe') ; ^
$WebClient.DownloadFile('https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/7za1900/history.txt', '%CD:~0,2%\E2E-Tools\7za1900\history.txt') ; ^
$WebClient.DownloadFile('https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/7za1900/License.txt', '%CD:~0,2%\E2E-Tools\7za1900\License.txt') ; ^
$WebClient.DownloadFile('https://widgetfactory.extranet.3ds.com/api/download/WebDAV/file/WebAppRelease/public/7za1900/readme.txt', '%CD:~0,2%\E2E-Tools\7za1900\readme.txt')
 
REM Validate if download is successful
if exist "%CD:~0,2%\E2E-Tools\7za1900\7za.exe" (
  GOTO :ZIP_TOOL_DONE
)
 
REM If we end up here when processing the ZIP_TOOL, we likely failed to automatically retrieve the executable
GOTO :MISSING_7ZA
 
:ZIP_TOOL_DONE
if "!E2E_ZIP_HANDLING_MODE!" == "ZIP_LOCAL" (
  REM Go to ZIP_LOCAL step after ZIP_TOOL is ready
  GOTO :ZIP_LOCAL
)
REM Continue to ZIP_COPY step after ZIP_TOOL is ready
 
:ZIP_COPY
call echo testing
call echo Extracting e2elib.zip
 
for %%I in (.) do set CURRENT_FOLDER=%%~nxI
 
REM set path for pointer
IF "%CURRENT_FOLDER%"=="e2elib" SET ISE2E=TRUE
IF "%CURRENT_FOLDER%"=="E2Elib" SET ISE2E=TRUE
 
REM Use 7za.exe to extract zip
call "%CD:~0,2%\E2E-Tools\7za1900\7za.exe" x -aoa -y -o"%~dp0" "%CD:~0,2%\E2E-TOOLS\Download\e2elib.zip"
if "%ISE2E%" == "TRUE" (
  call xcopy /r /y /s /i "%~dp0\e2elib\quintiq_modules" "%~dp0\quintiq_modules" > nul
) else (
  if exist "%~dp0\e2elib\e2elocalconfig.json" (
    call echo Copy config for vscode to e2e
    copy /B /V /Y /Z "%~dp0\e2elib\e2elocalconfig.json" "%~dp0\tsconfig.json"
  )
)
 
REM Remove Model in e2elib
call Rmdir /Q /S "%~dp0\e2elib\model"
 
REM End of ZIP_COPY
GOTO :EXIT
 
:ZIP_LOCAL
call echo Extracting e2elib.zip
 
REM Use 7za.exe to extract zip
call "%CD:~0,2%\E2E-Tools\7za1900\7za.exe" x -aoa -y -o"%~dp0" "%~dp0\e2elib.zip"
if "%ISE2E%" == "TRUE" (
 call xcopy /r /y /s /i "%~dp0\e2elib\quintiq_modules" "%~dp0\quintiq_modules" > nul
) else (
  if exist "%~dp0\e2elib\e2elocalconfig.json" (
    call echo Copy config for vscode to e2e
    copy /B /V /Y /Z "%~dp0\e2elib\e2elocalconfig.json" "%~dp0\tsconfig.json"
  )
)
 
 
REM End of ZIP_LOCAL
GOTO :EXIT
 
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
REM ===== This section is the RUN command                                                                             =====
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
 
:RUN_DEFAULT
call echo Executing default run
 
REM Configure RUN argument
SET SECOND_ARG=CHROME
 
REM Start RUN execution by skipping RUN_COMMAND processing
GOTO :RUN_EXECUTION
 
:RUN_COMMAND
REM Convert argument to upper-case for comparison
SET SECOND_ARG=%~2
for %%a in ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I" "j=J" "k=K" "l=L"
            "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R" "s=S" "t=T" "u=U" "v=V" "w=W" "x=X"
            "y=Y" "z=Z" "ä=Ä" "ö=Ö" "ü=Ü") do (
  SET SECOND_ARG=!SECOND_ARG:%%~a!
)
 
:RUN_EXECUTION
if not "%ISE2E%" == "TRUE" (
  if not exist "%~dp0\e2elib\" (
    REM Failure to find the e2elib
    GOTO :MISSING_E2ELIB
  )  
)
 
REM Validate if the request is to run the TypeScript compiler
if "!SECOND_ARG!" == "TSC" (
  call echo Triggering TypeScript compilation
  call echo.
 
  pushd %PUSH_PATH%
  IF "%ISE2E%"=="TRUE" (
   call npm run tsc %3 %4 %5 %6 %7 %8 %9
  ) ELSE (
   call npm run e2e:tsc %3 %4 %5 %6 %7 %8 %9
  )
  
  popd
 
  call echo.
  call echo TypeScript compilation completed, exiting...
 
  REM End of RUN_TSC
  GOTO :EXIT
)
 
if "!SECOND_ARG!" == "CLEAN" (
  call echo Triggering TypeScript cleaning
  call echo.
 
  pushd %PUSH_PATH%
  IF "%ISE2E%"=="TRUE" (
   call npm run clean %3 %4 %5 %6 %7 %8 %9
  ) ELSE (
   call npm run e2e:clean %3 %4 %5 %6 %7 %8 %9
  )
  
  popd
 
  call echo.
  call echo TypeScript cleaning completed, exiting...
 
  REM End of RUN_CLEAN
  GOTO :EXIT
)
 
REM Validate if the request is to run the TypeScript code linter
if "!SECOND_ARG!" == "LINT" (
  call echo Triggering TypeScript code linter
  call echo.
 
  pushd %PUSH_PATH%
  IF "%ISE2E%"=="TRUE" (
   call npm run lint %3 %4 %5 %6 %7 %8 %9
  ) ELSE (
   call npm run e2e:lint %3 %4 %5 %6 %7 %8 %9
  )
  popd
 
  call echo.
  call echo TypeScript code linting completed, exiting...
 
  REM End of RUN_LINT
  GOTO :EXIT
)
 
REM Validate if the request is to run the LOCAL run
if "!SECOND_ARG!" == "LOCAL" (
  call echo Triggering Local run
  call echo.
 
  pushd %PUSH_PATH%
  REM skip the argument %3 if it is not started with --
  IF "%E2E_ARG_3:~0,2%"=="--" (
    call npm run e2e:local -- %3 %4 %5 %6 %7 %8 %9
  ) else (
    call npm run e2e:local -- %4 %5 %6 %7 %8 %9
  )
 
  popd
 
  call echo.
  call echo Local run completed, exiting...
 
  REM End of RUN_LOCAL
  GOTO :EXIT
)
 
REM Validate if the request is to run the CHROME run
if "!SECOND_ARG!" == "CHROME" (
  call echo Triggering Chrome run
  call echo.
 
  pushd %PUSH_PATH%
  REM skip the argument %3 if it is not started with --
  IF "%E2E_ARG_3:~0,2%"=="--" (
    call npm run e2e:chrome -- %3 %4 %5 %6 %7 %8 %9
  ) else (
    call npm run e2e:chrome -- %4 %5 %6 %7 %8 %9
  )
  
  popd
 
  call echo.
  call echo Chrome run completed, exiting...
 
  REM End of RUN_CHROME
  GOTO :EXIT
)
 
REM Validate if the request is to run the FIREFOX run
if "!SECOND_ARG!" == "FIREFOX" (
  call echo Triggering Firefox run
  call echo.
 
  pushd %PUSH_PATH%
  REM skip the argument %3 if it is not started with --
  IF "%E2E_ARG_3:~0,2%"=="--" (
     call npm run e2e:firefox -- %3 %4 %5 %6 %7 %8 %9
  ) else (
     call npm run e2e:firefox -- %4 %5 %6 %7 %8 %9
  )
 
  popd
 
  call echo.
  call echo Chrome run completed, exiting...
 
  REM End of RUN_FIREFOX
  GOTO :EXIT
)
 
REM Validate if the request is to run the MSEDGE run
if "!SECOND_ARG!" == "EDGE" (
  call echo Triggering MSEdge run
  call echo.
 
  pushd %PUSH_PATH%
  REM skip the argument %3 if it is not started with --
  IF "%E2E_ARG_3:~0,2%"=="--" (
     call npm run e2e:msedge -- %3 %4 %5 %6 %7 %8 %9
  ) else (
     call npm run e2e:msedge -- %4 %5 %6 %7 %8 %9
  )
 
  popd
 
  call echo.
  call echo Chrome run completed, exiting...
 
  REM End of RUN_FIREFOX
  GOTO :EXIT
)
 
REM Validate if the request is to run the FIREFOX run
if "!SECOND_ARG!" == "BROWSERS" (
  call echo Triggering cross browsers run
  call echo.
 
  pushd %PUSH_PATH%
  REM skip the argument %3 if it is not started with --
  IF "%E2E_ARG_3:~0,2%"=="--" (
     call npm run e2e:browsers -- %3 %4 %5 %6 %7 %8 %9
  ) else (
     call npm run e2e:browsers -- %4 %5 %6 %7 %8 %9
  )
 
  popd
 
  call echo.
  call echo Chrome run completed, exiting...
 
  REM End of RUN_FIREFOX
  GOTO :EXIT
)
 
REM The RUN_COMMAND will end up here if the COMMAND is invalid
GOTO :UNKNOWN_COMMAND
 
REM The WEBDRIVER will performance webdriver-manager update and star the webdriver-manager
:WEBDRIVER
pushd %PUSH_PATH%
 
REM Download MSEdgeDriver
FOR /F "TOKENS=1-2* SKIP=2" %%A IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Edge\BLBeacon" /v version') DO SET QUERY_OUTPUT=%%C
 
call echo Processing downloading of microsoft edge driver from "https://msedgedriver.azureedge.net/%QUERY_OUTPUT%/edgedriver_win64.zip"
call echo Tempory disable due to VM not able to download
REM powershell.exe -Command ^
REM [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12^
 
REM $WebClient = New-Object System.Net.WebClient ; ^
REM $WebClient.DownloadFile('https://msedgedriver.azureedge.net/%QUERY_OUTPUT%/edgedriver_win64.zip', '.\edgedriver_win64.zip')
 
REM call echo Unzip the edge driver
REM powershell.exe -Command ^
REM Expand-Archive -LiteralPath .\edgedriver_win64.zip -DestinationPath . -Force
 
REM call "%CD:~0,2%\E2E-Tools\7za1900\7za.exe" x -aoa -y -o".\" ".\edgedriver_win64.zip"
 
REM Tempory implementation for the scripts that might not have the latest webdriver-manager 13.0.0
FOR /F "TOKENS=1-2* SKIP=2" %%A IN ('reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version') DO SET QUERY_OUTPUT=%%C
FOR /F "tokens=*" %%g IN ('node node_modules\webdriver-manager\bin\webdriver-manager --version') do (set webDriverVersion=%%g)
 
IF "%QUERY_OUTPUT:~0,3%" == "91." (
  SET QUERY_OUTPUT=90.0.4430.218
)
 
call node node_modules\webdriver-manager\bin\webdriver-manager update --versions.chrome=%QUERY_OUTPUT% --versions.standalone=3.141.59
IF %webDriverVersion% == 13.0.0 (
call start node node_modules\webdriver-manager\bin\webdriver-manager start --edge=".\msedgedriver.exe"
) ELSE (
call start node node_modules\webdriver-manager\bin\webdriver-manager start --versions.chrome=%QUERY_OUTPUT% --edge=".\msedgedriver.exe"
)
popd
 
REM The WEBDRIVER will end here
GOTO :EXIT
 
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
REM ===== This section are all the messages                                                                           =====
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
 
:E2E_HELP
call echo.
call echo ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
call echo =====                                                   E2E.BAT                                                   =====
call echo ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
call echo.
call echo Welcome to the "e2e.bat", where this script is developed to assist you in setting up the Web Application End-to-End
call echo  Testing environment to enable you to run your test.
call echo.
call echo.
call echo ===== Requirements                                                                                                =====
call echo.
call echo Please take note that this "e2e.bat" has the requirement of running beside the "e2e" folder where the "e2e" test
call echo  scripts are developed and stored.
call echo.
call echo The assumption is that the location of this "e2e.bat" and the "e2e" scripts are at the following location:
call echo - [MODEL]\_Main\Sys\Definitions
call echo.
call echo Environment requirement will be that there must be Node.JS installed on your machine and is accessible from the console.
call echo.
call echo Please go to "https://nodejs.org/en/" and download the "LTS", version 8.00 or higher.
call echo Ensure that you install Node.JS and the "node" and "npm" commands are available in the console.
call echo The important part is that this script executes the following executable "npm" to manage the "e2e" scripts.
call echo.
call echo.
call echo ===== Available Commands                                                                                          =====
call echo.
call echo There are several ways to use this "e2e.bat":
call echo - Start the "e2e.bat" with no arguments when the environment is already configured to trigger the "run chrome" action.
call echo   CONSOLE: e2e
call echo - Start the "e2e.bat" with the path to the e2elib.zip to enable the downloading and extraction of the e2elib.
call echo   CONSOLE: e2e "\\dsone.3ds.com\Quintiqbu$\R&D\Projects\Web Client\_RELEASE_\197613\e2elib.zip"
call echo - Start the "e2e.bat" with commands and sub-commands, more in the table later.
call echo   CONSOLE: e2e help
call echo   CONSOLE: e2e run tsc
call echo.
call echo These are the available commands and sub-commands:
call echo  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
call echo :  COMMAND  :    SUB    :            DESCRIPTION            :
call echo  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
call echo : help      :           : Shows this help page              :
call echo  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
call echo : version   :           : Gets the current version          :
call echo  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
call echo : update    :           : Update this e2e.bat               :
call echo  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
call echo : webdriver :           : Update and run the webdriver      :
call echo  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
call echo : run       :           : NPM based run action group        :
call echo :           : tsc       : Run E2E TypeScript compilation    :
call echo :           : lint      : Run E2E TypeScript code linting   :
call echo :           : local     : Run E2E Local test action         :
call echo :           : chrome    : Run E2E Local Chrome test action  :
call echo :           : firefox   : Run E2E Local Firefox test action :
call echo :           : edge      : Run E2E Local MSEdge test action  :
call echo :           : browsers  : Run E2E Local chrome and firefox  :
call echo  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
call echo.
 
REM End of E2E_VERSION
GOTO :EOF
 
:E2E_VERSION
call echo e2e.bat, version %E2E_BAT_VERSION%
 
REM End of E2E_VERSION
GOTO :EOF
 
:MISSING_START
call echo.
call echo Please provide either a Path to an E2ELib or start with the "run" command
call echo Only of the E2ELib folder is found beside this script can this script execute the default run without arguments
call echo.
 
REM End of MISSING_START
GOTO :EXIT
 
:MISSING_UPDATE
call echo.
call echo Failed to retrieve latest e2e.bat from the locations mentioned above
call echo Please either attempt to do this manually or file a support request
call echo.
 
REM End of MISSING_UPDATE
GOTO :EXIT
 
:MISSING_E2ELIB
call echo.
call echo Attempted to execute the RUN command but the e2elib is not found
call echo.
 
REM End of MISSING_E2ELIB
GOTO :EXIT
 
:MISSING_7ZA
call echo.
call echo Failed to really download or copy the 7za.exe
call echo.
call echo Please go to "https://www.7-zip.org/download.html" and download the "7-Zip Extra", version 19.00 or higher.
call echo Ensure that you extract the contents of "7z1900-extra.7z" to the "%CD:~0,2%\E2E-Tools\7za1900" and make sure that the "7za.exe" is available.
call echo The important part is that this script executes the following executable "%CD:~0,2%\E2E-Tools\7za1900\7za.exe" for ZIP file extraction.
call echo.
 
REM End of MISSING_7ZA
GOTO :EXIT
 
:UNKNOWN_COMMAND
call echo.
call echo Unknown RUN command: %~2
call echo.
 
REM End of UNKNOWN_COMMAND
GOTO :EXIT
 
:INVALID_COMMAND
call echo.
call echo Invalid file path or command, exiting...
call echo.
 
REM End of INVALID_COMMAND
GOTO :EXIT
 
:UPDATE_UNZIP
REM Unzip the e2elib.zip if exist
IF EXIST "%CD:~0,2%\E2E-TOOLS\Download\e2elib.zip" (
 GOTO :ZIP_TOOL
) ELSE (
 GOTO :EOF
)
 
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
REM ===== This is the end of file or exit handling                                                                    =====
REM ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
 
:EXIT
call echo Exiting...
ENDLOCAL