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::
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]});
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'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