thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 428 forks source link

`evaluate_script` throws an exception #1028

Closed arthwood closed 6 years ago

arthwood commented 6 years ago

capybara-webkit version: v1.14.0 (works fine on v1.13.0) capybara version: any but I run it on 2.13.0

I've got helper method:

    def get_style(node)
      path = node.path

      result = page.evaluate_script <<-EOS.squish
        var node = document.evaluate("#{path}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

        window.getComputedStyle(node);
      EOS

      pp page.driver.console_messages

      result
    end

output from console shows:

[{:line_number=>499,
  :message=>
   "NoModificationAllowedError: DOM Exception 7: An attempt was made to modify an object where modifications are not allowed.",
  :source=>"undefined"}]

I believe it's due to this change.

When I simulate wrapping result in real app in the browser the error is more descriptive (the _result passed to wrapper is a CSSStyleDeclaration in my case):

Uncaught DOMException: Failed to set the 'align-content' property on 'CSSStyleDeclaration': These styles are computed, and therefore the 'align-content' property is read-only.

twalpole commented 6 years ago

@arthwood Could you try PR #1032 and see if that fixes the issue for you?

arthwood commented 6 years ago

@twalpole Yup, that ref works fine. 👍

twalpole commented 6 years ago

Fixed via PR #1032