Skip to content

Commit ff222bd

Browse files
authored
Fix warning (#174)
* fix warning * tweak tests for espresso * update changelog * fix rubocop
1 parent 1cefd42 commit ff222bd

File tree

11 files changed

+55
-20
lines changed

11 files changed

+55
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Read `release_notes.md` for commit level details.
66
### Enhancements
77

88
### Bug fixes
9+
- Reduce warnings for method definitions
910

1011
### Deprecations
1112

lib/appium_lib_core/device.rb

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def extend_webdriver_with_forwardable
5454
private
5555

5656
def delegate_from_appium_driver(method, delegation_target = :driver)
57+
return if ::Appium::Core::Device.method_defined? method
58+
5759
def_delegator delegation_target, method
5860
end
5961

@@ -65,9 +67,11 @@ def delegate_driver_method(method)
6567

6668
def create_bridge_command(method)
6769
::Appium::Core::Base::Bridge::MJSONWP.class_eval do
70+
undef_method method if method_defined? method
6871
block_given? ? class_eval(&Proc.new) : define_method(method) { execute method }
6972
end
7073
::Appium::Core::Base::Bridge::W3C.class_eval do
74+
undef_method method if method_defined? method
7175
block_given? ? class_eval(&Proc.new) : define_method(method) { execute method }
7276
end
7377
end

lib/appium_lib_core/driver.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def delegated_target_for_test
174174
# @private
175175
def initialize(opts = {})
176176
@delegate_target = self # for testing purpose
177+
@automation_name = nil # initialise before `set_automation_name`
177178

178179
opts = Appium.symbolize_keys opts
179180
validate_keys(opts)
@@ -332,7 +333,7 @@ def appium_server_version
332333
# @core.platform_version #=> [10,1,1]
333334
#
334335
def platform_version
335-
p_version = @driver.capabilities['platformVersion']
336+
p_version = @driver.capabilities['platformVersion'] || @driver.session_capabilities['platformVersion']
336337
p_version.split('.').map(&:to_i)
337338
end
338339

script/commands.rb

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class CommandsChecker
1616
# - webdriver_w3c_commands: ::Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS
1717
#
1818
def initialize
19+
@spec_commands = nil
20+
1921
@implemented_mjsonwp_commands = convert_driver_commands Appium::Core::Commands::MJSONWP::COMMANDS
2022
@implemented_w3c_commands = convert_driver_commands Appium::Core::Commands::W3C::COMMANDS
2123
@implemented_core_commands = convert_driver_commands Appium::Core::Commands::COMMANDS

test/functional/android/android/device_test.rb

+27-13
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ def test_keyevent
273273

274274
def test_press_keycode
275275
# http://developer.android.com/reference/android/view/KeyEvent.html
276-
assert @driver.press_keycode(176)
276+
result = @driver.press_keycode(176) # it does not raise error
277+
assert result || result.nil?
277278
end
278279

279280
def test_long_press_keycode
280281
# http://developer.android.com/reference/android/view/KeyEvent.html
281-
assert @driver.long_press_keycode(176)
282+
result = @driver.long_press_keycode(176) # it does not raise error
283+
assert result || result.nil?
282284
end
283285

284286
def test_open_notifications
@@ -346,6 +348,8 @@ def test_take_element_screenshot
346348
end
347349

348350
def test_viewport_screenshot
351+
skip 'Espresso does not support battery_info' if @@core.automation_name == :espresso
352+
349353
file = @driver.save_viewport_screenshot 'android_viewport_screenshot_test.png'
350354

351355
assert File.exist?(file.path)
@@ -363,6 +367,8 @@ def test_clipbord
363367
end
364368

365369
def test_battery_info
370+
skip 'Espresso does not support battery_info' if @@core.automation_name == :espresso
371+
366372
result = @driver.battery_info
367373

368374
assert !result[:state].nil?
@@ -394,17 +400,25 @@ def test_file_management
394400
private
395401

396402
def scroll_to(text)
397-
text = %("#{text}")
398-
rid = resource_id(text, "new UiSelector().resourceId(#{text});")
399-
args = rid.empty? ? ["new UiSelector().textContains(#{text})", "new UiSelector().descriptionContains(#{text})"] : [rid]
400-
args.each_with_index do |arg, index|
401-
begin
402-
elem = @driver.find_element :uiautomator,
403-
'new UiScrollable(new UiSelector().scrollable(true).instance(0))' \
404-
".scrollIntoView(#{arg}.instance(0));"
405-
return elem
406-
rescue StandardError => e
407-
raise e if index == args.size - 1
403+
if @@core.automation_name == :espresso
404+
@driver.find_element :accessibility_id, text
405+
else
406+
text = %("#{text}")
407+
rid = resource_id(text, "new UiSelector().resourceId(#{text});")
408+
args = if rid.empty?
409+
["new UiSelector().textContains(#{text})", "new UiSelector().descriptionContains(#{text})"]
410+
else
411+
[rid]
412+
end
413+
args.each_with_index do |arg, index|
414+
begin
415+
elem = @driver.find_element :uiautomator,
416+
'new UiScrollable(new UiSelector().scrollable(true).instance(0))' \
417+
".scrollIntoView(#{arg}.instance(0));"
418+
return elem
419+
rescue StandardError => e
420+
raise e if index == args.size - 1
421+
end
408422
end
409423
end
410424
end

test/functional/android/android/image_comparison_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def teardown
1616
end
1717

1818
def test_image_comparison_match_result
19+
skip 'Requres `npm install -g appium opencv4nodejs`' if `which opencv4nodejs`.empty?
20+
1921
image1 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_normal.png')
2022
image2 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_has_blue.png')
2123

@@ -31,6 +33,8 @@ def test_image_comparison_match_result
3133
end
3234

3335
def test_image_comparison_find_result
36+
skip 'Requres `npm install -g appium opencv4nodejs`' if `which opencv4nodejs`.empty?
37+
3438
image1 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_normal.png')
3539
image2 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_has_blue.png')
3640

@@ -46,6 +50,8 @@ def test_image_comparison_find_result
4650
end
4751

4852
def test_image_comparison_get_images_result
53+
skip 'Requres `npm install -g appium opencv4nodejs`' if `which opencv4nodejs`.empty?
54+
4955
image1 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_normal.png')
5056
image2 = File.read AppiumLibCoreTest.path_of('test/functional/data/test_has_blue.png')
5157

test/functional/android/webdriver/device_test.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ def test_page_source
6868
xml = REXML::Document.new s_source
6969

7070
assert s_source.include?('io.appium.android.apis')
71-
assert_equal expected, xml[2].elements.each('//*') { |v| v }.map(&:name) # rubocop:disable Lint/Void:
71+
72+
if @@core.automation_name == :espresso
73+
assert_equal 130, xml[2].elements.each('//*') { |v| v }.map(&:name).size # rubocop:disable Lint/Void:
74+
else
75+
assert_equal expected, xml[2].elements.each('//*') { |v| v }.map(&:name) # rubocop:disable Lint/Void:
76+
end
7277
end
7378

7479
# def test_location
@@ -107,7 +112,7 @@ def test_dismiss_alert
107112
# assert @driver.switch_to.alert.dismiss
108113

109114
# Because the results depends on OS version.
110-
@@core.wait { assert_equal 'CANCEL', @driver.find_element(:id, 'android:id/button2').name.upcase }
115+
@@core.wait { assert_equal 'CANCEL', @driver.find_element(:id, 'android:id/button2').text.upcase }
111116
assert @driver.find_element(:id, 'android:id/button2').click
112117
end
113118

test/functional/android/webdriver/w3c_actions_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def test_tap_scroll
4242
.release
4343
.perform
4444

45+
# TODO: Selenium::WebDriver::Error::MoveTargetOutOfBoundsError: was raised in Espresso
46+
4547
@driver.manage.timeouts.implicit_wait = 3
4648
assert_raises ::Selenium::WebDriver::Error::NoSuchElementError do
4749
@driver.find_element(:accessibility_id, 'Custom')

test/functional/ios/webdriver/device_test.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def test_page_source
6262

6363
assert s_source.include?('AppiumAUT')
6464
assert s_source.include?('XCUIElementTypeApplication type')
65-
assert_equal 78, s_xml[2].elements.each('//*') { |v| v }.map(&:name).size # rubocop:disable Lint/Void:
65+
66+
assert [78, 81].include?(s_xml[2].elements.each('//*') { |v| v }.map(&:name).size) # rubocop:disable Lint/Void:
6667
end
6768

6869
def test_location

test/test_helper.rb

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
require 'minitest/reporters'
99
require 'minitest'
1010

11-
$VERBOSE = nil
1211
Appium::Logger.level = ::Logger::FATAL # Show Logger logs only they are fatal
1312

1413
Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new

test/unit/android/device/mjsonwp/image_comparison_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
require 'webmock/minitest'
33
require 'base64'
44

5-
# $ rake test:unit TEST=test/unit/android/device/mjsonwp/commands_test.rb
5+
# $ rake test:unit TEST=test/unit/android/device/mjsonwp/image_comparison_test.rb
66
class AppiumLibCoreTest
77
module Android
88
module Device
99
module MJSONWP
10-
class CommandsTest < Minitest::Test
10+
class ImageComparisonTest < Minitest::Test
1111
include AppiumLibCoreTest::Mock
1212

1313
def setup

0 commit comments

Comments
 (0)