blob: 224619c899cb8a6f2ebeffc67501994402905ea9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# Helper for setting cookies in Selenium/WebDriver
#
module CookieHelper
def set_cookie(name, value, options = {})
# Selenium driver will not set cookies for a given domain when the browser is at `about:blank`.
# It also doesn't appear to allow overriding the cookie path. loading `/` is the most inclusive.
visit options.fetch(:path, '/') unless on_a_page?
page.driver.browser.manage.add_cookie(name: name, value: value, **options)
end
private
def on_a_page?
current_url = Capybara.current_session.driver.browser.current_url
current_url && current_url != '' && current_url != 'about:blank' && current_url != 'data:,'
end
end
|