2

How we instruct Selenium to use Safari Technology Preview in C#?

In Java, we can set that using the method setUseTechnologyPreview, but unable to find similar method in C# class SafariOptions.

We have tried by using options.AddAdditionalCapability('useTechnologyPreview', true), but it did not work.

BSMP
  • 3,862
  • 8
  • 31
  • 41
Jibu
  • 41
  • 5

3 Answers3

2

I ran into the same problem and there's not a lot of documentation available. It is possible, though. The webdriver executable lives inside the application for the preview. Set up a webdriver service to use it. (I have a few extra options included...)

SafariDriverService serv = SafariDriverService.CreateDefaultService("/Applications/Safari Technology Preview.app/Contents/MacOS/", "safaridriver");
                SafariOptions opts = new SafariOptions();
                opts.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
                opts.AddAdditionalCapability(CapabilityType.AcceptInsecureCertificates, true);
                opts.AddAdditionalCapability("cleanSession", true);
                webDriver = new SafariDriver(serv, opts);
  • Thanks for the reply. We are using Selenium grid to run the test and we are instantiating the driver as follows:- `driver = new RemoteWebDriver(new Uri(seleniumHostUrl), capabilities)` Could you please let us know how we can setup the driver service here. – Jibu Jun 20 '17 at 09:37
  • If anyone is looking for how to do it with Ruby and Capybara. Check here: https://stackoverflow.com/questions/44663481/how-to-setup-capybara-with-safari-technology-preview-in-ruby/44663482#44663482 – N D Jun 20 '17 at 21:41
0

For remote Selenium, we are using the following approach:

Dictionary<string, object> remoteSafariOptions = new Dictionary<string, object>();
remoteSafariOptions["technologyPreview"] = true;
safariOptions = new SafariOptions();
safariOptions.AddAdditionalCapability("safari.options", remoteSafariOptions);
browser = new RemoteWebDriver(new Uri(seleniumRemoteGridUrl), 
safariOptions.ToCapabilities());
0

You may need to set the browser names in the current versions of SafariDriver:

            var safariService = SafariDriverService.CreateDefaultService("/Applications/Safari Technology Preview.app/Contents/MacOS/", "safaridriver");
            var safariOptions = new SafariOptions();
           safariOptions.AddAdditionalCapability(CapabilityType.BrowserName, "Safari Technology Preview");
            driver = new SafariDriver(safariService, safariOptions);
Rushby
  • 807
  • 9
  • 17