简体   繁体   中英

Calabash, Detect UIButton pressed state

I want to know is there a way to detect UIButton state from calabash/ruby.

Ex. Imagine I have a iphone app which contains a view with a round rect UIButton. This button will hold its state(if you pressed it, it will be on pressed state until you pressed it again). I want to know how to verify the state of that button from calabash test

Given I go to the Home Screen
   Then I should see "name" button is pressed

Seems Like I found a way to do it. ruby step for the functions is

Then /^I should see "([^\"]*)" is pressed$/ do |text|
    state = query("button marked:'#{text}'", :isSelected)[0]
    state = state.to_i
    if state!=1
      screenshot_and_raise "Current state is not Pressed for button: #{text}"
    end
    sleep(STEP_PAUSE)
end

which goes to steps.rb file

and In calabash feature file you can call it

Then I should see "NameBtn" is pressed

If anybody found improvements please add. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM