Class: Applitools::Selenium::RunningTest

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/applitools/selenium/visual_grid/running_test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(eyes, browser_info, driver) ⇒ RunningTest

Returns a new instance of RunningTest.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 126

def initialize(eyes, browser_info, driver)
  Applitools::ArgumentGuard.is_a? eyes, 'eyes', Applitools::Selenium::EyesConnector

  self.eyes = eyes
  self.browser_info = browser_info
  self.driver = driver

  self.open_queue = []
  self.task_queue = []
  self.render_queue = []
  self.close_queue = []

  self.watch_open = {}
  self.watch_task = {}
  self.watch_render = {}
  self.watch_close = {}

  self.task_lock = nil

  self.pending_exceptions = []
  super()
  init
end

Instance Attribute Details

#browser_infoObject

Returns the value of attribute browser_info.



124
125
126
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 124

def browser_info
  @browser_info
end

#close_queueObject

Returns the value of attribute close_queue.



121
122
123
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 121

def close_queue
  @close_queue
end

#driverObject

Returns the value of attribute driver.



124
125
126
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 124

def driver
  @driver
end

#eyesObject

Returns the value of attribute eyes.



124
125
126
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 124

def eyes
  @eyes
end

#open_queueObject

Returns the value of attribute open_queue.



121
122
123
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 121

def open_queue
  @open_queue
end

#pending_exceptionsObject

Returns the value of attribute pending_exceptions.



124
125
126
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 124

def pending_exceptions
  @pending_exceptions
end

#render_queueObject

Returns the value of attribute render_queue.



121
122
123
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 121

def render_queue
  @render_queue
end

#task_lockObject

Returns the value of attribute task_lock.



124
125
126
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 124

def task_lock
  @task_lock
end

#task_queueObject

Returns the value of attribute task_queue.



121
122
123
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 121

def task_queue
  @task_queue
end

#test_resultObject

Returns the value of attribute test_result.



124
125
126
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 124

def test_result
  @test_result
end

#watch_closeObject

Returns the value of attribute watch_close.



121
122
123
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 121

def watch_close
  @watch_close
end

#watch_openObject

Returns the value of attribute watch_open.



121
122
123
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 121

def watch_open
  @watch_open
end

#watch_renderObject

Returns the value of attribute watch_render.



121
122
123
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 121

def watch_render
  @watch_render
end

#watch_taskObject

Returns the value of attribute watch_task.



121
122
123
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 121

def watch_task
  @watch_task
end

Instance Method Details

#all_tasks_completed?(watch) ⇒ Boolean

Returns:

  • (Boolean)


199
200
201
202
203
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 199

def all_tasks_completed?(watch)
  return true if state_name == :completed
  uniq_values = watch.values.uniq
  uniq_values.count == 1 && uniq_values.first == true
end

#check(tag, target, render_task) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 167

def check(tag, target, render_task)
  result_index = render_task.add_running_test(self)

  check_task = VGTask.new("perform check #{tag} #{target}") do
    eyes.check(tag, target, render_task.uuid)
  end

  check_task.on_task_completed do
    watch_task[check_task] = true
    self.task_lock = nil if task_lock.uuid == check_task.uuid
    becomes_tested if all_tasks_completed?(watch_task)
  end

  task_queue.insert(0, check_task)
  watch_task[check_task] = false

  render_task.on_task_succeeded do |r|
    if r[result_index] && r[result_index]['status'] == 'rendered'
      eyes.render_status_for_task(render_task.uuid, r[result_index])
      watch_render[render_task] = true
      becomes_rendered if all_tasks_completed?(watch_render)
    else
      logger.error "Wrong render status! Render returned status #{r[result_index]['status']}"
      becomes_completed
    end
  end
  render_task.on_task_error do
    becomes_completed
  end
  watch_render[render_task] = false
end

#initObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/applitools/selenium/visual_grid/running_test.rb', line 150

def init
  open_task = Applitools::Selenium::VGTask.new("open #{browser_info}") { eyes.open(driver, browser_info) }

  open_task.on_task_succeeded do
    watch_open[open_task] = true
    becomes_opened if all_tasks_completed?(watch_open)
  end

  open_task.on_task_error do |e|
    pending_exceptions << e
    becomes_completed
  end

  open_queue << open_task
  watch_open[open_task] = false
end