Commit 22e34639 authored by Tails developers's avatar Tails developers
Browse files

Refactor.

The (lower) camelCase naming scheme is a trial to stay consistent with
Sikuli's api, which has e.g. findAll. I know that our other Sikuli
helpers follow the underscore-separation scheme, so this isn't very
consistent any way. Oh well.
parent 872088ac
...@@ -155,24 +155,7 @@ When /^I join some empty multi-user chat$/ do ...@@ -155,24 +155,7 @@ When /^I join some empty multi-user chat$/ do
# Room" prompt that Pidgin shows for some server configurations. # Room" prompt that Pidgin shows for some server configurations.
images = ["PidginCreateNewRoomPrompt.png", images = ["PidginCreateNewRoomPrompt.png",
"PidginChat1UserInRoom.png"] "PidginChat1UserInRoom.png"]
image_found = nil image_found, _ = @screen.waitAny(images, 30)
try_for(30, :msg => "Expected either the chatroom window or a prompt " +
"for creating a new chat room, but got neither") do
for image in images
begin
@screen.find(image)
image_found = image
break
rescue
# Ignore, since try_for otherwise will start the block from
# the beginning, so we don't loop beyond the first element.
end
end
# For-loops return nil, which would make the try_for always try
# until it fails, so we have to do a "check" here to determine if
# we've found the image.
image_found != nil
end
if image_found == "PidginCreateNewRoomPrompt.png" if image_found == "PidginCreateNewRoomPrompt.png"
@screen.click("PidginCreateNewRoomAcceptDefaultsButton.png") @screen.click("PidginCreateNewRoomAcceptDefaultsButton.png")
end end
......
...@@ -132,6 +132,35 @@ def sikuli_script_proxy.new(*args) ...@@ -132,6 +132,35 @@ def sikuli_script_proxy.new(*args)
self.hover(self.wait(pic, time)) self.hover(self.wait(pic, time))
end end
def s.findAny(images)
images.each do |image|
begin
return [image, self.find(image)]
rescue FindFailed
# Ignore. We deal we'll throw an appropriate exception after
# having looped through all images and found none of them.
end
end
# If we've reached this point, none of the images could be found.
Rjb::throw('org.sikuli.script.FindFailed',
"can not find any of the images #{images} on the screen")
end
def s.waitAny(images, time)
Timeout::timeout(time) do
loop do
begin
return self.findAny(images)
rescue FindFailed
# Ignore. We want to retry until we timeout.
end
end
end
rescue Timeout::Error
Rjb::throw('org.sikuli.script.FindFailed',
"can not find any of the images #{images} on the screen")
end
def s.hover_point(x, y) def s.hover_point(x, y)
self.hover(Sikuli::Location.new(x, y)) self.hover(Sikuli::Location.new(x, y))
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment