Skip to content

Commit 4569b0e

Browse files
Merge pull request #267 from 0x1mason/2969
Added start_activity function and tests
2 parents af6d44c + cfe9f29 commit 4569b0e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

android_tests/lib/android/specs/common/device.rb

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
wait { background_app 5 }
1616
end
1717

18+
t 'start_activity' do
19+
wait { current_activity.must_equal '.ApiDemos' }
20+
start_activity 'io.appium.android.apis', '.accessibility.AccessibilityNodeProviderActivity'
21+
wait { current_activity.include?('Node').must_equal true }
22+
start_activity 'com.android.contacts', '.ContactsListActivity'
23+
wait { current_activity.include?('Contact').must_equal true }
24+
end
25+
1826
t 'is_installed' do
1927
wait { is_installed?('fake_app').must_equal false }
2028
end

lib/appium_lib/device/device.rb

+30
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,36 @@ def background_app(duration)
151151
end
152152
end
153153

154+
# @!method start_activity
155+
# Start a new activity within the current app or launch a new app and start the target activity.
156+
#
157+
# Android only.
158+
# @param [String] The package owning the activity [required]
159+
# @param [String] The target activity [required]
160+
# @param [String] The package to start before the target package [optional]
161+
# @param [String] The activity to start before the target activity [optional]
162+
#
163+
# ```ruby
164+
# start_activity app_package: 'io.appium.android.apis', app_activity: '.accessibility.AccessibilityNodeProviderActivity'
165+
# ```
166+
add_endpoint_method(:start_activity, 'session/:session_id/appium/device/start_activity') do
167+
def start_activity(opts)
168+
raise 'opts must be a hash' unless opts.is_a? Hash
169+
app_package = opts[:app_package]
170+
raise 'app_package is required' unless app_package
171+
app_activity = opts[:app_activity]
172+
raise 'app_activity is required' unless opts[:app_activity]
173+
app_wait_package = opts.fetch(:app_wait_package, '')
174+
app_wait_activity = opts.fetch(:app_wait_activity, '')
175+
176+
unknown_opts = opts.keys - [:app_package, :app_activity, :app_wait_package, :app_wait_activity]
177+
raise "Unknown options #{unknown_opts}" unless unknown_opts.empty?
178+
179+
execute :start_activity, {}, { appPackage: app_package, appActivity: app_activity,
180+
appWaitPackage: app_wait_package, appWaitActivity: app_wait_activity }
181+
end
182+
end
183+
154184
add_endpoint_method(:set_context, 'session/:session_id/context') do
155185
def set_context(context=null)
156186
execute :set_context, {}, :name => context

0 commit comments

Comments
 (0)