Skip to content

Commit

Permalink
Add tests (#173)
Browse files Browse the repository at this point in the history
* add backdoor test

* add deprecation
  • Loading branch information
KazuCocoa authored Dec 4, 2018
1 parent 116e78a commit 2a3ea37
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ $ appium --log-level warn:error # show only warning and error logs
$ ruby test.rb
```

# Development
- Demo app
- https://android.googlesource.com/platform/development/+/master/samples/ApiDemos

# Release
Use [appium_thor](https://github.com/appium/appium_thor) to release this gem.

Expand Down
2 changes: 2 additions & 0 deletions lib/appium_lib_core/common/base/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def keyboard_shown?
end
alias is_keyboard_shown keyboard_shown?

# [DEPRECATION]
# Send keys for a current active element
# @param [String] key Input text
#
Expand All @@ -109,6 +110,7 @@ def keyboard_shown?
# @driver.send_keys 'happy testing!'
#
def send_keys(*key)
warn '[DEPRECATION] Driver#send_keys is deprecated in W3C spec. Use driver.action.<command>.perform instead'
@bridge.send_keys_to_active_element(key)
end
alias type send_keys
Expand Down
26 changes: 19 additions & 7 deletions test/functional/android/android/mobile_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def teardown
def test_toast
skip unless @core.automation_name == :espresso

caps = Caps.android 'io.appium.android.apis.view.SecureView'
@core = ::Appium::Core.for(caps)
@driver = @core.start_driver

@driver.find_element(:accessibility_id, 'Views').click
@driver.find_element(:accessibility_id, 'Secure View').click
@driver.find_element(:id, 'id/secure_view_toast_button').click
@driver.find_element(:id, 'io.appium.android.apis:id/secure_view_toast_button').click

assert @driver.execute_script 'mobile: isToastVisible', { text: 'A toast', isRegexp: true }

Expand All @@ -46,8 +46,7 @@ def test_drawer
def test_datepicker
skip unless @core.automation_name == :espresso

caps = Caps.android.dup
caps[:desired_capabilities][:appActivity] = 'io.appium.android.apis.view.DateWidgets1'
caps = Caps.android 'io.appium.android.apis.view.DateWidgets1'
@core = ::Appium::Core.for(caps)
@driver = @core.start_driver

Expand All @@ -62,8 +61,7 @@ def test_datepicker
def test_timepicker
skip unless @core.automation_name == :espresso

caps = Caps.android.dup
caps[:desired_capabilities][:appActivity] = 'io.appium.android.apis.view.DateWidgets2'
caps = Caps.android 'io.appium.android.apis.view.DateWidgets2'
@core = ::Appium::Core.for(caps)
@driver = @core.start_driver

Expand Down Expand Up @@ -94,6 +92,7 @@ def test_navigate_to
end

# @since Appium 1.11.0 (Newer than 1.10.0)
# It can work with `ViewPager` https://developer.android.com/reference/android/support/v4/view/ViewPager
def test_scroll_page_on_view_pager
skip unless @core.automation_name == :espresso

Expand All @@ -117,6 +116,19 @@ def test_scroll_page_on_view_pager
'Could not perform scroll to on element'
end

# @since Appium 1.11.0 (Newer than 1.10.0)
# https://github.com/appium/appium-espresso-driver/blob/0e03d2ca63dd0e77277aa3c493d239456bc2a899/lib/commands/general.js#L135-L174
def test_backdoor
skip unless @core.automation_name == :espresso

caps = Caps.android 'io.appium.android.apis.view.TextSwitcher1'
@core = ::Appium::Core.for(caps)
@driver = @core.start_driver

assert_mobile_command_error 'mobile: backdoor', { target: :activity, methods: [{ name: 'noMethod', args: [] }] },
'No public method noMethod definded on class io.appium.android.apis.view.TextSwitcher1'
end

private

def assert_mobile_command_error(command, args, expected_message)
Expand Down
8 changes: 4 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def self.ios
new.ios
end

def self.android
new.android
def self.android(activity_name = nil)
new.android(activity_name)
end

def self.android_web
Expand Down Expand Up @@ -99,7 +99,7 @@ def ios

# Require a real device or an emulator.
# We should update platformVersion and deviceName to fit your environment.
def android
def android(activity_name = nil)
{
desired_capabilities: { # :caps is also available
platformName: :android,
Expand All @@ -108,7 +108,7 @@ def android
udid: get_udid_name,
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis',
appActivity: 'io.appium.android.apis.ApiDemos',
appActivity: activity_name || 'io.appium.android.apis.ApiDemos',
someCapability: 'some_capability',
unicodeKeyboard: true,
resetKeyboard: true,
Expand Down

0 comments on commit 2a3ea37

Please sign in to comment.