compare the position of the element with the previous element

73 views
Skip to first unread message

HP

unread,
Apr 13, 2015, 11:05:58 PM4/13/15
to calabash...@googlegroups.com
 
Hi,

I am relatively new to this group and to working with ruby and calabash. I have a situation and much appreciate your comments

I am trying to automate a test with calabash cucumber ruby for android. I am trying to assert that my element_to_find appears after so and so element

I tried query("Textview","text") to get all the text view elements and then tried query("Textview index:17") get the desired element

So would the code be something like this

if exists
list_of_elements= query("Textview","text")
compare_element_index=list_of_elements.index('16')
desired_element_index=list_of_elements.index('17')
if (compare_element+1).eql? (desired_element)
puts "the element position is correct"
else
fail " the element order is incorrect"
end

I want it to be as generic as possible.
Many Thanks

Cheers
HP
Message has been deleted

tobias....@xamarin.com

unread,
Apr 14, 2015, 4:52:10 AM4/14/15
to calabash...@googlegroups.com
You can access the y-coordinate of each view to assert their position relative to each other. For example


# Layout:
#
#    foo
#    bar
#    baz


queries
= ["* text:'foo'", "* text:'bar'", "* text:'baz'"]


previous_query
= nil
previous_result
= nil

queries
.each do |q|
  result
= query(q).first

  unless previous_result.nil?
    y
= result['rect']['y']
    previous_y
= previous_result['rect']['y']

   
if y < previous_y
     
raise "#{q} should be below #{previous_query}"
    end
 
end

  previous_query
= q
  previous_result
= result
end
   

haritha pidikiti

unread,
Apr 14, 2015, 6:08:03 PM4/14/15
to calabash...@googlegroups.com

Thanks for the prompt reply Tobias

I tried this and this worked
def position_of_element(current_entry, previous_entry)
list_of_elements= query("Textview marked:'Entry'","text")
puts "The events appear in the order #{list_of_elements}"
previous_element_index = list_of_elements.index("#{current_entry}")
next_element_index = previous_element_index + 1
element_to_find_index = list_of_elements.index("#{previous_entry}")
if next_element_index == element_to_find_index
puts "The event '#{current_entry}' occurs in correct order"
else
fail "The event '#{current_entry}' does not appear after '#{previous_entry}'"
end
end
Just want to make it more generic interms of passing Textview , entry and text to the query

What would be the assertion step for this ...

Then I see entry2 appears after entry1 when queried by Textview entry text.

or is there any better way of writing this

Cheers
HP



--
You received this message because you are subscribed to a topic in the Google Groups "calabash-android" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/calabash-android/UG9iiPQv6Wc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to calabash-andro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tobias....@xamarin.com

unread,
Apr 15, 2015, 4:20:02 AM4/15/15
to calabash...@googlegroups.com
Your code asserts that the order in which the elements are returned from the test server corresponds to their y-coordinate sorted order. This is not the case. I see no reason why the code snippet I provided will not suit your needs :)

haritha pidikiti

unread,
Apr 15, 2015, 5:08:11 PM4/15/15
to calabash...@googlegroups.com
Sure. I will see what u mean. Will try that. Thanks

- Haritha

Reply all
Reply to author
Forward
0 new messages