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
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AllCops:
TargetRubyVersion: 3.1
Layout/LineLength:
Max: 128
Enabled: false
Layout/RescueEnsureAlignment:
Enabled: false
Layout/EmptyLinesAroundAttributeAccessor:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ Run unit tests which check each method and command, URL, using the webmock.

```bash
$ bundle install
$ bundle exec parallel_test test/unit/
$ UNIT_TEST=1 bundle exec parallel_test test/unit/
```

or

```bash
$ bundle install
$ bundle exec rake test:unit
$ UNIT_TEST=1 bundle exec rake test:unit
```

### Functional Tests
Expand Down
4 changes: 0 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,27 @@ namespace :test do
namespace :unit do
desc('Run all iOS related unit tests in test directory')
Rake::TestTask.new(:ios) do |t|
ENV['UNIT_TEST'] = '1'
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/unit/ios/**/*_test.rb']
end

desc('Run all Android related unit tests in test directory')
Rake::TestTask.new(:android) do |t|
ENV['UNIT_TEST'] = '1'
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/unit/android/**/*_test.rb']
end

desc('Run all common related unit tests in test directory')
Rake::TestTask.new(:common) do |t|
ENV['UNIT_TEST'] = '1'
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/unit/common/**/*_test.rb']
end

desc('Run all Windows related unit tests in test directory')
Rake::TestTask.new(:windows) do |t|
ENV['UNIT_TEST'] = '1'
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/unit/windows/**/*_test.rb']
Expand Down
4 changes: 0 additions & 4 deletions lib/appium_lib_core/android/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ module Android
module Device
extend Forwardable

# rubocop:disable Layout/LineLength

# @!method open_notifications
# Open Android notifications
#
Expand Down Expand Up @@ -244,8 +242,6 @@ module Device
## class << self
####

# rubocop:enable Layout/LineLength

class << self
def extended(_mod)
::Appium::Core::Device.extend_webdriver_with_forwardable
Expand Down
16 changes: 4 additions & 12 deletions lib/appium_lib_core/android/device/emulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ def send_sms(phone_number:, message:)

::Appium::Core::Device.add_endpoint_method(:gsm_call) do
def gsm_call(phone_number:, action:)
unless GSM_CALL_ACTIONS.member? action.to_sym
raise ::Appium::Core::Error::ArgumentError, "action: should be member of #{GSM_CALL_ACTIONS}. Not #{action}."
end
raise ::Appium::Core::Error::ArgumentError, "action: should be member of #{GSM_CALL_ACTIONS}. Not #{action}." unless GSM_CALL_ACTIONS.member? action.to_sym

execute_script 'mobile:gsmCall', { phoneNumber: phone_number, action: action }
end
Expand All @@ -142,9 +140,7 @@ def gsm_signal(signal_strength)

::Appium::Core::Device.add_endpoint_method(:gsm_voice) do
def gsm_voice(state)
unless GSM_VOICE_STATES.member? state.to_sym
raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{GSM_VOICE_STATES}. Not #{state}."
end
raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{GSM_VOICE_STATES}. Not #{state}." unless GSM_VOICE_STATES.member? state.to_sym

execute_script 'mobile:gsmVoice', { state: state }
end
Expand All @@ -163,19 +159,15 @@ def set_network_speed(netspeed)

::Appium::Core::Device.add_endpoint_method(:set_power_capacity) do
def set_power_capacity(percent)
unless (0..100).member? percent
::Appium::Logger.warn "The percent should be between 0 and 100. Not #{percent}."
end
::Appium::Logger.warn "The percent should be between 0 and 100. Not #{percent}." unless (0..100).member? percent

execute_script 'mobile:powerCapacity', { percent: percent }
end
end

::Appium::Core::Device.add_endpoint_method(:set_power_ac) do
def set_power_ac(state)
unless POWER_AC_STATE.member? state.to_sym
raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{POWER_AC_STATE}. Not #{state}."
end
raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{POWER_AC_STATE}. Not #{state}." unless POWER_AC_STATE.member? state.to_sym

