@@ -2,20 +2,27 @@ import { Builder, Capabilities, logging } from "selenium-webdriver";
22import Chrome from "selenium-webdriver/chrome.js" ;
33import Edge from "selenium-webdriver/edge.js" ;
44import Firefox from "selenium-webdriver/firefox.js" ;
5+ import Safari from "selenium-webdriver/safari.js" ;
56import IE from "selenium-webdriver/ie.js" ;
67import { browserSupportsHeadless } from "../lib/getBrowserString.js" ;
78
89// Set script timeout to 10min
910const DRIVER_SCRIPT_TIMEOUT = 1000 * 60 * 10 ;
1011
1112export default async function createDriver ( { browserName, headless, url, verbose } ) {
12- const capabilities = Capabilities [ browserName ] ( ) ;
13+
14+ // Support: Safari Technology Preview
15+ // Handle safari_tp as safari with a custom binary path
16+ const isSafariPreview = browserName === "safari_tp" ;
17+ const effectiveBrowserName = isSafariPreview ? "safari" : browserName ;
18+
19+ const capabilities = Capabilities [ effectiveBrowserName ] ( ) ;
1320
1421 // Support: IE 11+
1522 // When those are set for IE, the process crashes with an error:
1623 // "Unable to match capability set 0: goog:loggingPrefs is an unknown
1724 // extension capability for IE".
18- if ( browserName !== "ie" ) {
25+ if ( effectiveBrowserName !== "ie" ) {
1926 const prefs = new logging . Preferences ( ) ;
2027 prefs . setLevel ( logging . Type . BROWSER , logging . Level . ALL ) ;
2128 capabilities . setLoggingPrefs ( prefs ) ;
@@ -55,6 +62,16 @@ export default async function createDriver( { browserName, headless, url, verbos
5562 edgeOptions . setEdgeChromiumBinaryPath ( process . env . EDGE_BIN ) ;
5663 }
5764
65+ const safariOptions = new Safari . Options ( ) ;
66+
67+ // Use Safari Technology Preview if safari_tp browser is selected
68+ if ( isSafariPreview ) {
69+ if ( verbose ) {
70+ console . log ( "Using Safari Technology Preview" ) ;
71+ }
72+ safariOptions . setTechnologyPreview ( true ) ;
73+ }
74+
5875 const ieOptions = new IE . Options ( ) ;
5976 ieOptions . setEdgeChromium ( true ) ;
6077 ieOptions . setEdgePath ( "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe" ) ;
@@ -84,26 +101,39 @@ export default async function createDriver( { browserName, headless, url, verbos
84101 chromeOptions . addArguments ( "--headless=new" ) ;
85102 firefoxOptions . addArguments ( "--headless" ) ;
86103 edgeOptions . addArguments ( "--headless=new" ) ;
87- if ( ! browserSupportsHeadless ( browserName ) ) {
104+ if ( ! browserSupportsHeadless ( effectiveBrowserName ) ) {
88105 console . log (
89- `Headless mode is not supported for ${ browserName } .` +
106+ `Headless mode is not supported for ${ effectiveBrowserName } .` +
90107 "Running in normal mode instead."
91108 ) ;
92109 }
93110 }
94111
95- const builder = new Builder ( ) . withCapabilities ( capabilities )
96- . setChromeOptions ( chromeOptions )
97- . setFirefoxOptions ( firefoxOptions )
98- . setEdgeOptions ( edgeOptions )
99- . setIeOptions ( ieOptions ) ;
112+ let driver ;
113+
114+ // For Safari Technology Preview, use Safari.Driver.createSession directly
115+ // as it properly handles the Technology Preview executable
116+ if ( isSafariPreview ) {
117+
118+ // Safari Technology Preview reports its browser name as "Safari Technology Preview"
119+ // so we need to update the capabilities to match
120+ safariOptions . set ( "browserName" , "Safari Technology Preview" ) ;
121+ driver = Safari . Driver . createSession ( safariOptions ) ;
122+ } else {
123+ const builder = new Builder ( ) . withCapabilities ( capabilities )
124+ . setChromeOptions ( chromeOptions )
125+ . setFirefoxOptions ( firefoxOptions )
126+ . setEdgeOptions ( edgeOptions )
127+ . setSafariOptions ( safariOptions )
128+ . setIeOptions ( ieOptions ) ;
129+
130+ if ( ieService ) {
131+ builder . setIeService ( ieService ) ;
132+ }
100133
101- if ( ieService ) {
102- builder . setIeService ( ieService ) ;
134+ driver = builder . build ( ) ;
103135 }
104136
105- const driver = builder . build ( ) ;
106-
107137 if ( verbose ) {
108138 const driverCapabilities = await driver . getCapabilities ( ) ;
109139 const name = driverCapabilities . getBrowserName ( ) ;
0 commit comments