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 @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### Enhancements
- Add a `bug_report` option in `start_recording_screen`, Android
- Add clipboard apis [#69](https://github.com/appium/ruby_lib_core/pull/69)

### Bug fixes

Expand Down
1 change: 1 addition & 0 deletions lib/appium_lib_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_relative 'appium_lib_core/device/multi_touch'
require_relative 'appium_lib_core/device/screen_record'
require_relative 'appium_lib_core/device/app_state'
require_relative 'appium_lib_core/device/clipboard_content_type'

require_relative 'appium_lib_core/android'
require_relative 'appium_lib_core/android_uiautomator2'
Expand Down
54 changes: 54 additions & 0 deletions lib/appium_lib_core/android/device.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'device/emulator'
require 'base64'

module Appium
module Android
Expand Down Expand Up @@ -117,6 +118,27 @@ module Device
# @driver.start_recording_screen video_size: '1280x720', time_limit: '180', bit_rate: '5000000'
#

# @!method get_clipboard(content_type: :plaintext)
# Set the content of device's clipboard.
# @param [String] content_type: one of supported content types.
# @return [String]
#
# @example
#
# @driver.get_clipboard #=> "happy testing"
#

# @!method set_clipboard(content:, content_type: :plaintext, label: nil)
# Set the content of device's clipboard.
# @param [String] label: clipboard data label.
# @param [String] content_type: one of supported content types.
# @param [String] content: Contents to be set. (Will encode with base64-encoded inside this method)
#
# @example
#
# @driver.set_clipboard(content: 'happy testing') #=> {"protocol"=>"W3C"}
#

####
## class << self
####
Expand Down Expand Up @@ -181,6 +203,7 @@ def get_performance_data(package_name:, data_type:, data_read_timeout: 1000)
end

add_screen_recording
add_clipboard
Emulator.emulator_commands
end

Expand Down Expand Up @@ -209,6 +232,37 @@ def start_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT'
# rubocop:enable Metrics/ParameterLists
end
end

def add_clipboard
::Appium::Core::Device.add_endpoint_method(:get_clipboard) do
def get_clipboard(content_type: :plaintext)
unless ::Appium::Core::Device::Clipboard::CONTENT_TYPE.member?(content_type)
raise "content_type should be #{::Appium::Core::Device::Clipboard::CONTENT_TYPE}"
end

params = { contentType: content_type }

data = execute(:get_clipboard, {}, params)
Base64.decode64 data
end
end

::Appium::Core::Device.add_endpoint_method(:set_clipboard) do
def set_clipboard(content:, content_type: :plaintext, label: nil)
unless ::Appium::Core::Device::Clipboard::CONTENT_TYPE.member?(content_type)
raise "content_type should be #{::Appium::Core::Device::Clipboard::CONTENT_TYPE}"
end

params = {
contentType: content_type,
content: Base64.encode64(content)
}
params[:label] = label unless label.nil?

execute(:set_clipboard, {}, params)
end
end
end
end
end # module Device
end # module Android
Expand Down
2 changes: 2 additions & 0 deletions lib/appium_lib_core/common/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ module Commands
push_file: [:post, 'session/:session_id/appium/device/push_file'.freeze],
pull_file: [:post, 'session/:session_id/appium/device/pull_file'.freeze],
pull_folder: [:post, 'session/:session_id/appium/device/pull_folder'.freeze],
get_clipboard: [:post, 'session/:session_id/appium/device/get_clipboard'.freeze],
set_clipboard: [:post, 'session/:session_id/appium/device/set_clipboard'.freeze],
get_settings: [:get, 'session/:session_id/appium/settings'.freeze],
update_settings: [:post, 'session/:session_id/appium/settings'.freeze],
touch_actions: [:post, 'session/:session_id/touch/perform'.freeze],
Expand Down
9 changes: 9 additions & 0 deletions lib/appium_lib_core/device/clipboard_content_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Appium
module Core
module Device
module Clipboard
CONTENT_TYPE = [:plaintext, :image, :url].freeze
end
end
end
end
57 changes: 57 additions & 0 deletions lib/appium_lib_core/ios/device.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'base64'

module Appium
module Ios
module Device
Expand Down Expand Up @@ -28,6 +30,26 @@ module Device
# @driver.toggle_touch_id_enrollment false #=> Disable toggle enrolled
#

# @!method get_clipboard(content_type: :plaintext)
# Set the content of device's clipboard.
# @param [String] content_type: one of supported content types.
# @return [String]
#
# @example
#
# @driver.get_clipboard #=> "happy testing"
#

# @!method set_clipboard(content:, content_type: :plaintext)
# Set the content of device's clipboard.
# @param [String] content_type: one of supported content types.
# @param [String] content: Contents to be set. (Will encode with base64-encoded inside this method)
#
# @example
#
# @driver.set_clipboard(content: 'happy testing') #=> {"protocol"=>"W3C"}
#

####
## class << self
####
Expand All @@ -47,6 +69,41 @@ def toggle_touch_id_enrollment(enabled = true)
execute :toggle_touch_id_enrollment, {}, enabled: enabled
end
end

add_clipboard
end

private

def add_clipboard
::Appium::Core::Device.add_endpoint_method(:get_clipboard) do
def get_clipboard(content_type: :plaintext)
unless ::Appium::Core::Device::Clipboard::CONTENT_TYPE.member?(content_type)
raise "content_type should be #{::Appium::Core::Device::Clipboard::CONTENT_TYPE}"
end

params = {}
params[:contentType] = content_type

data = execute(:get_clipboard, {}, params)
Base64.decode64 data
end
end

::Appium::Core::Device.add_endpoint_method(:set_clipboard) do
def set_clipboard(content:, content_type: :plaintext)
unless ::Appium::Core::Device::Clipboard::CONTENT_TYPE.member?(content_type)
raise "content_type should be #{::Appium::Core::Device::Clipboard::CONTENT_TYPE}"
end

params = {
contentType: content_type,
content: Base64.encode64(content)
}

execute(:set_clipboard, {}, params)
end
end
end
end
end # module Device
Expand Down
8 changes: 8 additions & 0 deletions test/functional/android/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ def test_viewport_screenshot
assert !File.exist?(file.path)
end

def test_clipbord
input = 'happy testing'

@@driver.set_clipboard(content: input, label: 'Note')

assert_equal input, @@driver.get_clipboard
end

private

def scroll_to(text)
Expand Down
8 changes: 8 additions & 0 deletions test/functional/ios/ios/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ def test_start_performance_record_and_stop
File.delete file.path
assert !File.exist?(file.path)
end

def test_clipbord
input = 'happy testing'

@@driver.set_clipboard(content: input)

assert_equal input, @@driver.get_clipboard
end
end
end
end
4 changes: 3 additions & 1 deletion test/unit/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def test_with_arg_definitions
:start_activity,
:end_coverage,
:set_network_connection,
:get_performance_data])
:get_performance_data,
:get_clipboard,
:set_clipboard])
end

