In the process of studying calabash-cucumber for testing mobile applications, the question arose how to work with objects. For testing took the application iOS, and here is one of the Activites has 4 questions and 3 answers to each question. To pass to the next Activiti, you need to answer these questions, and the answer is a checkmark of the option opposite the question. The picture looks like this:
|1|0|0| or |1|0|0|
|0|1|0| or |1|0|0|
|0|0|1| or |1|0|0|
|1|0|0| or |0|0|1|
1 - the selected option (check-box);
0 - not selected field.
There are no bindings to the button - neither ID nor text. We have to find it by coordinates. And here's the question: how to set an object (button) with given coordinates, and then pass it a method (for example, object.touch(x, y)
) in the body of the step? There was an interest to check all the combinations, and there are 81 of them (in the steps it is very much) - it would be easier with the objects (you can write a counter for busting). Here are my attempts, but they do not work:
class Tapper
def tap(x, y)
perform_action('click_on_screen', x, y)
#or touch(nil, {:offset => {:x => x.to_i, :y => y.to_i}})
end
end
Then /^I touch on screen $/ do |x, y|
@answer_1_1 = Tapper.new
@answer_1_1.tap(802, 153)
end
The result is either:
undefined step
or:
undefined method 'perform_action' for Object
Calabash x-platform allows you to implement classes and object.