Class: Kinchan::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/kinchan.rb

Overview

A single unit of automation in Kinchan

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Task

Returns a new instance of Task.



40
41
42
43
44
45
46
# File 'lib/kinchan.rb', line 40

def initialize(**options)
  @before_tasks = []
  @after_tasks = []
  @options = options

  Task.start_browser unless defined?(@@browser_webdriver)
end

Class Method Details

.find_task(task_symbol) ⇒ Object



52
53
54
# 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) ⇒ Object



48
49
50
# File 'lib/kinchan.rb', line 48

def self.inherited(subclass)
  Task.descendants << subclass
end

.restart_browserObject



67
68
69
70
71
72
# 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_browserObject



56
57
58
59
60
61
62
63
64
65
# 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

Instance Method Details

#execute(_browser) ⇒ Object



74
# File 'lib/kinchan.rb', line 74

def execute(_browser); end

#runObject



76
77
78
79
80
# File 'lib/kinchan.rb', line 76

def run
  run_tasks(@before_tasks)
  execute(@@browser_webdriver)
  run_tasks(@after_tasks)
end