Estas capacidades e características são específicas ao navegador Apple Safari.
Ao invés dos drivers para Chromium e Firefox, o safaridriver faz parte to sistema Operativo.
Para activar a automação no Safari, execute o seguinte comando no terminal:
safaridriver --enable
Opções
Capacidades comuns a todos os navegadores estão descritas na página Opções.
Capacidades únicas ao Safari podem ser encontradas na página da Apple WebDriver para Safari
Este é um exemplo de como iniciar uma sessão Safari com um conjunto de opções básicas::
# frozen_string_literal: truerequire'spec_helper'# rubocop:disable RSpec/MultipleDescribesRSpec.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'enables 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/)endendendRSpec.describe'Safari Technology Preview',skip:'This test is being skipped as GitHub Actions '\'have no support for Safari Technology Preview'doit'sets the technology preview'doSelenium::WebDriver::Safari.technology_preview!local_driver=Selenium::WebDriver.for:safariexpect(local_driver.capabilities.browser_name).toeq'Safari Technology Preview'endend# rubocop:enable RSpec/MultipleDescribes
constsafari=require('selenium-webdriver/safari');const{Browser,Builder}=require("selenium-webdriver");constoptions=newsafari.Options();constprocess=require('node:process');describe('Should be able to Test Command line arguments',function(){(process.platform==='darwin'?it:it.skip)('headless',asyncfunction(){letdriver=newBuilder().forBrowser(Browser.SAFARI).setSafariOptions(options).build();awaitdriver.get('https://www.selenium.dev/selenium/web/blank.html');awaitdriver.quit();});});
Se pretende automatizar Safari em iOS, deve olhar para o Projecto Appium.
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'# rubocop:disable RSpec/MultipleDescribesRSpec.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'enables 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/)endendendRSpec.describe'Safari Technology Preview',skip:'This test is being skipped as GitHub Actions '\'have no support for Safari Technology Preview'doit'sets the technology preview'doSelenium::WebDriver::Safari.technology_preview!local_driver=Selenium::WebDriver.for:safariexpect(local_driver.capabilities.browser_name).toeq'Safari Technology Preview'endend# rubocop:enable RSpec/MultipleDescribes
# frozen_string_literal: truerequire'spec_helper'# rubocop:disable RSpec/MultipleDescribesRSpec.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'enables 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/)endendendRSpec.describe'Safari Technology Preview',skip:'This test is being skipped as GitHub Actions '\'have no support for Safari Technology Preview'doit'sets the technology preview'doSelenium::WebDriver::Safari.technology_preview!local_driver=Selenium::WebDriver.for:safariexpect(local_driver.capabilities.browser_name).toeq'Safari Technology Preview'endend# rubocop:enable RSpec/MultipleDescribes