Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Read `release_notes.md` for commit level details.
## [Unreleased]

### Enhancements
- Allow to override an existing method by `Appium::Core::Base::Driver#add_command` since Appium drivers/plugins allow to override them

### Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib_core/common/base/bridge/mjsonwp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def commands(command)

# command for Appium 2.0.
def add_command(method:, url:, name:, &block)
raise ::Appium::Core::Error::ArgumentError, "#{name} is already defined" if @available_commands.key? name
::Appium::Logger.debug "Overriding the method '#{name}' for '#{url}'" if @available_commands.key? name

@available_commands[name] = [method, url]

Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib_core/common/base/bridge/w3c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def commands(command)

# command for Appium 2.0.
def add_command(method:, url:, name:, &block)
raise ::Appium::Core::Error::ArgumentError, "#{name} is already defined" if @available_commands.key? name
::Appium::Logger.info "Overriding the method '#{name}' for '#{url}'" if @available_commands.key? name

@available_commands[name] = [method, url]

Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib_core/common/base/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def update_sending_request_to(protocol:, host:, port:, path:)
# values in the hash.
# The third argument should be hash. The hash will be the request body.
# Please read examples below for more details.
# @raise [ArgumentError] If the given +name+ is already defined or +method+ are invalid value.
# @raise [ArgumentError] If the given +method+ are invalid value.
#
# @example
#
Expand Down
21 changes: 12 additions & 9 deletions test/unit/android/webdriver/mjsonwp/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,27 @@ def test_add_command_error
end
end

def test_add_command_already_defined
def test_add_command_already_defined_without_error
stub_request(:get, "#{SESSION}/path/to/custom/url")
.to_return(headers: HEADER, status: 200, body: { value: 'xxxx' }.to_json)

@driver.add_command(
method: :get,
url: 'session/:session_id/path/to/custom/url',
name: :test_command
)
assert_equal @driver.respond_to?(:test_command), true

@driver.add_command(
method: :get,
url: 'session/:session_id/path/to/custom/url',
name: :test_command
)
assert_equal @driver.respond_to?(:test_command), true

assert_raises ::Appium::Core::Error::ArgumentError do
@driver.add_command(
method: :get,
url: 'session/:session_id/path/to/custom/url',
name: :test_command
)
end
@driver.test_command

assert_equal @driver.respond_to?(:test_command), true
assert_requested(:get, "#{SESSION}/path/to/custom/url", times: 1)
end

def test_no_session_id
Expand Down
21 changes: 12 additions & 9 deletions test/unit/android/webdriver/w3c/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,27 @@ def test_add_command_error
end
end

def test_add_command_already_defined
def test_add_command_already_defined_without_error
stub_request(:get, "#{SESSION}/path/to/custom/url")
.to_return(headers: HEADER, status: 200, body: { value: 'xxxx' }.to_json)

@driver.add_command(
method: :get,
url: 'session/:session_id/path/to/custom/url',
name: :test_command
)
assert_equal @driver.respond_to?(:test_command), true

@driver.add_command(
method: :get,
url: 'session/:session_id/path/to/custom/url',
name: :test_command
)
assert_equal @driver.respond_to?(:test_command), true

assert_raises ::Appium::Core::Error::ArgumentError do
@driver.add_command(
method: :get,
url: 'session/:session_id/path/to/custom/url',
name: :test_command
)
end
@driver.test_command

assert_equal @driver.respond_to?(:test_command), true
assert_requested(:get, "#{SESSION}/path/to/custom/url", times: 1)
end

def test_no_session_id
Expand Down