Adebayo
Adebayo

Reputation: 11

Calabash touch command works in calabash-ios console but not when running

I am in need of some serious help. When I input the touch command into the calabash-ios console, it works just as it should in every case. For example,

touch("view marked:'Select Accounts'") 

works exactly as it should.

However, when I actually run the tests with the exact same command, it does not work. It doesn't throw any error at all, but the action that is supposed to be initiated by the button click is not occurring. And it's frustrating me to no end...What's really killing me is that it's not a consistent issue, sometimes the touch command works just fine, other times it doesn't.

Has anyone else had an issue similar to this, and if so, were you able to discover what the problem was?

Thanks in advance! Ade

Upvotes: 1

Views: 510

Answers (3)

kubano
kubano

Reputation: 651

First thing first, the best practice of localizing elements is using unique IDs. To accomplish that, you should fill the accessibilityIdentifier field of app elements in Xcode.

That's the most accurate way to identify objects. After that you can use queries like this:

query("* id:'account_select_button'")

Queries that use the "marked" syntax looking for matches in the text or accessibilityIdentifier properties of app objects. This method isn't suitable for multilanguage apps or if the labels change.

For waiting elements you should use this instead of sleep:

wait_for_element_exists("* marked:'Select Accounts'", :timeout => 10)
touch("* marked:'Select Accounts'")

By default, Calabash query only searches in attributes of visible objects. If an element is outside of the viewport, you need to scroll until the element appears before you can do anything with it:

while (query("* marked:'Select Accounts'").empty?) == true
    swipe :up      #it performs scroll down, swipe :up equals scroll up    
    sleep 1        #in this case you have to wait between two swipes
end

I have never tried, but there is another way. As I read, this expressions query in every view, regardless of elements visibility.

query("all marked:'Select Accounts'")
query("all view marked:'Select Accounts'")
query("all * marked:'Select Accounts'")

Upvotes: 1

dimrsilva
dimrsilva

Reputation: 161

It can be caused by animations. You can use the wait_for_none_animating method.

Click here for the docs.

Upvotes: 1

Lasse
Lasse

Reputation: 1163

This might be related to timing. OFten you will need to have small delay before the actual touch. You can test it quickly by adding a sleep(0.5) or something like that prior to the touch. You can also a wait_for statement before, but even with that you might need to add a little delay still to get it to work.

Upvotes: 0

Related Questions