Clear field with calabash-ios
Recently while automating one of applications with calabash-ios we (QA team of Scimus) faced a problem with clearing a field with a certain text. When we would use one of out of box method
[code lang="ruby"]I clear (?:input|text) field number (\d+)[/code]
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.
[code lang="ruby"]
Then /^I clear a field with "([^\"]*)" text$/ do |name|
name = set_value name
element = query("UITextFieldLabel text: '#{name}'")[0]
touch(element)
wait_for_keyboard
name.to_s.split('').each do |c|
keyboard_enter_char 'Delete'
end
end
[/code]
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.