Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-09-22 21:15:43 +0300
committerMike Greiling <mike@pixelcog.com>2017-09-22 22:42:43 +0300
commit7a8514c3a1806f44d7602c7a6602c116b4264adb (patch)
treef1ad71caa1f06330c309003b4f3dda623b4dcbb2 /spec/support/cookie_helper.rb
parent76de6327d8eab3123f06f612e8f623424599ad91 (diff)
add set_cookie helper
Diffstat (limited to 'spec/support/cookie_helper.rb')
-rw-r--r--spec/support/cookie_helper.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/spec/support/cookie_helper.rb b/spec/support/cookie_helper.rb
new file mode 100644
index 00000000000..224619c899c
--- /dev/null
+++ b/spec/support/cookie_helper.rb
@@ -0,0 +1,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