calabashcalabash-ioscalabash-android

Calabash: Get state of toggle switch


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


Solution

  • 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.