Question

enter image description hereI'm trying a seat selection process for a bus. I have a seat layout with some seats booked ans some not booked. I need to select an unbooked seat. I need to create a loop by tapping random coordinates on the screen till i am able to tap on a unbooked seat. how can this be done using calabash.

Was it helpful?

Solution

This thread is a bit old. But anyways here goes something along the lines of what you are looking for.

You want to touch a certain set of coordinates on the screen, see if you select a seat and then read the fare value.

So you need a loop. You can use something like this. From you picture I can see that you only have 8 seats on there. But to make it quick lets just try and hit the the areas which also might have a seat and say that we are looking at 3x4 seats.

a = 0
b = 0
while a < 3
  while b < 4 
     b += 1
  end
  a += 1
end

The outer loop will run 3 times, that is from front to back. The inner loop will run 4 times, that is seats left to right.

Now we need to make sure that we click on each position, so we add

performAction('click_on_screen',<x-value>, <y-value>)

And combined we have something like this. Where you have x and y that are starting positions and should match the coordinates of the first seat. Then at first run you just click at that location and do what ever you need to get the fare price. After first click you increase the xOffset value by the distance between the two seats, and then you are ready to click on the second one. Please keep in mind, that I made this simpler so actually the second press will touch on the isle. But on the 3rd and the 4th you should again hit the seats. And then you do that for the two next rows afterwards.

a = 0
b = 0
x = 100
y = 500
xOffset = x;
while a < 3
  while b < 4  
     performAction('click_on_screen', xOffset, y)
     b += 1
     xOffset += 200 
  end
  xOffset = x
  y += 200
  a += 1
end

Best regards Lasse

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top