start_activity not working

I have been trying to use start_activity but it doesn’t seem to work for me

from appium import webdriver

def setup(self):
    self.driver.start_activity("packageName", "activityName")

I keep getting this error

AttributeError: 'WebDriver' object has no attribute 'start_activity'

I’m seeing this as well in Appium 1.3.3, on Android using Ruby

I’ve dug in here:

https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/appium-bindings.md

and it suggests the call should be

  self.start_activity("packageName", "activityName")

When I check the available methods on this object I find all methods are available EXCEPT start_activity. This looks like a bug to me.

I recommend looking at the test cases to see proper usage. start activity works correctly in Ruby.

I’ve updated my appium_lib to 5.0.1 where start_activity is available. I now see this error:

 Failure/Error: apm.appium_module.start_activity app_hash
 Selenium::WebDriver::Error::UnknownError:
   ERROR running Appium command: Cannot call method 'startApp' of null
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:640:in `raw_execute'
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:618:in `execute'
 # /Users/wosser/.rvm/gems/ruby-2.1.2/gems/appium_lib-5.0.1/lib/appium_lib/device/device.rb:180:in `start_activity'
 # ./spec/registration/existing_user_walkthrough_spec.rb:18:in `block (2 levels) in <top (required)>'

As I said, I’m on 1.3.3. I can try testing on 1.3.4 and see if that makes any difference.

Here is my code. I don’t believe I’m doing anything wrong. With these same values, the app starts up just fine when started automatically. I’m using these known values to test this api to make certain I understand it.

app_hash = {app_package: settings.app_package, app_activity: settings.app_activity}
apm.appium_module.start_activity app_hash

It turns out the problem for me now is that I am using close_app before opening it. This causes the server to call cleanup and dispose of the adb object. I’ll start another thread about whether that’s the right thing to do. For now, the solution to the problem above seems to be updating to at least 5.0.1 of appium_lib.

start_activity only works within a valid appium session and it’s an appium driver method. close_app disposing of adb is probably a bug.

Could you help me? I’m really new into Ruby and Appium and struggled some time with “activity”. methods, but without success.

How to use start_activity or current_activity it in Ruby? I have code (based on some tutorials):

config.before(:all) do
@driver = Appium::Driver.new(caps)
@driver.start_driver
end

but when I write:

@driver.current_activity
error is - method not found.

When I navigate to this class (Appium::Driver) in IntelliJ - it tells me about files: driver.rb or android/dynamic.rb located in:

C:/Programy/Ruby193/lib/ruby/gems/1.9.1/gems/appium_lib-3.0.3/lib/appium_lib/

When I search in files content in this location for string start_activity - I can’t found any file with this method. Is it method deprecated? Or I do something wrong? The same problem is with current_activity.

@czarnykwarc, The problem is, the driver you are creating has a class, driver that you need to access. In your code, I believe it should be

@driver.driver.current_activity

On the other hand, @driver.start_activity should work because it’s in the Appium::Driver object

@willosser thank you very much! After changing appium_lib version to 6.0.0 (I have… 3.0.3…) it works. IntelliJ still shows message that this method is not found, but when I run it, it works.

driver.startActivity();

It is showing error for appium java client 9.0.0, Could you please help me with this.

The method startActivity() is undefined for the type AndroidDriver