How do I handle cookies

Hello everyone,
I am trying to write a test for login on a site that requires cookies to be enabled. How do I receive cookies from a site and store them?

Thanks,
Terry

Hey @terry_lowery you can reference the documentation for the specific functions for manipulating cookies here - https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/scripting-monitors/synthetics-scripted-browser-reference#options. There’s also an example script here in the forums as well - Relic Solution: Get/Interact with Cookies Script

If you’re mocking up a basic login journey that utilises cookies post authentication then nothing needs to be done. Just enter the username/password, the test framework will accept the cookies and you’ll be able to continue your journey as if you’re a standard user.

If you want to manually add cookies at the start of the test to mock up a post-authentication journey then @bburkholder points you in the right direction.

If you’re using HTML5 local storage instead of cookies to mock up authentication tokens (think CA Authminder), you can add them at the start of your test as follows:

    $browser.executeScript("window.localStorage.setItem('keyname', 'value')"); 

P

3 Likes