From 0bf746a3455c61313aeca0a75e9ee0877bc1661b Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 14 Jul 2023 01:15:13 -0700 Subject: [PATCH] feat: add acceptInsecureCerts as safaridriver 15.4+ have it (#63) * feat: add acceptInsecureCerts as safaridriver 15.4+ have it * Update README.md * fix: allow to pass standard caps, update readme * fix typo --- README.md | 4 ++-- lib/desired-caps.js | 3 +++ lib/utils.js | 3 +++ test/unit/utils-specs.js | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7f93f30..9d7067f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Under the hood this driver is a wrapper/proxy over Apple's `safaridriver` binary > **Note** > -> Since version 3.0.0 Safari driver has dropped the support of Appium 1, and is only compatible to Appium 2. Use the `appium driver install safari` +> Since version 3.0.0 Safari driver has dropped the support of Appium 1, and is only compatible to Appium 2. Use the `appium driver install safari` > command to add it to your Appium 2 dist. @@ -34,6 +34,7 @@ platformName | safaridriver binary can only create WebDriver sessions for deskto automationName | Value of automationName must equal to 'Safari' in order to start Safari driver session. Values of automationName are compared case-insensitively. browserName | safaridriver can only create WebDriver sessions for Safari. Any value passed to this capability will be changed to 'Safari'. browserVersion | safaridriver will only create a session using hosts whose Safari version matches the value of browserVersion. Browser version numbers are prefix-matched. For example, if the value of browserVersion is '12', this will allow hosts with a Safari version of '12.0.1' or '12.1'. +acceptInsecureCerts | Makes the browser to ignore the appropriate security warning and thus allows navigation to web sites having invalid or expired TLS certificates. The capability is supported since safaridriver v15.4. safari:platformVersion | safaridriver will only create a session using hosts whose OS version matches the value of safari:platformVersion. OS version numbers are prefix-matched. For example, if the value of safari:platformVersion is '12', this will allow hosts with an OS version of '12.0' or '12.1' but not '10.12'. safari:platformBuildVersion | safaridriver will only create a session using hosts whose OS build version matches the value of safari:platformBuildVersion. example of a macOS build version is '18E193'. On macOS, the OS build version can be determined by running the sw_vers(1) utility. safari:useSimulator | If the value of safari:useSimulator is true, safaridriver will only use iOS Simulator hosts. If the value of safari:useSimulator is false, safaridriver will not use iOS Simulator hosts. NOTE: An Xcode installation is required in order to run WebDriver tests on iOS Simulator hosts. @@ -153,4 +154,3 @@ npm install npm run lint npm run test ``` - diff --git a/lib/desired-caps.js b/lib/desired-caps.js index 319db45..6819061 100644 --- a/lib/desired-caps.js +++ b/lib/desired-caps.js @@ -5,6 +5,9 @@ const desiredCapConstraints = { browserVersion: { isString: true }, + acceptInsecureCerts: { + isBoolean: true + }, 'safari:platformVersion': { isString: true }, diff --git a/lib/utils.js b/lib/utils.js index 10da8cf..6b6d9ce 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,3 +1,4 @@ +import { STANDARD_CAPS } from 'appium/driver'; import _ from 'lodash'; const SAFARI_CAP_PREFIXES = ['safari:', 'webkit:']; @@ -11,6 +12,8 @@ function formatCapsForServer (caps) { for (const [name, value] of _.toPairs(caps)) { if (SAFARI_CAP_PREFIXES.some((prefix) => name.startsWith(prefix))) { result[name] = value; + } else if (!_.has(result, name) && STANDARD_CAPS.has(name)) { + result[name] = value; } } return result; diff --git a/test/unit/utils-specs.js b/test/unit/utils-specs.js index c112c39..8de3fdf 100644 --- a/test/unit/utils-specs.js +++ b/test/unit/utils-specs.js @@ -26,11 +26,12 @@ describe('formatCapsForServer', function () { }); }); - it('should only pass caps with supported prefixes', function () { + it('should only pass caps with supported prefixes and standard caps', function () { const result = formatCapsForServer({ 'safari:deviceUDID': '1234', 'webkit:yolo': '567', 'appium:bar': '789', + 'acceptInsecureCerts': true }); result.should.eql({ browserName: 'Safari', @@ -38,6 +39,7 @@ describe('formatCapsForServer', function () { platformName: 'iOS', 'safari:deviceUDID': '1234', 'webkit:yolo': '567', + 'acceptInsecureCerts': true }); }); });