3

I am trying to get the state of a toggle switch in my native app.

This is the query of the switch itself, when ON:

query "Switch id:'quadrant_buzz'"

and its results

[
[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
}]

This is the result of the query when the switch is OFF:

[
[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
}]

I am unsure how to check for its on/off state. When I tap/touch the switch, nothing changes in the returned query. The only difference I see is the center-y.

Is there something in the Calabash Api for this?

Thanks

2 Answers2

4

Looking up the documentation for a Switch widget on Android developers it is the method "isChecked". http://developer.android.com/reference/android/widget/Switch.html

Therefore you can find this value in Calabash by invoking

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

You could also used just :checked in Calabash.

Tobias
  • 678
  • 4
  • 9
  • 1
    I tried using :checked before, but I will give this a shot. Ill dig around those android docs too, I didn't know I can use those! Thanks Tobias! – Nick Stalter Dec 13 '15 at 22:07
0

The isChecked works.

    irb(main):001:0> query("android.widget.Switch",:isChecked)
    [
       [0] true
    ]