@@ -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,21 @@ 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+ // Without it, we're getting an error:
75+ // SessionNotCreatedError: Could not create a session: Browser name does
76+ // not match (requested: safari; available: Safari Technology Preview)
77+ safariOptions . set ( "browserName" , "Safari Technology Preview" ) ;
78+ }
79+
5880 const ieOptions = new IE . Options ( ) ;
5981 ieOptions . setEdgeChromium ( true ) ;
6082 ieOptions . setEdgePath ( "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe" ) ;
@@ -84,9 +106,9 @@ export default async function createDriver( { browserName, headless, url, verbos
84106 chromeOptions . addArguments ( "--headless=new" ) ;
85107 firefoxOptions . addArguments ( "--headless" ) ;
86108 edgeOptions . addArguments ( "--headless=new" ) ;
87- if ( ! browserSupportsHeadless ( browserName ) ) {
109+ if ( ! browserSupportsHeadless ( effectiveBrowserName ) ) {
88110 console . log (
89- `Headless mode is not supported for ${ browserName } .` +
111+ `Headless mode is not supported for ${ effectiveBrowserName } .` +
90112 "Running in normal mode instead."
91113 ) ;
92114 }
0 commit comments