summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranonym <anonym@riseup.net>2018-04-03 12:34:01 +0200
committeranonym <anonym@riseup.net>2019-05-14 16:51:14 +0200
commit39f241a684da5895b7aed68a377b5bdeccceb4c0 (patch)
treeea80f7668bbe2b1e2c26fb0735eea6db6627dccb
parentde7a6b66b49e94ba1043f9bbbb66aff2797173a5 (diff)
Test suite: add generic Dogtail actions that refer to the last used application.
These are good enough (and can prevent step definition spam) when the context is clear, e.g.: When I start "gnome-disks" via GNOME Activities Overview Then application "gnome-disks" starts When I click the "1.6 GB Loop Device" item And I click the "Menu" toggle button And I click the "Benchmark Disk..." menu item Then I see the "Benchmark" dialog When I click the "Start Benchmark..." button Then I see the "Benchmark Settings" dialog When I click "Start Benchmarking..." button
-rw-r--r--features/step_definitions/apt.rb2
-rw-r--r--features/step_definitions/common_steps.rb46
-rw-r--r--features/support/helpers/dogtail.rb37
3 files changed, 78 insertions, 7 deletions
diff --git a/features/step_definitions/apt.rb b/features/step_definitions/apt.rb
index 59039a4..ea0aed1 100644
--- a/features/step_definitions/apt.rb
+++ b/features/step_definitions/apt.rb
@@ -147,7 +147,7 @@ When /^I update APT using Synaptic$/ do
) do
!$vm.has_process?("/usr/lib/apt/methods/tor+http")
end
- assert_raise(RuntimeError) do
+ assert_raise(Dogtail::ScriptFailure) do
@synaptic.child(roleName: 'dialog', recursive: false)
.child('Error', roleName: 'icon', retry: false)
end
diff --git a/features/step_definitions/common_steps.rb b/features/step_definitions/common_steps.rb
index f3c3771..6ab18ad 100644
--- a/features/step_definitions/common_steps.rb
+++ b/features/step_definitions/common_steps.rb
@@ -721,6 +721,15 @@ Given /^I start "([^"]+)" via GNOME Activities Overview$/ do |app_name|
@screen.type(Sikuli::Key.ENTER, Sikuli::KeyModifier.CTRL)
end
+When /^application "([^"]+)" (?:starts|has started|is running)$/ do |app_name|
+ # Let's say it is running as soon as some *visible* (i.e. "showing")
+ # child exists.
+ try(timeout: 60) do
+ Dogtail::Application.new(app_name)
+ .child(showingOnly: true, recursive: false)
+ end
+end
+
When /^I type "([^"]+)"$/ do |string|
@screen.type(string)
end
@@ -1103,3 +1112,40 @@ When /^I disable the (.*) (system|user) unit$/ do |unit, scope|
options = scope == 'system' ? '' : '--global'
$vm.execute_successfully("systemctl #{options} disable '#{unit}'")
end
+
+When /^I (see|(?:double )?click|point) (the|a|no|\d+) "([^"]+)" ([a-z ]+)(?: in application "([^"]+)")?$/ do |action, article, name, role, app|
+ action = 'doubleClick' if action == 'double click'
+ if /^(no|d+)$/.match(article)
+ req_hits = article.to_i # 'no'.to_i == 0
+ else
+ req_hits = nil
+ end
+ if req_hits != 1
+ # Drop potential plural "s"
+ role.sub!(/s$/, '')
+ end
+ role = Dogtail.translate_role(role)
+ flags = {}
+ generic_roles = ['node', 'object', 'widget', 'thingy']
+ unless generic_roles.include?(role)
+ flags[:roleName] = role
+ end
+ if app
+ Dogtail::Application.last = Dogtail::Application.new(app)
+ end
+ hits = Dogtail::Application.last.children(name, **flags)
+ if req_hits
+ if req_hits != hits.size
+ raise "Did not get the expected number of matches " +
+ "(got #{hits.size}, expected #{req_hits})"
+ end
+ else
+ if hits.empty?
+ raise 'No match found'
+ end
+ hits = [hits.first]
+ end
+ if action != 'see'
+ hits.each { |node| node.method(action).call }
+ end
+end
diff --git a/features/support/helpers/dogtail.rb b/features/support/helpers/dogtail.rb
index 1bbb617..3691612 100644
--- a/features/support/helpers/dogtail.rb
+++ b/features/support/helpers/dogtail.rb
@@ -5,6 +5,9 @@ module Dogtail
RIGHT_CLICK = 3
end
+ class ScriptFailure < StandardError
+ end
+
TREE_API_NODE_SEARCHES = [
:button,
:child,
@@ -36,6 +39,13 @@ module Dogtail
:window,
]
+ def self.translate_role(name)
+ {
+ 'button' => 'push button',
+ 'text area' => 'text',
+ }[name] || name
+ end
+
# We want to keep this class immutable so that handles always are
# left intact when doing new (proxied) method calls. This way we
# can support stuff like:
@@ -51,8 +61,21 @@ module Dogtail
class Application
@@node_counter ||= 0
+ @@last ||= nil
+
+ def self.last
+ @@last
+ end
+
+ def self.last=(app)
+ assert_equal(Application, app.class)
+ @@last = app
+ end
+
+ attr_reader :app
def initialize(app_name, opts = {})
+ @app = self
@var = "node#{@@node_counter += 1}"
@app_name = app_name
@opts = opts
@@ -77,10 +100,11 @@ module Dogtail
end
def run(code)
+ self.class.last = self.app
code = code.join("\n") if code.class == Array
c = RemoteShell::PythonCommand.new($vm, code, user: @opts[:user])
if c.failure?
- raise RuntimeError.new("The Dogtail script raised: #{c.exception}")
+ raise ScriptFailure.new("The Dogtail script raised: #{c.exception}")
end
return c
end
@@ -160,7 +184,7 @@ module Dogtail
]
size = run(find_script_lines).stdout.chomp.to_i
return size.times.map do |i|
- Node.new("#{nodes_var}[#{i}]", @opts)
+ Node.new(@app, "#{nodes_var}[#{i}]", @opts)
end
end
@@ -202,13 +226,13 @@ module Dogtail
define_method(method) do |*args|
args_str = self.class.args_to_s(args)
method_call = "#{method.to_s}(#{args_str})"
- Node.new("#{@var}.#{method_call}", @opts)
+ Node.new(@app, "#{@var}.#{method_call}", @opts)
end
end
TREE_API_NODE_SEARCH_FIELDS.each do |field|
define_method(field) do
- Node.new("#{@var}.#{field}", @opts)
+ Node.new(@app, "#{@var}.#{field}", @opts)
end
end
@@ -216,7 +240,8 @@ module Dogtail
class Node < Application
- def initialize(expr, opts = {})
+ def initialize(app, expr, opts = {})
+ @app = app
@expr = expr
@opts = opts
@opts[:user] ||= LIVE_USER
@@ -229,7 +254,7 @@ module Dogtail
define_method(method) do |*args|
args_str = self.class.args_to_s(args)
method_call = "#{method.to_s}(#{args_str})"
- Node.new("#{@var}.#{method_call}", @opts)
+ Node.new(@app, "#{@var}.#{method_call}", @opts)
end
end