Improve the 'I press the "KEY" key' step with meta-programming
Originally created by @anonym on #8885 (Redmine)
With the use of eval
we don’t need to handle each key separately as
long as we call the keys the same as Sikuli does:
--- a/features/step_definitions/common_steps.rb
+++ b/features/step_definitions/common_steps.rb
@@ -809,10 +809,9 @@ end
When /^I press the "([^"]+)" key$/ do |key|
next if @skip_steps_while_restoring_background
- case key
- when "ENTER"
- @screen.type(Sikuli::Key.ENTER)
- else
+ begin
+ @screen.type(eval("Sikuli::Key.#{key}"))
+ rescue RuntimeError
raise "unsupported key #{key}"
end
end
Feature Branch: test/8688-gnome-screenshot