execute_script 'mobile:powerAc', { state: state }
end
Expand Down
4 changes: 1 addition & 3 deletions lib/appium_lib_core/android/device/screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def start_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT'
option[:bitRate] = bit_rate unless bit_rate.nil?

unless bug_report.nil?
unless [true, false].member?(bug_report)
raise ::Appium::Core::Error::ArgumentError, 'bug_report should be true or false'
end
raise ::Appium::Core::Error::ArgumentError, 'bug_report should be true or false' unless [true, false].member?(bug_report)

option[:bugReport] = bug_report
end
Expand Down
2 changes: 1 addition & 1 deletion lib/appium_lib_core/common/base/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def attach_to(session_id, platform_name, automation_name)
# caps: {
# platformName: :ios,
# automationName: 'XCUITest',
# app: 'test/functional/app/UICatalog.app.zip',
# app: 'test/functional/app/UIKitCatalog-iphonesimulator.zip',
# platformVersion: '11.4',
# deviceName: 'iPhone Simulator',
# useNewWDA: true,
Expand Down
4 changes: 1 addition & 3 deletions lib/appium_lib_core/common/base/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ def update_sending_request_to(protocol:, host:, port:, path:)
# @driver.test_action_command(e.id, 'action')
#
def add_command(method:, url:, name:, &block)
unless AVAILABLE_METHODS.include? method
raise ::Appium::Core::Error::ArgumentError, "Available method is either #{AVAILABLE_METHODS}"
end
raise ::Appium::Core::Error::ArgumentError, "Available method is either #{AVAILABLE_METHODS}" unless AVAILABLE_METHODS.include? method

@bridge.add_command method: method, url: url, name: name, &block
end
Expand Down
4 changes: 1 addition & 3 deletions lib/appium_lib_core/common/base/has_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def location
# driver.location = ::Appium::Location.new(10, 10, 10)
#
def location=(location)
unless location.is_a?(::Appium::Location)
raise TypeError, "expected #{::Appium::Location}, got #{location.inspect}:#{location.class}"
end
raise TypeError, "expected #{::Appium::Location}, got #{location.inspect}:#{location.class}" unless location.is_a?(::Appium::Location)

@bridge.set_location location.latitude, location.longitude, location.altitude
end
Expand Down
4 changes: 1 addition & 3 deletions lib/appium_lib_core/common/base/rotable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ module Rotatable
#
#
def rotation=(orientation)
unless ORIENTATIONS.include?(orientation)
raise ::Appium::Core::Error::ArgumentError, "expected #{ORIENTATIONS.inspect}, got #{orientation.inspect}"
end
raise ::Appium::Core::Error::ArgumentError, "expected #{ORIENTATIONS.inspect}, got #{orientation.inspect}" unless ORIENTATIONS.include?(orientation)

