Search code examples
iosrubyuiswitchcalabashfrank

How to change the value of a Switch in Frank / Calabash


I have a switch with a view, say 'switch_view'. I need to change it for an automation test. How do I do this? My work till now is:

def switch(switch_view)
    # Get the value of the switch
    switch_state = (frankly_map(switch_view, 'isON')).first
    switch_state[0] = !switch_state[0]
    touch(switch_view)
end

As you can see, this is just an amalgamation of all the stuff I have tried out till now and that damn switch has still not moved. Please do help me out.


Solution

  • I figured it out. But I thought I should leave it here since it might be the cause of quite some confusion. The key is to use the in-build tap_and_hold method.

    def switch(switch_view)
      tap_and_hold(switch_view)
      sleep 1 # For the animation
    end
    

    You can combine this with prior information about the state and create definite tests as well.