0

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>'
asinha
  • 337
  • 1
  • 6
  • 24

1 Answers1

0

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.

king_wayne
  • 222
  • 1
  • 9
  • Calabash does not need to open the app through url. As example my calabash installs the apk file at the beginning of test suite starts. Once the installation is done then ruby + selenium webdriver would open the browser and navigate to that url. Then it would open the same app which installed by calabash. Then calabash would click the login button etc and move on. I added some selenium code at the beginning of my question. However it does not work. – asinha Jun 29 '15 at 09:51
  • I think you should give Appium a try, which also utilizes WebDriver. I believe you may be able to do what you wish with that one instead of Calabash. – king_wayne Aug 28 '15 at 13:49