Class: Maze::ErrorMonitor::SeleniumErrorMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/maze/error_monitor/selenium_error_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(middleware) ⇒ SeleniumErrorMiddleware

Returns a new instance of SeleniumErrorMiddleware.



5
6
7
# File 'lib/maze/error_monitor/selenium_error_middleware.rb', line 5

def initialize(middleware)
  @middleware = middleware
end

Instance Method Details

#call(report) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/maze/error_monitor/selenium_error_middleware.rb', line 9

def call(report)
  first_ex = report.raw_exceptions.first
  if first_ex.class.name.start_with?('Selenium::WebDriver')
    report.grouping_hash = first_ex.class.name.to_s + sanitise(first_ex.message.to_s)
  end

  @middleware.call(report)
end

#sanitise(message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/maze/error_monitor/selenium_error_middleware.rb', line 18

def sanitise(message)
  regexes = [
    {
      pattern: /(An unknown server-side error occurred while processing the command. Original error: ')(.*)(' is still running after 500ms timeout)/,
      replacement: '\1APP_NAME\3'
    },
    {
      pattern: /(unexpected end of stream on )(http:\/\/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,5}\/\.\.\.)/,
      replacement: '\1URL'
    },
    {
      pattern: /(Could not find a connected Android device in )([0-9]+)ms/,
      replacement: '\1TIME'
    }
  ]

  regex = regexes.find{|r| message =~ r[:pattern]}
  if regex
    message.gsub(regex[:pattern], regex[:replacement])
  else
    message
  end
end