Skip to content

Commit 4e2bfc0

Browse files
authored
add finger print feature (#142)
* add finger print feature * update changelog * fixrubocop
1 parent ee6756b commit 4e2bfc0

File tree

8 files changed

+69
-4
lines changed

8 files changed

+69
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
55
### Enhancements
6+
- Add finger print feature for Android emulators [#13](https://github.com/appium/ruby_lib_core/issues/13)
67

78
### Bug fixes
89

lib/appium_lib_core/android/device.rb

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_relative 'device/network'
44
require_relative 'device/performance'
55
require_relative 'device/screen'
6+
require_relative 'device/auth_finger_print'
67

78
module Appium
89
module Core
@@ -324,6 +325,7 @@ def end_coverage(path, intent)
324325
Network.add_methods
325326
Clipboard.add_methods
326327
Emulator.add_methods
328+
AuthenticatesByFinger.add_methods
327329
end
328330
end
329331
end # module Device
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Appium
2+
module Core
3+
module Android
4+
module Device
5+
module AuthenticatesByFinger
6+
# @!method finger_print(finger_id)
7+
# Authenticate users by using their finger print scans on supported emulators.
8+
#
9+
# @param [Integer] finger_id Finger prints stored in Android Keystore system (from 1 to 10)
10+
#
11+
# @example
12+
#
13+
# @driver.finger_print 1
14+
#
15+
def self.add_methods
16+
::Appium::Core::Device.add_endpoint_method(:finger_print) do
17+
def finger_print(finger_id)
18+
unless (1..10).cover? finger_id.to_i
19+
raise ArgumentError, "finger_id should be integer between 1 to 10. Not #{finger_id}"
20+
end
21+
22+
execute(:finger_print, {}, { fingerprintId: finger_id.to_i })
23+
end
24+
end
25+
end # def self.emulator_commands
26+
end # module Emulator
27+
end # module Device
28+
end # module Android
29+
end # module Core
30+
end # module Appium

lib/appium_lib_core/common/command/common.rb

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module Commands
4242
pull_folder: [:post, 'session/:session_id/appium/device/pull_folder'.freeze],
4343
get_clipboard: [:post, 'session/:session_id/appium/device/get_clipboard'.freeze],
4444
set_clipboard: [:post, 'session/:session_id/appium/device/set_clipboard'.freeze],
45+
finger_print: [:post, 'session/:session_id/appium/device/finger_print'.freeze],
4546
get_settings: [:get, 'session/:session_id/appium/settings'.freeze],
4647
update_settings: [:post, 'session/:session_id/appium/settings'.freeze],
4748
stop_recording_screen: [:post, 'session/:session_id/appium/stop_recording_screen'.freeze],

test/test_helper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
require 'minitest'
1010

1111
$VERBOSE = nil
12+
Appium::Logger.level = ::Logger::FATAL # Show Logger logs only they are fatal
1213

13-
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
14+
Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new
1415

1516
ROOT_REPORT_PATH = "#{Dir.pwd}/test/report".freeze
1617
START_AT = Time.now.strftime('%Y-%m-%d-%H%M%S').freeze

test/unit/android/webdriver/mjsonwp/commands_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ def test_session_capabilities
116116

117117
assert_requested(:get, SESSION.to_s, times: 1)
118118
end
119+
120+
def test_finger_print
121+
stub_request(:post, "#{SESSION}/appium/device/finger_print")
122+
.with(body: { fingerprintId: 1 }.to_json)
123+
.to_return(headers: HEADER, status: 200, body: { value: { finger: 'name' } }.to_json)
124+
125+
error = assert_raises ArgumentError do
126+
@driver.finger_print 0
127+
end
128+
assert_equal 'finger_id should be integer between 1 to 10. Not 0', error.message
129+
130+
@driver.finger_print 1
131+
132+
assert_requested(:post, "#{SESSION}/appium/device/finger_print", times: 1)
133+
end
119134
end # class CommandsTest
120135
end # module MJSONWP
121136
end # module WebDriver

test/unit/android/webdriver/w3c/commands_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ def test_session_capabilities
110110

111111
assert_requested(:get, SESSION.to_s, times: 1)
112112
end
113+
114+
def test_finger_print
115+
stub_request(:post, "#{SESSION}/appium/device/finger_print")
116+
.with(body: { fingerprintId: 1 }.to_json)
117+
.to_return(headers: HEADER, status: 200, body: { value: { finger: 'name' } }.to_json)
118+
119+
error = assert_raises ArgumentError do
120+
@driver.finger_print 0
121+
end
122+
assert_equal 'finger_id should be integer between 1 to 10. Not 0', error.message
123+
124+
@driver.finger_print 1
125+
126+
assert_requested(:post, "#{SESSION}/appium/device/finger_print", times: 1)
127+
end
113128
end # class CommandsTest
114129
end # module W3C
115130
end # module WebDriver

test/unit/script/commands_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ def test_get_all_command_path
2222

2323
# depends on webdriver-version... (number of commands)
2424
def test_implemented_mjsonwp_commands
25-
assert_equal 145, @c.implemented_mjsonwp_commands.length
25+
assert_equal 146, @c.implemented_mjsonwp_commands.length
2626
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_mjsonwp_commands.first
2727

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

3232
def test_implemented_w3c_commands
33-
assert_equal 118, @c.implemented_w3c_commands.length
33+
assert_equal 119, @c.implemented_w3c_commands.length
3434
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_w3c_commands.first
3535

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

4040
def test_implemented_core_commands
41-
assert_equal 59, @c.implemented_core_commands.length
41+
assert_equal 60, @c.implemented_core_commands.length
4242
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_core_commands.first
4343

4444
# pick up an arbitrary command

0 commit comments

Comments
 (0)