-
Notifications
You must be signed in to change notification settings - Fork 413
TypeError When dealing with link clicks via Capybara::Session #935
Description
Meta
Poltergeist Version: 1.6.0/1.18.1
(Tried both, saw issues with both)
Expected Behavior
I am attempting to confirm the correct function of a link with target="_blank" by switching to the window opened up when clicking the link, then checking the current_url. This should return the url opened by clicking the link.
Actual Behavior
In reality, I am getting the following error when attempting to switch_to_window:
Failure/Error: switch_to_window(new_window)
Capybara::Poltergeist::JavascriptError:
One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).
TypeError: Attempting to configurable attribute of unconfigurable property.
TypeError: Attempting to configurable attribute of unconfigurable property.
at https://www.gstatic.com/recaptcha/api2/v1562567553145/recaptcha__en.js:5 in defineProperty
at https://www.gstatic.com/recaptcha/api2/v1562567553145/recaptcha__en.js:5 in fZ
at https://www.gstatic.com/recaptcha/api2/v1562567553145/recaptcha__en.js:16
If I attempt the switch_to_window in binding.pry, it gives this error code, but actually seems to process switching windows, since afterwards I can check current_url and get the correct result and a passing test.
Since I ran into this with versions 1.6.0 and 1.18.1, I decided to try to work around this by executing some javascript to reset the links' target to "self". After this workaround, when testing the specs involved individually, they typically pass. However, when I run the entire file of specs, they fail locally. They do pass in our CI process, though.
If this is an error in something in my implementation, please let me know.
Steps to reproduce
Here is the code I attempt:
new_window = window_opened_by { row_to_click.click_link }
sleep 3
switch_to_window(new_window)
expect(current_url).to include anticipated_url # use include in case routing adds path to root url
Here is my 'workaround' code:
before do
execute_script("$('.link-to-click').each(function() {$(this).attr('target', '_self');})")
end
scenario 'the user is redirected to the correct path' do
row_to_click.click_link
sleep 3 # wait for event logging
expect(current_url).to include anticipated_url # In case link redirects to more specific path
end