Skip to content

Instantly share code, notes, and snippets.

@sam3k
Created September 6, 2016 17:43
Show Gist options
  • Save sam3k/6f29ea4b885568027fa3e68e5054fa97 to your computer and use it in GitHub Desktop.
Save sam3k/6f29ea4b885568027fa3e68e5054fa97 to your computer and use it in GitHub Desktop.
undefined method `message' for "TypeError: window.textContent is undefined":String (NoMethodError)
class DriverJSError < StandardError; end
AfterStep do |scenario, step|
errors = page.driver.browser.manage.logs.get(:browser)
.select {|e| e.level == "SEVERE" }
.map(&:message)
.to_a
if errors.any?
message = errors.map(&:message).join("\n\n")
raise DriverJSError, message
end
end
// Sometimes it throws the following error
// undefined method `message' for "TypeError: window.textContent is undefined":String (NoMethodError)
@sam3k
Copy link
Author

sam3k commented Sep 7, 2016

This works for now:

class DriverJSError < StandardError; end

# Some errors are thrown by Selenium but are not
# actual application errors. Those we completely
# ignore
false_positive_errors = [
  "TypeError: window.textContent is undefined"
]

AfterStep do |scenario, step|
  errors = page.driver.browser.manage.logs.get(:browser)
    .select {|e| e.level == "SEVERE" }
    .map(&:message)
    .to_a

  if errors.any?
    uniq = errors.uniq  # removes duplicate errors
    message = uniq.join("\n\n") 

    if false_positive_errors.include?(message)
    else
      raise DriverJSError, "(Cucumber encounter JavaScript errors in the App) " + message
    end

  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment