Module: WatchDoge::Regression::DSL

Included in:
Manager
Defined in:
lib/watchdoge/regression/dsl.rb

Instance Method Summary collapse

Instance Method Details

#compare(path, **kwargs) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/watchdoge/regression/dsl.rb', line 43

def compare path, **kwargs
  path = URI.join(WatchDoge.configuration.host, path).to_s
  @reference_file_name = WatchDoge::Regression::Utils.path_to_filename(kwargs[:with] || path)

  puts "[compare] #{path} #{ ('[with]'+ @reference_file_name) if kwargs[:with] }"

  @setup_proc.call if @setup_proc

  args = {
    wait: nil
  }.merge(kwargs)

  @worker.goto path

  if args[:wait]
    @view_port.merge!({
      wait: args[:wait]
    })
  end

  @worker.resize_by_viewport(@view_port) do
    yield(@worker) if block_given?

    case @regression_flag
    when :capture
      puts "  -> make reference images on worker #{@worker}"
      @worker.screenshot.save reference_image
    when :test
      puts "  -> compare reference images on worker #{@worker}"
      reference_image = WatchDoge::Regression::Utils.load_png self.reference_image
      input_image = WatchDoge::Regression::Utils.load_png @worker.screenshot.png
      pixel_test = WatchDoge::PixelTest.new(input_image, reference_image, filename: @reference_file_name)

      WatchDoge::Notification.push pixel_test if pixel_test.diff?
    end
  end

  @teardown_proc.call if @teardown_proc
end

#setupObject


83
84
85
# File 'lib/watchdoge/regression/dsl.rb', line 83

def setup
  @setup_proc = -> { yield }
end

#sign_in_as(resoruce) {|@worker| ... } ⇒ Object

Yields:

  • (@worker)

26
27
28
29
30
31
32
33
34
35
# File 'lib/watchdoge/regression/dsl.rb', line 26

def  resoruce
  puts "[sign_in_as] #{resoruce}"
  WatchDoge.configuration..call(@worker, resoruce)

  return unless block_given?

  yield(@worker)
  puts "sign_out #{resoruce}"
  WatchDoge.configuration.sign_out_proc.call(@worker, resoruce)
end

#teardownObject


87
88
89
# File 'lib/watchdoge/regression/dsl.rb', line 87

def teardown
  @teardown_proc = -> { yield }
end

#use(browser) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/watchdoge/regression/dsl.rb', line 13

def use browser
  puts "[use] browser #{browser}"
  @worker.close

  worker_options =
    WatchDoge.configuration.default_worker_options.merge WatchDoge.configuration.worker_options

  worker_options = worker_options.dup
  worker_options[:browser] = browser

  @worker = WatchDoge::Worker.new @scenario_name, worker_options
end

#with_viewport(**kwargs) ⇒ Object


37
38
39
40
41
# File 'lib/watchdoge/regression/dsl.rb', line 37

def with_viewport **kwargs
  @view_port = kwargs
  yield
  @view_port = {}
end