bridge.screen_orientation = orientation.to_s.upcase
end
Expand Down
2 changes: 0 additions & 2 deletions lib/appium_lib_core/common/base/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Appium
module Core
class Base
module SearchContext
# rubocop:disable Layout/LineLength
#
# Find the first element matching the given arguments
#
Expand Down Expand Up @@ -89,7 +88,6 @@ module SearchContext
# e = find_element :class_chain, "**/XCUIElementTypeStaticText[$name == 'Buttons'$]"
# e.tag_name #=> "XCUIElementTypeStaticText"
#
# rubocop:enable Layout/LineLength
APPIUM_EXTRA_FINDERS = {
accessibility_id: 'accessibility id',
image: '-image',
Expand Down
15 changes: 3 additions & 12 deletions lib/appium_lib_core/common/device/image_comparison.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,9 @@ def match_images_features(first_image:,
match_func: 'BruteForce',
good_matches_factor: nil,
visualize: false)
unless MATCH_FEATURES[:detector_name].member?(detector_name.to_s)
raise ::Appium::Core::Error::ArgumentError, "detector_name should be #{MATCH_FEATURES[:detector_name]}"
end

unless MATCH_FEATURES[:match_func].member?(match_func.to_s)
raise ::Appium::Core::Error::ArgumentError, "match_func should be #{MATCH_FEATURES[:match_func]}"
end

unless MATCH_FEATURES[:visualize].member?(visualize)
raise ::Appium::Core::Error::ArgumentError,
"visualize should be #{MATCH_FEATURES[:visualize]}"
end
raise ::Appium::Core::Error::ArgumentError, "detector_name should be #{MATCH_FEATURES[:detector_name]}" unless MATCH_FEATURES[:detector_name].member?(detector_name.to_s)
raise ::Appium::Core::Error::ArgumentError, "match_func should be #{MATCH_FEATURES[:match_func]}" unless MATCH_FEATURES[:match_func].member?(match_func.to_s)
raise ::Appium::Core::Error::ArgumentError, "visualize should be #{MATCH_FEATURES[:visualize]}" unless MATCH_FEATURES[:visualize].member?(visualize)

options = {}
options[:detectorName] = detector_name.to_s.upcase
Expand Down
4 changes: 1 addition & 3 deletions lib/appium_lib_core/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,7 @@ def set_implicit_wait_by_default(wait)

@driver.manage.timeouts.implicit_wait = wait
rescue ::Selenium::WebDriver::Error::UnknownError => e
unless e.message.include?('The operation requested is not yet implemented')
raise ::Appium::Core::Error::ServerError, e.message
end
raise ::Appium::Core::Error::ServerError, e.message unless e.message.include?('The operation requested is not yet implemented')

::Appium::Logger.debug(e.message)
{}
Expand Down
5 changes: 0 additions & 5 deletions lib/appium_lib_core/ios/xcuitest/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ module Ios
module Xcuitest
module Device
extend Forwardable

# rubocop:disable Layout/LineLength

# @!method hide_keyboard(close_key = nil)
# Hide the onscreen keyboard
# @param [String] close_key The name of the key which closes the keyboard.
Expand Down Expand Up @@ -168,8 +165,6 @@ module Device
# @driver.battery_info #=> { state: :full, level: 0.7 }
#

# rubocop:enable Layout/LineLength

####
## class << self
####
Expand Down
5 changes: 0 additions & 5 deletions lib/appium_lib_core/mac2/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ module Core
module Mac2
module Device
extend Forwardable

# rubocop:disable Layout/LineLength

# @since Appium 1.20.0
# @!method start_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT', file_field_name: nil, form_fields: nil, headers: nil, force_restart: nil, fps: nil, preset: nil, video_filter: nil, enable_capture_clicks: nil, enable_cursor_capture: nil, device_id: nil, time_limit: nil)
#
Expand Down Expand Up @@ -75,8 +72,6 @@ module Device
# @driver.start_recording_screen fps: 30, enable_cursor_capture: true
#

# rubocop:enable Layout/LineLength

####
## class << self
####
Expand Down
5 changes: 0 additions & 5 deletions lib/appium_lib_core/windows/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ module Core
module Windows
module Device
extend Forwardable

# rubocop:disable Layout/LineLength

# @since Appium 1.18.0
# @!method start_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT', force_restart: nil, time_limit: nil, fps: nil, preset: nil, video_filter: nil, capture_clicks: nil, capture_cursor: nil, audio_input: nil)
#
Expand Down Expand Up @@ -69,8 +66,6 @@ module Device
# @driver.start_recording_screen capture_cursor: true, capture_clicks: true, time_limit: '260'
#

# rubocop:enable Layout/LineLength

####
## class << self
####
Expand Down
2 changes: 1 addition & 1 deletion sig/lib/appium_lib_core/common/base/bridge.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module Appium
# caps: {
# platformName: :ios,
# automationName: 'XCUITest',
# app: 'test/functional/app/UICatalog.app.zip',
# app: 'test/functional/app/UIKitCatalog-iphonesimulator.zip',
# platformVersion: '11.4',
# deviceName: 'iPhone Simulator',
# useNewWDA: true,
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_re_install
@driver.remove_app 'io.appium.android.apis'
assert !@driver.app_installed?('io.appium.android.apis')

@driver.install_app "#{Dir.pwd}/#{Caps.android[:capabilities][:app]}"
@driver.install_app Caps.android[:capabilities][:app]
assert @driver.app_installed?('io.appium.android.apis')

assert !@driver.app_installed?('fake_app')
Expand Down
8 changes: 2 additions & 6 deletions test/functional/android/android/image_comparison_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def test_image_comparison_get_images_result

def test_image_element
skip_as_appium_version '1.9.0'
if @@core.automation_name == :espresso
skip 'Espresso does not support find_element since it does not support settings API'
end
skip 'Espresso does not support find_element since it does not support settings API' if @@core.automation_name == :espresso

@driver.rotation = :portrait

Expand Down Expand Up @@ -143,9 +141,7 @@ def test_image_element

def test_image_elements
skip_as_appium_version '1.9.0'
if @@core.automation_name == :espresso
skip 'Espresso does not support find_element since it does not support settings API'
end
skip 'Espresso does not support find_element since it does not support settings API' if @@core.automation_name == :espresso

@driver.update_settings(
{
Expand Down
5 changes: 3 additions & 2 deletions test/functional/android/android/mobile_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ def test_navigate_to
'must be a non-negative number'
assert_mobile_command_error 'mobile: navigateTo', { elementId: el.id, menuItemId: 'no element' },
'must be a non-negative number'
# Skip this line since the espresso driver/server easy to break with the dependencies.
# A test demo apk has no the element
assert_mobile_command_error 'mobile: navigateTo', { elementId: el.id, menuItemId: 10 },
'Could not navigate to menu item 10'
# assert_mobile_command_error 'mobile: navigateTo', { elementId: el.id, menuItemId: 10 },
# 'Could not navigate to menu item 10'
end

# @since Appium 1.11.0 (Newer than 1.10.0)
Expand Down
2 changes: 2 additions & 0 deletions test/functional/android/webdriver/bidi_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class AppiumLibCoreTest
module WebDriver
class BidiTest < AppiumLibCoreTest::Function::TestCase
def test_bidi
skip 'Skipping to running BIDI on CI since it is unstable on CI while it works on local' if ci?

caps = Caps.android
caps[:capabilities]['webSocketUrl'] = true
core = ::Appium::Core.for(caps)
Expand Down
Binary file removed test/functional/app/UICatalog.app.zip
Binary file not shown.
Binary file removed test/functional/app/VodQA.apk.zip
Binary file not shown.
Binary file removed test/functional/app/VodQAReactNative.app.zip
Binary file not shown.
Binary file removed test/functional/app/api.apk
Binary file not shown.
Binary file removed test/functional/app/api.apk.zip
Binary file not shown.
Binary file removed test/functional/app/iOS13__UICatalog.app.zip
Binary file not shown.
30 changes: 7 additions & 23 deletions test/functional/ios/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@ class DriverTest < AppiumLibCoreTest::Function::TestCase
private

def alert_view_cell
if over_ios17? @@driver
'Alert Views'
elsif over_ios13? @@driver
'Alert Controller'
else
'Alert Views'
end
over_ios17?(@@driver) ? 'Alert Views' : 'Alert Controller'
end

def uicatalog
over_ios13?(@@driver) ? 'UIKitCatalog' : 'UICatalog'
'UIKitCatalog'
end

public
Expand Down Expand Up @@ -88,21 +82,11 @@ def test_click_back
e = @@driver.find_element :accessibility_id, alert_view_cell
e.click
sleep 1 # wait for animation
if over_ios13?(@@driver)
begin
e.click # nothing happens
rescue ::Selenium::WebDriver::Error::StaleElementReferenceError
# This case also could happen
assert true
end
else
error = assert_raises do
e.click
end
assert [::Selenium::WebDriver::Error::UnknownError,
::Selenium::WebDriver::Error::ElementNotVisibleError,
::Selenium::WebDriver::Error::InvalidSelectorError].include? error.class
assert error.message.include? ' is not visible on the screen and thus is not interactable'
begin
e.click # nothing happens
rescue ::Selenium::WebDriver::Error::StaleElementReferenceError
# This case also could happen
assert true
end
@@driver.back
end
Expand Down
Loading
Loading