calabash-automate the app which gets opened by hitting a link from browser

442 views Asked by At

I have already my calabash android set up there which is working fine. Now I have to add a scenario where in android emulator I need to open the default browser navigate to an url ( i.e https://def/l/abc) It would open the app assuming the app is already installed. Then I can login to the app and move on. How I can automate this through calabash . Particularly open the browser and click the link . Assume that my emulator is already opened. I found something like

 require 'selenium-webdriver'

caps = Selenium::WebDriver::Remote::Capabilities.android
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 480
driver = Selenium::WebDriver.for(
:remote,
:http_client => client,
:desired_capabilities => caps,
)
driver.navigate.to "http://www.google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver! 

However it always giving error as

 ruby test.rb
 /.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/net/http.rb:878:in   `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
    from /Users/asinha/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/net/http.rb:878:in `open'
   from /Users/asinha/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
   from /Users/asinha/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
    from /Users/asinha/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/net/http.rb:877:in `connect'
    from /Users/asinha/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
    from /Users/asinha/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/net/http.rb:851:in `start'
    from /Users/asinha/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/2.0.0/net/http.rb:1367:in `request'
    from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/default.rb:107:in `response_for'
    from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/default.rb:58:in `request'
    from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
    from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:657:in `raw_execute'
    from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:122:in `create_session'
    from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:87:in `initialize'
    from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/common/driver.rb:52:in `new'
    from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/common/driver.rb:52:in `for'
   from /Users/asinha/.rvm/gems/ruby-2.0.0-p598/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver.rb:84:in `for'
from test.rb:6:in `<main>'
1

There are 1 answers

2
king_wayne On

I think you may be confusing what Calabash is used for. Calabash is used for testing iOS and Android apps. To the best of my knowledge, Calabash does not support what you're attempting to do. If I'm wrong in assuming that Calabash cannot open your app via a url, then you would still need to add <uses-permission android:name="android.permission.INJECT_EVENTS"/> to your Android manifest file in order to be able to use the "native" functionality of your phone, such as pressing the home button, pressing the back button, etc. Then you're going to face the problem of not being able to launch your web browser. Calabash uses your apk file to install the app on your phone to replace using a simulator. Calabash is therefore in somewhat of a "sandbox" environment because it does not know how to communicate with your device's firmware and hardware. Therefore, to the best of my knowledge, what you're trying to do is not in the scope of what Calabash achieves. Hope this helps.