appium-safari-driver 1.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.azure-pipelines.yml +30 -0
- package/.eslintignore +2 -0
- package/.eslintrc +3 -0
- package/.github/dependabot.yml +11 -0
- package/README.md +138 -13
- package/azure-templates/node_setup_steps.yml +6 -0
- package/build/index.js +32 -31
- package/build/lib/commands/find.js +16 -473
- package/build/lib/commands/index.js +13 -65
- package/build/lib/desired-caps.js +48 -0
- package/build/lib/driver.js +58 -198
- package/build/lib/logger.js +12 -7
- package/build/lib/safari.js +197 -0
- package/build/lib/server.js +23 -30
- package/build/lib/utils.js +19 -273
- package/build/test/functional/desktop-driver-e2e-specs.js +56 -0
- package/build/test/functional/mobile-driver-e2e-specs.js +83 -0
- package/build/test/unit/driver-specs.js +20 -0
- package/build/test/unit/utils-specs.js +51 -0
- package/build/test/utils.js +18 -0
- package/gulpfile.js +10 -4
- package/index.js +8 -11
- package/lib/commands/find.js +10 -199
- package/lib/commands/index.js +8 -24
- package/lib/desired-caps.js +37 -0
- package/lib/driver.js +57 -62
- package/lib/logger.js +3 -2
- package/lib/safari.js +175 -0
- package/lib/server.js +7 -8
- package/lib/utils.js +13 -131
- package/package.json +47 -32
- package/test/functional/desktop-driver-e2e-specs.js +48 -0
- package/test/functional/mobile-driver-e2e-specs.js +73 -0
- package/test/unit/driver-specs.js +9 -0
- package/test/unit/utils-specs.js +43 -0
- package/test/utils.js +5 -0
- package/.jscsrc +0 -11
- package/.jshintrc +0 -11
- package/.npmignore +0 -2
- package/LICENSE +0 -13
- package/build/lib/commands/alert.js +0 -134
- package/build/lib/commands/context.js +0 -1135
- package/build/lib/commands/element.js +0 -452
- package/build/lib/commands/execute.js +0 -198
- package/build/lib/commands/general.js +0 -362
- package/build/lib/commands/gesture.js +0 -851
- package/build/lib/commands/logging.js +0 -96
- package/build/lib/commands/navigation.js +0 -101
- package/build/lib/commands/orientation.js +0 -74
- package/build/lib/commands/safari.js +0 -99
- package/build/lib/commands/screenshot.js +0 -169
- package/build/lib/commands/web.js +0 -1125
- package/build/test/functional/driver-e2e-specs.js +0 -186
- package/build/test/unit/webdriveragent-specs.js +0 -17
- package/lib/commands/alert.js +0 -49
- package/lib/commands/context.js +0 -447
- package/lib/commands/element.js +0 -158
- package/lib/commands/execute.js +0 -83
- package/lib/commands/general.js +0 -143
- package/lib/commands/gesture.js +0 -402
- package/lib/commands/logging.js +0 -40
- package/lib/commands/navigation.js +0 -34
- package/lib/commands/orientation.js +0 -28
- package/lib/commands/safari.js +0 -55
- package/lib/commands/screenshot.js +0 -60
- package/lib/commands/web.js +0 -446
- package/test/.jshintrc +0 -22
- package/test/functional/driver-e2e-specs.js +0 -69
- package/test/unit/webdriveragent-specs.js +0 -9
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/macos/
|
|
2
|
+
variables:
|
|
3
|
+
VM_IMAGE: macOS-10.15
|
|
4
|
+
XCODE_VERSION: 12.1
|
|
5
|
+
PLATFORM_VERSION: 14.1
|
|
6
|
+
DEVICE_NAME: iPhone 11 Pro Max
|
|
7
|
+
DEFAULT_NODE_VERSION: "12.x"
|
|
8
|
+
|
|
9
|
+
pool:
|
|
10
|
+
vmImage: "$(VM_IMAGE)"
|
|
11
|
+
|
|
12
|
+
stages:
|
|
13
|
+
- stage: Unit_Tests_And_Linters
|
|
14
|
+
jobs:
|
|
15
|
+
- job: Node_Unit_Tests
|
|
16
|
+
steps:
|
|
17
|
+
- template: azure-templates/node_setup_steps.yml
|
|
18
|
+
- script: npm install
|
|
19
|
+
- script: npm run test
|
|
20
|
+
|
|
21
|
+
- stage: Integration_Tests
|
|
22
|
+
jobs:
|
|
23
|
+
- job: Node_Integration_Tests
|
|
24
|
+
variables:
|
|
25
|
+
CI: true
|
|
26
|
+
_FORCE_LOGS: 1
|
|
27
|
+
steps:
|
|
28
|
+
- template: azure-templates/node_setup_steps.yml
|
|
29
|
+
- script: npm install
|
|
30
|
+
- script: npm run e2e-test
|
package/.eslintignore
ADDED
package/.eslintrc
ADDED
package/README.md
CHANGED
|
@@ -1,21 +1,146 @@
|
|
|
1
|
-
appium-
|
|
2
|
-
|
|
1
|
+
appium-safari-driver
|
|
2
|
+
====
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
This is Appium driver for automating Safari on [Mac OS X](https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari?language=objc) and iOS [since version 13](https://webkit.org/blog/9395/webdriver-is-coming-to-safari-in-ios-13/).
|
|
5
|
+
The driver only supports Safari automation using [W3C WebDriver protocol](https://www.w3.org/TR/webdriver/).
|
|
6
|
+
Under the hood this driver is a wrapper/proxy over Apple's `safaridriver` binary. Check the output of `man safaridriver` command to get more details on the supported features and possible pitfalls.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
driver-e2e-specs.js requires that a simulator is already running, and is running safari.
|
|
9
|
-
It didn't make much sense to add the simulator start/stop functionality to this driver since it's not quite a standalone driver but more for proxying to from other running drivers.
|
|
8
|
+
## Usage
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
It is mandatory to run the `safaridriver --enable` command from the Mac OS terminal and provide your administrator password before any automated session will be executed.
|
|
11
|
+
In order to automate Safari on real devices it is also necessary to enable Remote Automation switch in `Settings → Safari → Advanced → Remote Automation` for these particular devices.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
Then you need to decide where the automated test is going to be executed. Safari driver supports the following target platforms:
|
|
14
|
+
- Mac OS (High Sierra or newer)
|
|
15
|
+
- iOS Simulator (iOS version 13 or newer)
|
|
16
|
+
- iOS Real Device (iOS version 13 or newer)
|
|
17
|
+
|
|
18
|
+
Safari driver allows to define multiple criterions for platform selection and also to fine-tune your automation session properties. This could be done via the following session capabilities:
|
|
19
|
+
|
|
20
|
+
Capability Name | Description
|
|
21
|
+
--- | ---
|
|
22
|
+
platformName | safaridriver binary can only create WebDriver sessions for desktop or mobile Safari and can only run on Mac OS. Value of platformName could equal to 'Mac' or 'iOS' in order to start Safari driver session for the corresponding platform. Values of platformName are compared case-insensitively.
|
|
23
|
+
automationName | Value of automationName must equal to 'Safari' in order to start Safari driver session. Values of automationName are compared case-insensitively.
|
|
24
|
+
browserName | safaridriver can only create WebDriver sessions for Safari. Any value passed to this capability will be changed to 'Safari'.
|
|
25
|
+
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'.
|
|
26
|
+
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'.
|
|
27
|
+
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.
|
|
28
|
+
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.
|
|
29
|
+
safari:deviceType | If the value of safari:deviceType is 'iPhone', safaridriver will only create a session using an iPhone device or iPhone simulator. If the value of safari:deviceType is 'iPad', safaridriver will only create a session using an iPad device or iPad simulator. Values of safari:deviceType are compared case-insensitively.
|
|
30
|
+
safari:deviceName | safaridriver will only create a session using hosts whose device name matches the value of safari:deviceName. Device names are compared case-insensitively. NOTE: Device names for connected devices are shown in iTunes. If Xcode is installed, device names for connected devices are available via the output of instruments(1) and in the Devices and Simulators window (accessed in Xcode via "Window > Devices and Simulators").
|
|
31
|
+
safari:deviceUDID | safaridriver will only create a session using hosts whose device UDID matches the value of safari:deviceUDID. Device UDIDs are compared case-insensitively. NOTE: If Xcode is installed, UDIDs for connected devices are available via the output of instruments(1) and in the Devices and Simulators window (accessed in Xcode via "Window > Devices and Simulators").
|
|
32
|
+
safari:automaticInspection | This capability instructs Safari to preload the Web Inspector and JavaScript debugger in the background prior to returning a newly-created window. To pause the test's execution in JavaScript and bring up Web Inspector's Debugger tab, you can simply evaluate a debugger; statement in the test page.
|
|
33
|
+
safari:automaticProfiling | This capability instructs Safari to preload the Web Inspector and start a Timeline recording in the background prior to returning a newly-created window. To view the recording, open the Web Inspector through Safari's Develop menu.
|
|
34
|
+
webkit:WebRTC | This capability allows a test to temporarily change Safari's policies for WebRTC and Media Capture. The value of the webkit:WebRTC capability is a dictionary with the following sub-keys, all of which are optional: `DisableInsecureMediaCapture` - Normally, Safari refuses to allow media capture over insecure connections. This restriction is relaxed by default for WebDriver sessions for testing purposes (for example, a test web server not configured for HTTPS). When this capability is specified, Safari will revert to the normal behavior of preventing media capture over insecure connections. `DisableICECandidateFiltering` - To protect a user's privacy, Safari normally filters out WebRTC ICE candidates that correspond to internal network addresses when capture devices are not in use. This capability suppresses ICE candidate filtering so that both internal and external network addresses are always sent as ICE candidates.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
# Python3 + PyTest
|
|
41
|
+
import pytest
|
|
42
|
+
import time
|
|
43
|
+
|
|
44
|
+
from appium import webdriver
|
|
45
|
+
from selenium.webdriver.common.by import By
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def generate_caps():
|
|
49
|
+
common_caps = {
|
|
50
|
+
# It does not really matter what to put there, although setting 'Safari' might cause a failure
|
|
51
|
+
# depending on the particular client library
|
|
52
|
+
'browserName': 'AppiumSafari',
|
|
53
|
+
# automationName capability presence is mandatory for this Safari Driver to be selected
|
|
54
|
+
'automationName': 'Safari',
|
|
55
|
+
}
|
|
56
|
+
real_device_caps = {
|
|
57
|
+
**common_caps,
|
|
58
|
+
'platformName': 'iOS',
|
|
59
|
+
# This capability is optional
|
|
60
|
+
'safari:deviceType': 'iPhone',
|
|
61
|
+
# Do not forget to verify that Remote Automation is enabled for this device
|
|
62
|
+
'safari:deviceUDID': '<MyDeviceUDID>',
|
|
63
|
+
'safari:useSimulator': False,
|
|
64
|
+
}
|
|
65
|
+
simulator_caps = {
|
|
66
|
+
**common_caps,
|
|
67
|
+
'platformName': 'iOS',
|
|
68
|
+
'safari:platformVersion': '14.1',
|
|
69
|
+
'safari:deviceName': 'iPad Air 2',
|
|
70
|
+
'safari:useSimulator': True,
|
|
71
|
+
}
|
|
72
|
+
desktop_browser_caps = {
|
|
73
|
+
**common_caps,
|
|
74
|
+
'platformName': 'Mac',
|
|
75
|
+
}
|
|
76
|
+
return [real_device_caps, simulator_caps, desktop_browser_caps]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@pytest.fixture(params=generate_caps())
|
|
80
|
+
def driver(request):
|
|
81
|
+
drv = webdriver.Remote('http://localhost:4723/wd/hub', request.param)
|
|
82
|
+
yield drv
|
|
83
|
+
drv.quit()
|
|
16
84
|
|
|
17
|
-
## Test
|
|
18
85
|
|
|
86
|
+
class TimeoutError(Exception):
|
|
87
|
+
pass
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def wait_until_truthy(func, timeout_sec=5.0, interval_sec=0.5):
|
|
91
|
+
started = time.time()
|
|
92
|
+
original_error = None
|
|
93
|
+
while time.time() - started < timeout_sec:
|
|
94
|
+
original_error = None
|
|
95
|
+
try:
|
|
96
|
+
result = func()
|
|
97
|
+
if result:
|
|
98
|
+
return result
|
|
99
|
+
except Exception as e:
|
|
100
|
+
original_error = e
|
|
101
|
+
time.sleep(interval_sec)
|
|
102
|
+
if original_error is None:
|
|
103
|
+
raise TimeoutError(f'Condition unmet after {timeout_sec}s timeout')
|
|
104
|
+
raise original_error
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_feature_status_page_search(driver):
|
|
108
|
+
driver.get('https://webkit.org/status/')
|
|
109
|
+
|
|
110
|
+
# Enter "CSS" into the search box.
|
|
111
|
+
# Ensures that at least one result appears in search
|
|
112
|
+
# !!! Remember there are no ID and NAME locators in W3C standard
|
|
113
|
+
# These two have been superseded by CSS ones
|
|
114
|
+
search_box = driver.find_element_by_css('#search')
|
|
115
|
+
search_box.send_keys('CSS')
|
|
116
|
+
value = search_box.get_attribute('value')
|
|
117
|
+
assert len(value) > 0
|
|
118
|
+
search_box.submit()
|
|
119
|
+
# Count the visible results when filters are applied
|
|
120
|
+
# so one result shows up in at most one filter
|
|
121
|
+
assert wait_until_truthy(lambda: len(driver.execute_script("return document.querySelectorAll('li.feature:not(.is-hidden)')")) > 0)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_feature_status_page_filters(driver):
|
|
125
|
+
driver.get('https://webkit.org/status/')
|
|
126
|
+
|
|
127
|
+
assert wait_until_truthy(lambda: len(driver.execute_script("return document.querySelectorAll('.filter-toggle')")) == 7)
|
|
128
|
+
|
|
129
|
+
# Make sure every filter is turned off.
|
|
130
|
+
for checked_filter in filter(lambda f: f.is_selected(), filters):
|
|
131
|
+
checked_filter.click()
|
|
132
|
+
|
|
133
|
+
# Make sure you can select every filter.
|
|
134
|
+
for filt in filters:
|
|
135
|
+
filt.click()
|
|
136
|
+
assert filt.is_selected()
|
|
137
|
+
filt.click()
|
|
19
138
|
```
|
|
20
|
-
|
|
139
|
+
|
|
140
|
+
## Development
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# clone repo, then in repo dir:
|
|
144
|
+
npm install
|
|
145
|
+
gulp watch
|
|
21
146
|
```
|
package/build/index.js
CHANGED
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, '__esModule', {
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
6
|
value: true
|
|
11
7
|
});
|
|
8
|
+
Object.defineProperty(exports, "SafariDriver", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return _driver.default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "startServer", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _server.startServer;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
exports.default = void 0;
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _yargs2 = _interopRequireDefault(_yargs);
|
|
22
|
+
require("source-map-support/register");
|
|
16
23
|
|
|
17
|
-
var
|
|
24
|
+
var _driver = _interopRequireDefault(require("./lib/driver"));
|
|
18
25
|
|
|
19
|
-
var
|
|
26
|
+
var _server = require("./lib/server");
|
|
20
27
|
|
|
21
|
-
var
|
|
28
|
+
var _yargs = _interopRequireDefault(require("yargs"));
|
|
22
29
|
|
|
23
|
-
var
|
|
24
|
-
var DEFAULT_PORT = 4723;
|
|
30
|
+
var _asyncbox = require("asyncbox");
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return _regeneratorRuntime.async(function main$(context$1$0) {
|
|
29
|
-
while (1) switch (context$1$0.prev = context$1$0.next) {
|
|
30
|
-
case 0:
|
|
31
|
-
port = _yargs2['default'].argv.port || DEFAULT_PORT;
|
|
32
|
-
host = _yargs2['default'].argv.host || DEFAULT_HOST;
|
|
33
|
-
return context$1$0.abrupt('return', (0, _libServer.startServer)(port, host));
|
|
32
|
+
const DEFAULT_HOST = 'localhost';
|
|
33
|
+
const DEFAULT_PORT = 4797;
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}, null, this);
|
|
35
|
+
async function main() {
|
|
36
|
+
let port = _yargs.default.argv.port || _yargs.default.argv.p || DEFAULT_PORT;
|
|
37
|
+
let host = _yargs.default.argv.host || _yargs.default.argv.h || DEFAULT_HOST;
|
|
38
|
+
return await (0, _server.startServer)(port, host);
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
if (require.main === module) {
|
|
43
42
|
(0, _asyncbox.asyncify)(main);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
exports
|
|
48
|
-
|
|
45
|
+
var _default = _driver.default;
|
|
46
|
+
exports.default = _default;require('source-map-support').install();
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LmpzIl0sIm5hbWVzIjpbIkRFRkFVTFRfSE9TVCIsIkRFRkFVTFRfUE9SVCIsIm1haW4iLCJwb3J0IiwieWFyZ3MiLCJhcmd2IiwicCIsImhvc3QiLCJoIiwicmVxdWlyZSIsIm1vZHVsZSIsIlNhZmFyaURyaXZlciJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQTs7QUFDQTs7QUFDQTs7QUFDQTs7QUFFQSxNQUFNQSxZQUFZLEdBQUcsV0FBckI7QUFDQSxNQUFNQyxZQUFZLEdBQUcsSUFBckI7O0FBRUEsZUFBZUMsSUFBZixHQUF1QjtBQUNyQixNQUFJQyxJQUFJLEdBQUdDLGVBQU1DLElBQU4sQ0FBV0YsSUFBWCxJQUFtQkMsZUFBTUMsSUFBTixDQUFXQyxDQUE5QixJQUFtQ0wsWUFBOUM7QUFDQSxNQUFJTSxJQUFJLEdBQUdILGVBQU1DLElBQU4sQ0FBV0UsSUFBWCxJQUFtQkgsZUFBTUMsSUFBTixDQUFXRyxDQUE5QixJQUFtQ1IsWUFBOUM7QUFDQSxTQUFPLE1BQU0seUJBQVlHLElBQVosRUFBa0JJLElBQWxCLENBQWI7QUFDRDs7QUFFRCxJQUFJRSxPQUFPLENBQUNQLElBQVIsS0FBaUJRLE1BQXJCLEVBQTZCO0FBQzNCLDBCQUFTUixJQUFUO0FBQ0Q7O2VBRWNTLGUiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgU2FmYXJpRHJpdmVyIGZyb20gJy4vbGliL2RyaXZlcic7XG5pbXBvcnQgeyBzdGFydFNlcnZlciB9IGZyb20gJy4vbGliL3NlcnZlcic7XG5pbXBvcnQgeWFyZ3MgZnJvbSAneWFyZ3MnO1xuaW1wb3J0IHsgYXN5bmNpZnkgfSBmcm9tICdhc3luY2JveCc7XG5cbmNvbnN0IERFRkFVTFRfSE9TVCA9ICdsb2NhbGhvc3QnO1xuY29uc3QgREVGQVVMVF9QT1JUID0gNDc5NztcblxuYXN5bmMgZnVuY3Rpb24gbWFpbiAoKSB7XG4gIGxldCBwb3J0ID0geWFyZ3MuYXJndi5wb3J0IHx8IHlhcmdzLmFyZ3YucCB8fCBERUZBVUxUX1BPUlQ7XG4gIGxldCBob3N0ID0geWFyZ3MuYXJndi5ob3N0IHx8IHlhcmdzLmFyZ3YuaCB8fCBERUZBVUxUX0hPU1Q7XG4gIHJldHVybiBhd2FpdCBzdGFydFNlcnZlcihwb3J0LCBob3N0KTtcbn1cblxuaWYgKHJlcXVpcmUubWFpbiA9PT0gbW9kdWxlKSB7XG4gIGFzeW5jaWZ5KG1haW4pO1xufVxuXG5leHBvcnQgZGVmYXVsdCBTYWZhcmlEcml2ZXI7XG5leHBvcnQgeyBTYWZhcmlEcml2ZXIsIHN0YXJ0U2VydmVyIH07XG4iXSwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlUm9vdCI6Ii4uIn0=
|