11#! /usr/bin/env node
22/* eslint-disable-next-line no-unused-vars */
3+
4+ // Copyright (C) 2007-2025 Apple Inc. All rights reserved.
5+
6+ // Redistribution and use in source and binary forms, with or without
7+ // modification, are permitted provided that the following conditions
8+ // are met:
9+ // 1. Redistributions of source code must retain the above copyright
10+ // notice, this list of conditions and the following disclaimer.
11+ // 2. Redistributions in binary form must reproduce the above copyright
12+ // notice, this list of conditions and the following disclaimer in the
13+ // documentation and/or other materials provided with the distribution.
14+
15+ // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16+ // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17+ // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+ // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19+ // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+ // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+ // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+ // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25+ // THE POSSIBILITY OF SUCH DAMAGE.
26+
327import serve from "./server.mjs" ;
4- import { Builder , Capabilities } from "selenium-webdriver" ;
28+ import { Builder , Capabilities , logging } from "selenium-webdriver" ;
529import commandLineArgs from "command-line-args" ;
30+ import { promises as fs } from "fs" ;
31+ import path from "path" ;
32+ import os from "os" ;
633
734import { logInfo , logError , printHelp , runTest } from "./helper.mjs" ;
835
@@ -12,7 +39,6 @@ const optionDefinitions = [
1239 { name : "help" , alias : "h" , description : "Print this help text." } ,
1340] ;
1441
15-
1642const options = commandLineArgs ( optionDefinitions ) ;
1743
1844if ( "help" in options )
@@ -26,6 +52,7 @@ let capabilities;
2652switch ( BROWSER ) {
2753 case "safari" :
2854 capabilities = Capabilities . safari ( ) ;
55+ capabilities . set ( "safari:diagnose" , true ) ;
2956 break ;
3057
3158 case "firefox" : {
@@ -78,13 +105,15 @@ async function runEnd2EndTest(name, params) {
78105
79106async function testEnd2End ( params ) {
80107 const driver = await new Builder ( ) . withCapabilities ( capabilities ) . build ( ) ;
108+ const sessionId = ( await driver . getSession ( ) ) . getId ( ) ;
81109 const driverCapabilities = await driver . getCapabilities ( ) ;
82110 logInfo ( `Browser: ${ driverCapabilities . getBrowserName ( ) } ${ driverCapabilities . getBrowserVersion ( ) } ` ) ;
83111 const urlParams = Object . assign ( {
84112 worstCaseCount : 2 ,
85113 iterationCount : 3
86114 } , params ) ;
87115 let results ;
116+ let success = true ;
88117 try {
89118 const url = new URL ( `http://localhost:${ PORT } /index.html` ) ;
90119 url . search = new URLSearchParams ( urlParams ) . toString ( ) ;
@@ -102,9 +131,13 @@ async function testEnd2End(params) {
102131 results = await benchmarkResults ( driver ) ;
103132 // FIXME: validate results;
104133 } catch ( e ) {
134+ success = false ;
105135 throw e ;
106136 } finally {
107- driver . quit ( ) ;
137+ await driver . quit ( ) ;
138+ if ( ! success ) {
139+ await printLogs ( sessionId ) ;
140+ }
108141 }
109142}
110143
@@ -128,7 +161,6 @@ class JetStreamTestError extends Error {
128161 super ( `Tests failed: ${ errors . map ( e => e . stack ) . join ( ", " ) } ` ) ;
129162 this . errors = errors ;
130163 }
131-
132164}
133165
134166const UPDATE_INTERVAL = 250 ;
@@ -163,4 +195,28 @@ function logIncrementalResult(previousResults, benchmarkResults) {
163195 }
164196}
165197
198+ function printLogs ( sessionId ) {
199+ if ( BROWSER === "safari" && sessionId )
200+ return printSafariLogs ( sessionId ) ;
201+ }
202+
203+ async function printSafariLogs ( sessionId ) {
204+ const sessionLogDir = path . join ( os . homedir ( ) , "Library" , "Logs" , "com.apple.WebDriver" , sessionId ) ;
205+ try {
206+ const files = await fs . readdir ( sessionLogDir ) ;
207+ const logFiles = files . filter ( f => f . startsWith ( "safaridriver." ) && f . endsWith ( ".txt" ) ) ;
208+ if ( logFiles . length === 0 ) {
209+ logInfo ( `No safaridriver log files found in session directory: ${ sessionLogDir } ` ) ;
210+ return ;
211+ }
212+ for ( const file of logFiles ) {
213+ const logPath = path . join ( sessionLogDir , file ) ;
214+ const logContent = await fs . readFile ( logPath , "utf8" ) ;
215+ logGroup ( `SafariDriver Log: ${ file } ` , ( ) => console . log ( logContent ) ) ;
216+ }
217+ } catch ( err ) {
218+ logError ( "Error reading SafariDriver logs:" , err ) ;
219+ }
220+ }
221+
166222setImmediate ( runTests ) ;
0 commit comments