1
+ <!DOCTYPE html>
2
+ < html >
3
+
4
+ < head >
5
+ < title > Test Page Runner: open one Test URL at a time from a list of Test URLs.</ title >
6
+ </ head >
7
+
8
+ < body >
9
+ < script >
10
+ // Insert URLs and timeout dynamically
11
+ let urls = $$$URLS$$$ ;
12
+ let timeout = $$$TIMEOUT$$$ ;
13
+ let counter = 0 ;
14
+ let openWindow ;
15
+ let timeoutId ;
16
+ let urlParams = new URLSearchParams ( decodeURIComponent ( window . location . search ) ) ;
17
+ let browser_id = urlParams . get ( 'browser_id' ) || 1 ;
18
+ let run_id = urlParams . get ( 'run_id' ) || "unknown" ;
19
+
20
+ function closeCurrentWindow ( ) {
21
+ if ( openWindow ) {
22
+ openWindow . close ( ) ;
23
+ }
24
+ }
25
+
26
+ function openNextWindow ( ) {
27
+ closeCurrentWindow ( ) ;
28
+
29
+ if ( counter < urls . length ) {
30
+ // interpreted as: top=min,left=min,width=min,height=min
31
+ let url = urls [ counter ] ;
32
+ url = url . replace ( / b r o w s e r _ i d = \d + / , `browser_id=${ browser_id } ` ) ;
33
+ url_timeout = Math . max ( parseInt ( url . match ( / t i m e o u t = ( \d + ) / ) [ 1 ] , 10 ) * 1000 + 2000 , timeout ) ;
34
+ openWindow = window . open ( url , "_blank" , "top=0,left=0,width=100,height=100" ) ;
35
+ counter ++ ;
36
+ // Open the next test after the TIMEOUT
37
+ timeoutId = setTimeout ( function ( ) {
38
+ openNextWindow ( ) ;
39
+ } , url_timeout ) ;
40
+
41
+ } else {
42
+ console . log ( "Finished!" ) ;
43
+ // Append a "finished" div which we can await for in Selenium/Playwright based tests
44
+ d = document . createElement ( "div" ) ;
45
+ d . id = "finished" ;
46
+ document . body . style . backgroundColor = "green" ;
47
+ document . body . appendChild ( d ) ;
48
+
49
+ // Try to stop the page runner
50
+ fetch ( `${ location . origin } /_hp/server/notify_runner_clients.py?run_id=${ run_id } ` ) ;
51
+
52
+ }
53
+ }
54
+
55
+ function handleMessage ( event ) {
56
+ // If the test is finished, clear the timeout and directly start the next test
57
+ if ( event . data === 'finished' ) {
58
+ clearTimeout ( timeoutId ) ;
59
+ openNextWindow ( ) ;
60
+ }
61
+ }
62
+ window . addEventListener ( 'message' , handleMessage ) ;
63
+
64
+ // Open the first window
65
+ openNextWindow ( ) ;
66
+
67
+
68
+ </ script >
69
+ </ body >
70
+
71
+ </ html >
0 commit comments