Skip to content

Commit eb7680f

Browse files
authored
refactor: collect no agrs in core/command (#675)
1 parent f174e75 commit eb7680f

File tree

5 files changed

+14
-52
lines changed

5 files changed

+14
-52
lines changed

lib/appium_lib/core/android/device.rb

+1-41
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,6 @@ module Device
1414
# background_app(-1) #=> the app never come back. https://github.com/appium/appium/issues/7741
1515
# ```
1616

17-
# @!method current_activity
18-
# Get current activity name
19-
# @return [String] An activity name
20-
#
21-
# ```ruby
22-
# current_activity # '.ApiDemos'
23-
# ```
24-
25-
# @!method current_package
26-
# Get current package name
27-
# @return [String] A package name
28-
#
29-
# ```ruby
30-
# current_package # 'com.example.android.apis'
31-
# ```
32-
33-
# @!method get_system_bars
34-
# Get system bar's information
35-
# @return [String] System bar
36-
#
37-
# ```ruby
38-
# get_system_bars
39-
# ```
40-
41-
# @!method get_display_density
42-
# Get connected device's density.
43-
# @return [Integer] The size of density
44-
#
45-
# ```ruby
46-
# get_display_density # 320
47-
# ```
48-
4917
# @!method hide_keyboard
5018
# Hide the onscreen keyboard
5119
# @param [String] close_key The name of the key which closes the keyboard.
@@ -78,10 +46,6 @@ module Device
7846
# app_activity: '.accessibility.AccessibilityNodeProviderActivity'
7947
# ```
8048

81-
# @!method get_network_connection
82-
# Get the device network connection current status
83-
# See set_network_connection method for return value
84-
8549
# @!method set_network_connection
8650
# Set the device network connection mode
8751
# @param [String] path Bit mask that represent the network mode
@@ -118,10 +82,6 @@ class << self
11882
def extended(_mod)
11983
Appium::Core::Device.extend_webdriver_with_forwardable
12084

121-
::Appium::Core::Commands::COMMAND_NO_ARG_ANDROID.each_key do |method|
122-
Appium::Core::Device.add_endpoint_method method
123-
end
124-
12585
# Android
12686
Appium::Core::Device.add_endpoint_method(:start_activity) do
12787
def start_activity(opts)
@@ -143,7 +103,7 @@ def start_activity(opts)
143103
end
144104
end
145105

146-
# Android
106+
# Android, Override
147107
Appium::Core::Device.add_endpoint_method(:hide_keyboard) do
148108
def hide_keyboard(close_key = nil, strategy = nil)
149109
option = {}

lib/appium_lib/core/common/command.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ module Core
55
# ref: https://github.com/appium/appium-base-driver/blob/master/lib/mjsonwp/routes.js
66
module Commands
77
COMMAND_NO_ARG = {
8+
# Common
89
shake: [:post, 'session/:session_id/appium/device/shake'.freeze],
910
launch_app: [:post, 'session/:session_id/appium/app/launch'.freeze],
1011
close_app: [:post, 'session/:session_id/appium/app/close'.freeze],
1112
reset: [:post, 'session/:session_id/appium/app/reset'.freeze],
1213
device_locked?: [:post, 'session/:session_id/appium/device/is_locked'.freeze],
1314
device_time: [:get, 'session/:session_id/appium/device/system_time'.freeze],
14-
current_context: [:get, 'session/:session_id/context'.freeze]
15-
}.freeze
15+
current_context: [:get, 'session/:session_id/context'.freeze],
1616

17-
COMMAND_NO_ARG_ANDROID = {
17+
# Android
1818
open_notifications: [:post, 'session/:session_id/appium/device/open_notifications'.freeze],
1919
toggle_airplane_mode: [:post, 'session/:session_id/appium/device/toggle_airplane_mode'.freeze],
2020
current_activity: [:get, 'session/:session_id/appium/device/current_activity'.freeze],
@@ -23,12 +23,12 @@ module Commands
2323
get_display_density: [:get, 'session/:session_id/appium/device/display_density'.freeze],
2424
is_keyboard_shown: [:get, 'session/:session_id/appium/device/is_keyboard_shown'.freeze],
2525
get_network_connection: [:get, 'session/:session_id/network_connection'.freeze],
26-
get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'.freeze]
27-
}.freeze
26+
get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'.freeze],
2827

29-
COMMAND_NO_ARG_IOS = {
28+
# iOS
3029
}.freeze
3130

31+
# Some commands differ for each driver.
3232
COMMAND = {
3333
# common
3434
available_contexts: [:get, 'session/:session_id/contexts'.freeze],
@@ -65,7 +65,7 @@ module Commands
6565
}.freeze
6666

6767
COMMANDS = {}.merge(COMMAND).merge(COMMAND_ANDROID).merge(COMMAND_IOS)
68-
.merge(COMMAND_NO_ARG).merge(COMMAND_NO_ARG_ANDROID).merge(COMMAND_NO_ARG_IOS).freeze
68+
.merge(COMMAND_NO_ARG).freeze
6969

7070
COMMANDS_EXTEND_OSS = COMMANDS.merge(::Appium::Core::Base::Commands::OSS).freeze
7171
COMMANDS_EXTEND_W3C = COMMANDS.merge(::Appium::Core::Base::Commands::W3C).freeze

lib/appium_lib/core/common/device.rb

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ module Device
140140
# set_immediate_value element, 'hello'
141141
# ```
142142

143+
# @!method get_network_connection
144+
# Get the device network connection current status
145+
# See set_network_connection method for return value
146+
143147
class << self
144148
def extended(_mod)
145149
extend_webdriver_with_forwardable

lib/appium_lib/core/ios/device.rb

-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ class << self
2525
def extended(_mod)
2626
::Appium::Core::Device.extend_webdriver_with_forwardable
2727

28-
::Appium::Core::Commands::COMMAND_NO_ARG_IOS.each_key do |method|
29-
::Appium::Core::Device.add_endpoint_method method
30-
end
31-
3228
# TODO: TEST ME
3329
::Appium::Core::Device.add_endpoint_method(:touch_id) do
3430
def touch_id(match = true)

lib/appium_lib/core/ios/xcuitest/device.rb

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class << self
3030
def extended(_mod)
3131
::Appium::Core::Device.extend_webdriver_with_forwardable
3232

33+
# Override
3334
::Appium::Core::Device.add_endpoint_method(:hide_keyboard) do
3435
def hide_keyboard(close_key = nil, strategy = nil)
3536
option = {}
@@ -41,6 +42,7 @@ def hide_keyboard(close_key = nil, strategy = nil)
4142
end
4243
end
4344

45+
# Override
4446
::Appium::Core::Device.add_endpoint_method(:background_app) do
4547
def background_app(duration = 0)
4648
# https://github.com/appium/ruby_lib/issues/500, https://github.com/appium/appium/issues/7741

0 commit comments

Comments
 (0)