0

我已经在那里设置了我的葫芦 android,它工作正常。现在我必须添加一个场景,在 android 模拟器中我需要打开默认浏览器导航到一个 url(即https://def/l/abc)假设应用程序已经安装,它将打开应用程序。然后我可以登录应用程序并继续前进。我如何通过 calabash 自动执行此操作。特别是打开浏览器并单击链接。假设我的模拟器已经打开。我发现了类似的东西

 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! 

但是它总是给出错误

 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>'
4

1 回答 1

0

我想你可能会混淆葫芦的用途。Calabash 用于测试 iOS 和 Android 应用程序。据我所知,Calabash 不支持您尝试做的事情。如果我假设 Calabash 无法通过 url 打开您的应用程序是错误的,那么您仍然需要添加<uses-permission android:name="android.permission.INJECT_EVENTS"/>到您的Android清单文件,以便能够使用手机的“本机”功能,例如按主页按钮,按返回按钮等。然后您将面临无法启动的问题您的网络浏览器。Calabash 使用您的 apk 文件在您的手机上安装应用程序以替换使用模拟器。因此,Calabash 处于某种“沙盒”环境中,因为它不知道如何与设备的固件和硬件进行通信。因此,据我所知,您尝试做的事情不在 Calabash 所达到的范围内。希望这可以帮助。

于 2015-06-26T16:55:01.100 回答