0

In short i have a custom step definition to scroll down a page of search results until a text string is found.

It's scrolling down and finding the text string

But the while loop is not ending, despite it correctly scrolling down and stopping when the text string is found.

This is obviously causing me no end of but hurt.

Then /^I scroll until I see the "This is a test" text$/ do 
  q = query("android.widget.TextView text:'This is a test'")
  while q.empty?
    scroll("android.view.View id:'search_listView'", :down)
    q = query("android.widget.TextView text:'This is a test'")
  end
end

is the ruby that I've been using.

  • I don't believe there's enough information here to determine the cause of the problem. The loop will break when `q.empty?` returns false. If `q.empty?` never returns false, the loop will go on forever. – Ajedi32 Aug 27 '14 at 14:42
  • OK, but isn't the query("android.widget.TextView text:'This is a test'") when it finds the text string changing q.empty to false – Grizzled Newbie Aug 27 '14 at 14:52
  • 1
    Obviously not, otherwise the loop would terminate. Or perhaps your assumption is wrong and `query("android.widget.TextView text:'This is a test'")` isn't finding the test string. One of those two must be true. Consider adding some debug code, or perhaps using something like pry debugger to examine the cause of the problem manually. – Ajedi32 Aug 27 '14 at 14:54
  • Yup my assumption was wrong. Despite it appearing to find the text string. ` q = query("android.widget.TextView id:`idoftextviewelementinquestion'" "This is a test") ` is the query that I should have used, and that causes it to work. @Ajedi32, thanks for nudging me along. Plus, that conical hat with the D on it, it's mine, thanks. – Grizzled Newbie Aug 27 '14 at 15:20

2 Answers2

0

Which version of Calabash do you use? I have written similiar step definition and it works perfectly for me (Calabash 0.5.1, Ruby 2.1.2).

Here is the code (I think it's more universal and simple):

Then /^I scroll down until I see '(.*?)' text$/ do |text|
  while element_does_not_exist("TextView marked:'#{text}'")
    scroll_down
  end
end

Both element_does_not_exist() and scroll_down are Calabash Ruby API's functions.

Instead scroll_down you can try to use your function to scroll specified ScrollView.

(edit: Sorry, I didn't look at comments ;))

kjuri
  • 158
  • 1
  • 10
0

Try This...

def scroll_to_text(text)
  element = "android.widget.TextView text:'#{text}'"
  if !element_exists(element)
    wait_poll(:until_exists => element, :timeout => 60, :screenshot_on_error => true) do
      scroll("android.view.View id:'search_listView'", :down)
    end
  end
end

This method will give you a screenshot and raise an error if it didn't find the text scrolling after 60 seconds. you can modify to use as you wanted. (I just get the code from your post so if something is wrong at the first time try modifying this).