Skip to content

Commit dbd8762

Browse files
authored
Update deactive app for xcuitest (#502)
* update deactive app for XCUITest * add checking appium server version for background_app * add comments * remove a redundant line * add comment
1 parent e06b25e commit dbd8762

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

ios_tests/lib/ios/specs/device/device.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def go_back
5252
tag(UI::Inventory.navbar).name.must_equal 'UICatalog'
5353
end
5454

55+
t 'background_app homescreen' do
56+
background_app(-1) # background_app(nil) should work as same.
57+
screen.must_raise ::Selenium::WebDriver::Error::NoSuchElementError
58+
end
59+
5560
t 'reset' do
5661
reset
5762
end

lib/appium_lib/device/device.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ module Device
1313
# @!method background_app
1414
# Backgrounds the app for a set number of seconds.
1515
# This is a blocking application
16-
# @param seconds (int) How many seconds to background the app for.
16+
# @param [Integer] seconds How many seconds to background the app for.
17+
#
18+
# ```ruby
19+
# background_app
20+
# background_app(5)
21+
# background_app(-1) #=> the app never come back. https://github.com/appium/appium/issues/7741
22+
# ```
1723

1824
# @!method current_activity
1925

@@ -202,8 +208,14 @@ def app_installed?(app_id)
202208
end
203209

204210
add_endpoint_method(:background_app) do
205-
def background_app(duration)
206-
execute :background_app, {}, seconds: duration
211+
def background_app(duration = 0)
212+
# https://github.com/appium/ruby_lib/issues/500, https://github.com/appium/appium/issues/7741
213+
if $driver.automation_name_is_xcuitest? && $driver.appium_server_status['build']['version'] >= '1.6.4'
214+
duration_milli_sec = duration.nil? ? nil : duration * 1000
215+
execute :background_app, {}, seconds: { timeout: duration_milli_sec }
216+
else
217+
execute :background_app, {}, seconds: duration
218+
end
207219
end
208220
end
209221

lib/appium_lib/driver.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class Driver
299299
# If automation_name is nil, it is not set both client side and server side.
300300
attr_reader :automation_name
301301
# Appium's server version
302-
attr_reader :appium_server_version
302+
attr_reader :appium_server_status
303303
# Boolean debug mode for the Appium Ruby bindings
304304
attr_accessor :appium_debug
305305
# instance of AbstractEventListener for logging support
@@ -476,7 +476,7 @@ def automation_name_is_xcuitest?
476476
# If the Appium server is under REQUIRED_VERSION_XCUITEST, then error is raised.
477477
# @return [Boolean]
478478
def check_server_version_xcuitest
479-
if automation_name_is_xcuitest? && (@appium_server_version['build']['version'] < REQUIRED_VERSION_XCUITEST)
479+
if automation_name_is_xcuitest? && (@appium_server_status['build']['version'] < REQUIRED_VERSION_XCUITEST)
480480
raise Appium::Error::NotSupportedAppiumServer, "XCUITest requires Appium version >= #{REQUIRED_VERSION_XCUITEST}"
481481
end
482482
true
@@ -618,7 +618,7 @@ def start_driver
618618
raise "ERROR: Unable to connect to Appium. Is the server running on #{server_url}?"
619619
end
620620

621-
@appium_server_version = appium_server_version
621+
@appium_server_status = appium_server_version
622622

623623
check_server_version_xcuitest
624624
set_automation_name_if_nil

0 commit comments

Comments
 (0)