class Kinchan::Task
A single unit of automation in Kinchan
Public Class Methods
find_task(task_symbol)
click to toggle source
# File lib/kinchan.rb, line 52 def self.find_task(task_symbol) Task.descendants.select { |task| task.name.split('::').last.downcase == task_symbol.to_s.downcase }[0] end
inherited(subclass)
click to toggle source
# File lib/kinchan.rb, line 48 def self.inherited(subclass) Task.descendants << subclass end
new(**options)
click to toggle source
# File lib/kinchan.rb, line 40 def initialize(**options) @before_tasks = [] @after_tasks = [] @options = options Task.start_browser unless defined?(@@browser_webdriver) end
restart_browser()
click to toggle source
# File lib/kinchan.rb, line 67 def self.restart_browser return if @@browser_webdriver.nil? @@browser_webdriver.close @@browser_webdriver = Selenium::WebDriver.for Kinchan.browser end
start_browser()
click to toggle source
# File lib/kinchan.rb, line 56 def self.start_browser browser = Kinchan.browser browser_options = Kinchan.browser_options @@browser_webdriver = if browser_options.nil? Selenium::WebDriver.for browser else Selenium::WebDriver.for(browser, options: browser_options) end end
Public Instance Methods
execute(_browser)
click to toggle source
# File lib/kinchan.rb, line 74 def execute(_browser); end
run()
click to toggle source
# File lib/kinchan.rb, line 76 def run run_tasks(@before_tasks) execute(@@browser_webdriver) run_tasks(@after_tasks) end
Private Instance Methods
get_task(task_hash)
click to toggle source
# File lib/kinchan.rb, line 84 def get_task(task_hash) task = Task.find_task(task_hash[:task]) options = task_hash[:options] if options.nil? task.new else task.new(**options) end end
run_tasks(tasks)
click to toggle source
# File lib/kinchan.rb, line 95 def run_tasks(tasks) tasks.each do |task_hash| get_task(task_hash)&.public_send('run') end end