Clear field with calabash-ios

Recently while automating one of applications with calabash-ios we faced a problem with clearing a field with a certain text. When we would use one of out of box method

I clear (?:input|text) field number (\d+)

it would work for the first time but then would start failing. As field was cleared, but iOS remembers a previous state and puts the same value back with autoselected. So technically this steps works fine, it clears a field but then puts it back and our test for edit field did not work as expected.
This is a soltion that we implemented in order to fix this problem.

Then /^I clear a field with "([^\"]*)" text$/ do |name|
   name = set_value name
   element = query("UITextFieldLabel text: '#{name}'")[0]
   name.to_s.split('').each do |c|
      keyboard_enter_char 'Delete'

It is just pretty simple solution, you tap to erase a number of character in a field times and field becomes empty. Works every time and test is stable now. I hope it will help someone out there.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s