Class: Kinchan::Task
- Inherits:
-
Object
- Object
- Kinchan::Task
- Defined in:
- lib/kinchan.rb
Constant Summary collapse
- @@browser_webdriver =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #execute(browser) ⇒ Object
-
#initialize(**options) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
Constructor Details
#initialize(**options) ⇒ Task
Returns a new instance of Task.
19 20 21 22 23 |
# File 'lib/kinchan.rb', line 19 def initialize(**) @before_tasks = [] @after_tasks = [] @options = end |
Class Method Details
.find_task(task_symbol) ⇒ Object
29 30 31 |
# File 'lib/kinchan.rb', line 29 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
25 26 27 |
# File 'lib/kinchan.rb', line 25 def self.inherited(subclass) Task.descendants << subclass end |
.restart_browser ⇒ Object
33 34 35 36 37 38 |
# File 'lib/kinchan.rb', line 33 def self.restart_browser unless @@browser_webdriver.nil? @@browser_webdriver.close @@browser_webdriver = Selenium::WebDriver.for Task.browser end end |
Instance Method Details
#execute(browser) ⇒ Object
40 |
# File 'lib/kinchan.rb', line 40 def execute(browser); end |
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kinchan.rb', line 42 def run if @@browser_webdriver.nil? if Task..nil? @@browser_webdriver = Selenium::WebDriver.for Task.browser else @@browser_webdriver = Selenium::WebDriver.for(Task.browser, options: Task.) end end @before_tasks.each do |task_hash| task = Task.find_task(task_hash[:task]) task.new(**task_hash[:options]).public_send('run') unless task.nil? end execute(@@browser_webdriver) @after_tasks.each do |task_hash| task = Task.find_task(task_hash[:task]) task.new(**task_hash[:options]).public_send('run') unless task.nil? end end |