These are capabilities and features specific to Apple Safari browsers.
Unlike Chromium and Firefox drivers, the safaridriver is installed with the Operating System.
To enable automation on Safari, run the following command from the terminal:
safaridriver --enable
Options
Capabilities common to all browsers are described on the Options page.
describe('Should be able to Test Command line arguments',function(){(process.platform==='darwin'?it:it.skip)('headless',asyncfunction(){letdriver=awaitenv.builder().setSafariOptions(options)
constsafari=require('selenium-webdriver/safari');const{Browser}=require("selenium-webdriver");const{suite}=require('selenium-webdriver/testing')constoptions=newsafari.Options();constprocess=require('node:process');suite(function(env){describe('Should be able to Test Command line arguments',function(){(process.platform==='darwin'?it:it.skip)('headless',asyncfunction(){letdriver=awaitenv.builder().setSafariOptions(options).build();awaitdriver.get('https://www.google.com');awaitdriver.quit();});});},{browsers:[Browser.SAFARI]});
Those looking to automate Safari on iOS should look to the Appium project.
Service
Service settings common to all browsers are described on the Service page.
Logging
Unlike other browsers, Safari doesn’t let you choose where logs are output, or change levels. The one option
available is to turn logs off or on. If logs are toggled on, they can be found at:~/Library/Logs/com.apple.WebDriver/.
Note: Java also allows setting console output by System Property; Property key: SafariDriverService.SAFARI_DRIVER_LOGGING Property value: "true" or "false"
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Safari',exclusive:{platform::macosx}dodescribe'Options'doit'basic options'dooptions=Selenium::WebDriver::Options.safari@driver=Selenium::WebDriver.for:safari,options:optionsendenddescribe'Service'dolet(:directory){"#{Dir.home}/Library/Logs/com.apple.WebDriver/*"}it'enable logs'dooriginal_count=Dir[directory].lengthservice=Selenium::WebDriver::Service.safariservice.args<<'--diagnose'@driver=Selenium::WebDriver.for:safari,service:serviceexpect(Dir[directory].length-original_count).toeq1endit'does not set log output'doservice=Selenium::WebDriver::Service.safariexpect{service.log=$stdout}.toraise_error(Selenium::WebDriver::Error::WebDriverError,/Safari Service does not support setting log output/)endendend
# frozen_string_literal: truerequire'spec_helper'RSpec.describe'Safari',exclusive:{platform::macosx}dodescribe'Options'doit'basic options'dooptions=Selenium::WebDriver::Options.safari@driver=Selenium::WebDriver.for:safari,options:optionsendenddescribe'Service'dolet(:directory){"#{Dir.home}/Library/Logs/com.apple.WebDriver/*"}it'enable logs'dooriginal_count=Dir[directory].lengthservice=Selenium::WebDriver::Service.safariservice.args<<'--diagnose'@driver=Selenium::WebDriver.for:safari,service:serviceexpect(Dir[directory].length-original_count).toeq1endit'does not set log output'doservice=Selenium::WebDriver::Service.safariexpect{service.log=$stdout}.toraise_error(Selenium::WebDriver::Error::WebDriverError,/Safari Service does not support setting log output/)endendend