[英]calabash/ruby while loop not ending
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. 但是while循环并没有结束,尽管它正确向下滚动并在找到文本字符串时停止了。
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. 是我一直在使用的红宝石。
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). 我已经编写了类似的步骤定义,它对我来说非常有效(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. element_does_not_exist()
和scroll_down
都是Calabash Ruby API的函数。
Instead scroll_down
you can try to use your function to scroll specified ScrollView. 相反scroll_down
你可以尝试用你的函数滚动指定滚动型。
(edit: Sorry, I didn't look at comments ;)) (编辑:对不起,我没有看评论;))
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. 如果60秒后找不到滚动文字,此方法将为您提供屏幕截图并引发错误。 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). (我只是从您的帖子中获取代码,因此,如果第一次出现问题,请尝试对此进行修改)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.