【问题标题】:Calabash: Get state of toggle switchCalabash:获取拨动开关的状态
【发布时间】:2016-03-17 21:54:38
【问题描述】:

我正在尝试在我的原生应用中获取切换开关的状态。

这是开关本身的查询,当ON时:

query "Switch id:'quadrant_buzz'"

及其结果

[
[0] {
                 "class" => "android.widget.Switch",
                   "tag" => nil,
           "description" => "android.widget.Switch{29ddf658 VFED..C. ........ 877,0-1017,81 #7f10017f app:id/quadrant_buzz}",
                    "id" => "quadrant_buzz",
                  "text" => "",
               "visible" => true,
                  "rect" => {
          "height" => 81,
           "width" => 140,
               "y" => 1303,
               "x" => 877,
        "center_x" => 947,
        "center_y" => 1343
    },
               "enabled" => true,
    "contentDescription" => nil
}]

这是开关关闭时的查询结果:

[
[0] {
                 "class" => "android.widget.Switch",
                   "tag" => nil,
           "description" => "android.widget.Switch{29ddf658 VFED..C. ........ 877,0-1017,81 #7f10017f app:id/quadrant_buzz}",
                    "id" => "quadrant_buzz",
                  "text" => "",
               "visible" => true,
                  "rect" => {
          "height" => 81,
           "width" => 140,
               "y" => 1213,
               "x" => 877,
        "center_x" => 947,
        "center_y" => 1253
    },
               "enabled" => true,
    "contentDescription" => nil
}]

我不确定如何检查其开/关状态。当我点击/触摸开关时,返回的查询没有任何变化。我看到的唯一区别是中心 Y。

Calabash Api 中有什么东西吗?

谢谢

【问题讨论】:

    标签: calabash calabash-ios calabash-android


    【解决方案1】:

    在 Android 开发人员上查找 Switch 小部件的文档,它是“isChecked”方法。 http://developer.android.com/reference/android/widget/Switch.html

    因此你可以通过调用在 Calabash 中找到这个值

    query("Switch id:'quadrant_buzz'", :isChecked)

    你也可以只使用 :checked in Calabash。

    【讨论】:

    • 我之前尝试过使用 :checked,但我会试一试。我也会挖掘那些 android 文档,我不知道我可以使用那些!谢谢托比亚斯!
    【解决方案2】:

    isChecked 有效。

    irb(main):001:0> 查询("android.widget.Switch",:isChecked) [ [0] 真 ]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      • 1970-01-01
      相关资源
      最近更新 更多