Module: PercyCapybara
- Defined in:
- lib/percy/version.rb,
lib/percy/capybara.rb
Constant Summary collapse
- VERSION =
'5.0.0'.freeze
- PERCY_DEBUG =
ENV['PERCY_LOGLEVEL'] == 'debug'
- PERCY_SERVER_ADDRESS =
ENV['PERCY_SERVER_ADDRESS'] || 'http://localhost:5338'
- PERCY_LABEL =
"[\u001b[35m" + (PERCY_DEBUG ? 'percy:capybara' : 'percy') + "\u001b[39m]"
Instance Method Summary collapse
-
#percy_snapshot(name, options = {}) ⇒ Object
Take a DOM snapshot and post it to the snapshot endpoint.
Instance Method Details
#percy_snapshot(name, options = {}) ⇒ Object
Take a DOM snapshot and post it to the snapshot endpoint
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/percy/capybara.rb', line 18 def percy_snapshot(name, = {}) return unless percy_enabled? page = Capybara.current_session begin page.evaluate_script(fetch_percy_dom) dom_snapshot = page .evaluate_script("(function() { return PercyDOM.serialize(#{.to_json}) })()") response = fetch('percy/snapshot', name: name, url: page.current_url, dom_snapshot: dom_snapshot, client_info: CLIENT_INFO, environment_info: ENV_INFO, **,) unless response.body.to_json['success'] raise StandardError, data['error'] end rescue StandardError => e log("Could not take DOM snapshot '#{name}'") if PERCY_DEBUG then log(e) end end end |