Skip to content

Commit 2201e90

Browse files
feat: Add Safari driver options (appium#731)
1 parent 312c229 commit 2201e90

10 files changed

+405
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import Optional
19+
20+
from appium.options.common.supports_capabilities import SupportsCapabilities
21+
22+
AUTOMATIC_INSPECTION = 'safari:automaticInspection'
23+
24+
25+
class AutomaticInspectionOption(SupportsCapabilities):
26+
@property
27+
def automatic_inspection(self) -> Optional[bool]:
28+
"""
29+
:Returns: Whether to use automatic inspection.
30+
"""
31+
return self.get_capability(AUTOMATIC_INSPECTION)
32+
33+
@automatic_inspection.setter
34+
def automatic_inspection(self, value: bool) -> None:
35+
"""
36+
This capability instructs Safari to preload the Web Inspector and JavaScript
37+
debugger in the background prior to returning a newly-created window.
38+
To pause the test's execution in JavaScript and bring up Web Inspector's
39+
Debugger tab, you can simply evaluate a debugger statement in the test page.
40+
"""
41+
self.set_capability(AUTOMATIC_INSPECTION, value)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import Optional
19+
20+
from appium.options.common.supports_capabilities import SupportsCapabilities
21+
22+
AUTOMATIC_PROFILING = 'safari:automaticProfiling'
23+
24+
25+
class AutomaticProfilingOption(SupportsCapabilities):
26+
@property
27+
def automatic_profiling(self) -> Optional[bool]:
28+
"""
29+
:Returns: Whether to use automatic profiling.
30+
"""
31+
return self.get_capability(AUTOMATIC_PROFILING)
32+
33+
@automatic_profiling.setter
34+
def automatic_profiling(self, value: bool) -> None:
35+
"""
36+
This capability instructs Safari to preload the Web Inspector and start
37+
a Timeline recording in the background prior to returning a newly-created
38+
window. To view the recording, open the Web Inspector through Safari's
39+
Develop menu.
40+
"""
41+
self.set_capability(AUTOMATIC_PROFILING, value)

appium/options/ios/safari/base.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,34 @@
1818
from typing import Dict
1919

2020
from appium.options.common.automation_name_option import AUTOMATION_NAME
21-
from appium.options.common.base import AppiumOptions
21+
from appium.options.common.base import PLATFORM_NAME, AppiumOptions
22+
23+
from .automatic_inspection_option import AutomaticInspectionOption
24+
from .automatic_profiling_option import AutomaticProfilingOption
25+
from .device_name_option import DeviceNameOption
26+
from .device_type_option import DeviceTypeOption
27+
from .device_udid_option import DeviceUdidOption
28+
from .platform_build_version_option import PlatformBuildVersionOption
29+
from .platform_version_option import PlatformVersionOption
30+
from .use_simulator_option import UseSimulatorOption
31+
from .webkit_webrtc_option import WebkitWebrtcOption
2232

2333

2434
class SafariOptions(
2535
AppiumOptions,
36+
AutomaticInspectionOption,
37+
AutomaticProfilingOption,
38+
DeviceNameOption,
39+
DeviceTypeOption,
40+
DeviceUdidOption,
41+
PlatformBuildVersionOption,
42+
PlatformVersionOption,
43+
UseSimulatorOption,
44+
WebkitWebrtcOption,
2645
):
2746
@property
2847
def default_capabilities(self) -> Dict:
2948
return {
30-
AppiumOptions.PLATFORM_NAME: 'iOS',
49+
PLATFORM_NAME: 'iOS',
3150
AUTOMATION_NAME: 'Safari',
3251
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import Optional
19+
20+
from appium.options.common.supports_capabilities import SupportsCapabilities
21+
22+
DEVICE_NAME = 'safari:deviceName'
23+
24+
25+
class DeviceNameOption(SupportsCapabilities):
26+
@property
27+
def device_name(self) -> Optional[str]:
28+
"""
29+
:Returns: String representing the name of the device.
30+
"""
31+
return self.get_capability(DEVICE_NAME)
32+
33+
@device_name.setter
34+
def device_name(self, value: str) -> None:
35+
"""
36+
safaridriver will only create a session using hosts whose device name
37+
matches the value of safari:deviceName. Device names are compared
38+
case-insensitively. NOTE: Device names for connected devices are shown in
39+
iTunes. If Xcode is installed, device names for connected devices are available
40+
via the output of instruments(1) and in the Devices and Simulators window
41+
(accessed in Xcode via "Window -> Devices and Simulators").
42+
"""
43+
self.set_capability(DEVICE_NAME, value)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import Optional
19+
20+
from appium.options.common.supports_capabilities import SupportsCapabilities
21+
22+
DEVICE_TYPE = 'safari:deviceType'
23+
24+
25+
class DeviceTypeOption(SupportsCapabilities):
26+
@property
27+
def device_type(self) -> Optional[str]:
28+
"""
29+
:Returns: String representing the type of the device.
30+
"""
31+
return self.get_capability(DEVICE_TYPE)
32+
33+
@device_type.setter
34+
def device_type(self, value: str) -> None:
35+
"""
36+
If the value of safari:deviceType is 'iPhone', safaridriver will only create a session
37+
using an iPhone device or iPhone simulator. If the value of safari:deviceType is 'iPad',
38+
safaridriver will only create a session using an iPad device or iPad simulator.
39+
Values of safari:deviceType are compared case-insensitively.
40+
"""
41+
self.set_capability(DEVICE_TYPE, value)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import Optional
19+
20+
from appium.options.common.supports_capabilities import SupportsCapabilities
21+
22+
DEVICE_UDID = 'safari:deviceUDID'
23+
24+
25+
class DeviceUdidOption(SupportsCapabilities):
26+
@property
27+
def device_udid(self) -> Optional[str]:
28+
"""
29+
:Returns: String representing the UDID of the device.
30+
"""
31+
return self.get_capability(DEVICE_UDID)
32+
33+
@device_udid.setter
34+
def device_udid(self, value: str) -> None:
35+
"""
36+
safaridriver will only create a session using hosts whose device UDID
37+
matches the value of safari:deviceUDID. Device UDIDs are compared
38+
case-insensitively. NOTE: If Xcode is installed, UDIDs for connected
39+
devices are available via the output of instruments(1) and in the
40+
Devices and Simulators window (accessed in Xcode via
41+
"Window -> Devices and Simulators").
42+
"""
43+
self.set_capability(DEVICE_UDID, value)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import Optional
19+
20+
from appium.options.common.supports_capabilities import SupportsCapabilities
21+
22+
PLATFORM_BUILD_VERSION = 'safari:platformBuildVersion'
23+
24+
25+
class PlatformBuildVersionOption(SupportsCapabilities):
26+
@property
27+
def platform_build_version(self) -> Optional[str]:
28+
"""
29+
:Returns: String representing the platform build version.
30+
"""
31+
return self.get_capability(PLATFORM_BUILD_VERSION)
32+
33+
@platform_build_version.setter
34+
def platform_build_version(self, value: str) -> None:
35+
"""
36+
safaridriver will only create a session using hosts whose OS build
37+
version matches the value of safari:platformBuildVersion. Example
38+
of a macOS build version is '18E193'. On macOS, the OS build version
39+
can be determined by running the sw_vers(1) utility.
40+
"""
41+
self.set_capability(PLATFORM_BUILD_VERSION, value)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import Optional
19+
20+
from appium.options.common.supports_capabilities import SupportsCapabilities
21+
22+
PLATFORM_VERSION = 'safari:platformVersion'
23+
24+
25+
class PlatformVersionOption(SupportsCapabilities):
26+
@property
27+
def platform_version(self) -> Optional[str]:
28+
"""
29+
:Returns: String representing the platform version.
30+
"""
31+
return self.get_capability(PLATFORM_VERSION)
32+
33+
@platform_version.setter
34+
def platform_version(self, value: str) -> None:
35+
"""
36+
safaridriver will only create a session using hosts whose OS
37+
version matches the value of safari:platformVersion. OS version
38+
numbers are prefix-matched. For example, if the value of safari:platformVersion
39+
is '12', this will allow hosts with an OS version of '12.0' or '12.1' but not '10.12'.
40+
"""
41+
self.set_capability(PLATFORM_VERSION, value)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from typing import Optional
19+
20+
from appium.options.common.supports_capabilities import SupportsCapabilities
21+
22+
USE_SIMULATOR = 'safari:useSimulator'
23+
24+
25+
class UseSimulatorOption(SupportsCapabilities):
26+
@property
27+
def use_simulator(self) -> Optional[bool]:
28+
"""
29+
:Returns: Whether to use iOS Simulator.
30+
"""
31+
return self.get_capability(USE_SIMULATOR)
32+
33+
@use_simulator.setter
34+
def use_simulator(self, value: bool) -> None:
35+
"""
36+
If the value of safari:useSimulator is true, safaridriver will only use
37+
iOS Simulator hosts. If the value of safari:useSimulator is false, safaridriver
38+
will not use iOS Simulator hosts. NOTE: An Xcode installation is required
39+
in order to run WebDriver tests on iOS Simulator hosts.
40+
"""
41+
self.set_capability(USE_SIMULATOR, value)

0 commit comments

Comments
 (0)