## no args
Expand Down
4 changes: 3 additions & 1 deletion test/unit/android/device_w3c_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def test_with_arg_definitions
:start_activity,
:end_coverage,
:set_network_connection,
:get_performance_data])
:get_performance_data,
:get_clipboard,
:set_clipboard])
end

## no args
Expand Down
2 changes: 2 additions & 0 deletions test/unit/ios/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def test_with_arg_definitions
:push_file,
:pull_file,
:pull_folder,
:get_clipboard,
:set_clipboard,
:get_settings,
:update_settings,
:touch_actions,
Expand Down
2 changes: 2 additions & 0 deletions test/unit/ios/device_w3c_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def test_with_arg_definitions
:push_file,
:pull_file,
:pull_folder,
:get_clipboard,
:set_clipboard,
:get_settings,
:update_settings,
:touch_actions,
Expand Down
6 changes: 3 additions & 3 deletions test/unit/script/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ def test_get_all_command_path

# depends on webdriver-version... (number of commands)
def test_implemented_mjsonwp_commands
assert_equal 142, @c.implemented_mjsonwp_commands.length
assert_equal 144, @c.implemented_mjsonwp_commands.length
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_mjsonwp_commands.first

# pick up an arbitrary command
assert_equal %i(get post), @c.implemented_mjsonwp_commands['session/:session_id/alert_text']
end

def test_implemented_w3c_commands
assert_equal 113, @c.implemented_w3c_commands.length
assert_equal 115, @c.implemented_w3c_commands.length
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_w3c_commands.first

# pick up an arbitrary command
assert_equal %i(get post), @c.implemented_w3c_commands['session/:session_id/alert/text']
end

def test_implemented_core_commands
assert_equal 56, @c.implemented_core_commands.length
assert_equal 58, @c.implemented_core_commands.length
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_core_commands.first

# pick up an arbitrary command
Expand Down