Commit e8461c4d authored by Tails developers's avatar Tails developers
Browse files

In general, let Sikuli wait for pictures before trying to click.

If Sikuli can't find the picture, it will throw an exception. This
could easily happen if there's some delay before an excepted clickable
element appears, and for that reason we often used wait() + click()
combos. This makes that easier, and will encourage this practice.
parent 0dcbeb73
......@@ -40,6 +40,7 @@ When /^I update APT using synaptic$/ do
# Upon start the interface will be frozen while synaptic loads the
# package list
try_for(20, :msg => "Failed to click the Synaptic 'Reload' button") {
# Note: here we want to spam clicks, so we don't use wait_and_click()
@screen.click('SynapticReload.png')
}
@screen.wait('SynapticReloadPrompt.png', 20)
......@@ -55,8 +56,7 @@ Then /^I should be able to install a package using synaptic$/ do
@screen.find('SynapticSearch.png')
}
@screen.type(package + Sikuli::KEY_RETURN)
@screen.wait('SynapticCowsaySearchResult.png', 20)
@screen.click('SynapticCowsaySearchResult.png')
@screen.wait_and_click('SynapticCowsaySearchResult.png', 20)
sleep 1
@screen.type("i", Sikuli::KEY_CTRL) # Mark for installation
sleep 1
......
When /^I open a new tab in Iceweasel$/ do
next if @skip_steps_while_restoring_background
@screen.wait("IceweaselRunning.png", 10)
@screen.click("IceweaselRunning.png")
@screen.wait_and_click("IceweaselRunning.png", 10)
@screen.type("t", Sikuli::KEY_CTRL)
end
......
......@@ -115,7 +115,7 @@ end
Given /^I log in to a new session$/ do
next if @skip_steps_while_restoring_background
@screen.click('TailsGreeterLoginButton.png')
@screen.wait_and_click('TailsGreeterLoginButton.png', 10)
# FIXME: Here we should do something which waits for all Tails
# Greeter post-hooks to finish so we can rid ourselves of steps like
# "Tails Greeter has dealt with the sudo password"
......@@ -129,8 +129,7 @@ Given /^I enable more Tails Greeter options$/ do
# match. This may even work accross different screen resolutions.
pos_y = match.y + match.height*2
@screen.click(pos_x, pos_y)
@screen.wait('TailsGreeterForward.png', 10)
@screen.click('TailsGreeterForward.png')
@screen.wait_and_click('TailsGreeterForward.png', 10)
@screen.wait('TailsGreeterLoginButton.png', 20)
end
......@@ -191,12 +190,11 @@ Given /^Iceweasel has autostarted and is not loading a web page$/ do
else
iceweasel_picture = "IceweaselRunning.png"
end
step "I see \"#{iceweasel_picture}\" after at most 120 seconds"
# Stop iceweasel to load its home page. We do this to prevent Tor
# from getting confused in case we save and restore a snapshot in
# the middle of loading a page.
@screen.click(iceweasel_picture)
@screen.wait_and_click(iceweasel_picture, 120)
@screen.type("l", Sikuli::KEY_CTRL)
@screen.type("about:blank" + Sikuli::KEY_RETURN)
end
......@@ -317,9 +315,9 @@ end
Given /^I shutdown Tails$/ do
next if @skip_steps_while_restoring_background
@screen.hide_cursor
@screen.click('TailsEmergencyShutdownButton.png')
@screen.wait_and_click('TailsEmergencyShutdownButton.png', 10)
@screen.hide_cursor
@screen.click('TailsEmergencyShutdownHalt.png')
@screen.wait_and_click('TailsEmergencyShutdownHalt.png', 10)
try_for(120, :msg => "VM is still running") { ! @vm.is_running? }
end
......
......@@ -23,6 +23,18 @@ module Sikuli::Clickable
end
end
class Sikuli::Region
def wait_and_click(pic, time)
# It's undocumented, but wait() returns the matched region, so we
# compute the middle of it and click() there instead of letting
# click() scan for the picture again.
r = self.wait(pic, time)
x = r.x + r.width/2
y = r.y + r.height/2
self.click(x, y)
end
end
class Sikuli::Screen
def hide_cursor()
hover(self.width, self.height)
......
......@@ -4,8 +4,7 @@ When /^I see and accept the Unsafe Browser start verification$/ do
end
Then /^I see and close the Unsafe Browser start notification$/ do
@screen.wait("UnsafeBrowserStartNotification.png", 10)
@screen.click("UnsafeBrowserStartNotification.png")
@screen.wait_and_click("UnsafeBrowserStartNotification.png", 10)
end
Then /^the Unsafe Browser has started$/ do
......@@ -50,8 +49,7 @@ end
When /^I open a new tab in the Unsafe Browser$/ do
next if @skip_steps_while_restoring_background
@screen.wait("UnsafeBrowserWindow.png", 10)
@screen.click("UnsafeBrowserWindow.png")
@screen.wait_and_click("UnsafeBrowserWindow.png", 10)
@screen.type("t", Sikuli::KEY_CTRL)
end
......@@ -64,17 +62,15 @@ end
Then /^I cannot configure the Unsafe Browser to use any local proxies$/ do
@screen.click("UnsafeBrowserWindow.png")
@screen.wait_and_click("UnsafeBrowserWindow.png", 10)
sleep 0.5
# First we open the proxy settings page to prepare it with the
# correct open tabs for the loop below.
@screen.type("e", Sikuli::KEY_ALT)
@screen.type("n")
@screen.wait('UnsafeBrowserPreferences.png', 10)
@screen.wait('UnsafeBrowserAdvancedSettings.png', 10)
@screen.click('UnsafeBrowserAdvancedSettings.png')
@screen.wait('UnsafeBrowserNetworkTab.png', 10)
@screen.click('UnsafeBrowserNetworkTab.png')
@screen.wait_and_click('UnsafeBrowserAdvancedSettings.png', 10)
@screen.wait_and_click('UnsafeBrowserNetworkTab.png', 10)
sleep 0.5
@screen.type(Sikuli::KEY_ESC)
# @screen.waitVanish('UnsafeBrowserPreferences.png', 10)
......
......@@ -52,10 +52,9 @@ def usb_install_helper(name)
# # Unfortunately this results in almost garbage, like "|]dev/sdm"
# # when it should be /dev/sda1
@screen.click('USBCreateLiveUSB.png')
@screen.wait_and_click('USBCreateLiveUSB.png', 10)
# @screen.hide_cursor
@screen.wait('USBCreateLiveUSBNext.png', 10)
@screen.click('USBCreateLiveUSBNext.png')
@screen.wait_and_click('USBCreateLiveUSBNext.png', 10)
# @screen.hide_cursor
@screen.wait('USBInstallationComplete.png', 60*60)
@screen.type(Sikuli::KEY_RETURN)
......@@ -65,16 +64,14 @@ end
When /^I "Clone & Install" Tails to USB drive "([^"]+)"$/ do |name|
next if @skip_steps_while_restoring_background
step "I run \"liveusb-creator-launcher\""
@screen.wait('USBCloneAndInstall.png', 10)
@screen.click('USBCloneAndInstall.png')
@screen.wait_and_click('USBCloneAndInstall.png', 10)
usb_install_helper(name)
end
When /^I "Clone & Upgrade" Tails to USB drive "([^"]+)"$/ do |name|
next if @skip_steps_while_restoring_background
step "I run \"liveusb-creator-launcher\""
@screen.wait('USBCloneAndUpgrade.png', 10)
@screen.click('USBCloneAndUpgrade.png')
@screen.wait_and_click('USBCloneAndUpgrade.png', 10)
usb_install_helper(name)
end
......@@ -91,15 +88,14 @@ end
When /^I do a "Upgrade from ISO" on USB drive "([^"]+)"$/ do |name|
next if @skip_steps_while_restoring_background
step "I run \"liveusb-creator-launcher\""
@screen.wait('USBUpgradeFromISO.png', 10)
@screen.click('USBUpgradeFromISO.png')
@screen.wait_and_click('USBUpgradeFromISO.png', 10)
@screen.wait('USBUseLiveSystemISO.png', 10)
match = @screen.find('USBUseLiveSystemISO.png')
pos_x = match.x + match.width/2
pos_y = match.y + match.height*2
@screen.click(pos_x, pos_y)
@screen.wait('USBSelectISO.png', 10)
@screen.click('GnomeFileDiagTypeFilename.png')
@screen.wait_and_click('GnomeFileDiagTypeFilename.png', 10)
iso = "#{shared_iso_dir_on_guest}/#{File.basename(ENV['ISO'])}"
@screen.type(iso + Sikuli::KEY_RETURN)
usb_install_helper(name)
......@@ -119,7 +115,7 @@ Given /^I enable all persistence presets$/ do
@screen.type('a', Sikuli::KEY_ALT)
@screen.type('/etc/ssh')
@screen.type('a', Sikuli::KEY_ALT)
@screen.click('PersistenceWizardSave.png')
@screen.wait_and_click('PersistenceWizardSave.png', 10)
@screen.wait('PersistenceWizardDone.png', 20)
@screen.type(Sikuli::KEY_F4, Sikuli::KEY_ALT)
end
......@@ -197,8 +193,7 @@ end
Given /^I enable read-only persistence with password "([^"]+)"$/ do |pwd|
step "I enable persistence with password \"#{pwd}\""
next if @skip_steps_while_restoring_background
@screen.wait('TailsGreeterPersistenceReadOnly.png', 10)
@screen.click('TailsGreeterPersistenceReadOnly.png')
@screen.wait_and_click('TailsGreeterPersistenceReadOnly.png', 10)
end
Given /^persistence has been enabled$/ do
......
Given /^I enable Microsoft Windows XP camouflage$/ do
@theme = "winxp"
next if @skip_steps_while_restoring_background
@screen.wait("TailsGreeterWinXPCamouflage.png", 10)
@screen.click("TailsGreeterWinXPCamouflage.png")
@screen.wait_and_click("TailsGreeterWinXPCamouflage.png", 10)
end
When /^I click the start menu$/ do
@screen.click("WinXPStartButton.png")
@screen.wait_and_click("WinXPStartButton.png", 10)
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