How can I set cookies for my browsers in Katalon?

As the title says

Thanks for help.

It is quite easy:

import org.openqa.selenium.Cookie
import org.openqa.selenium.WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory
Cookie ck = new Cookie("name", "value");
WebDriver driver = DriverFactory.getWebDriver()
driver.manage().addCookie(ck)

@Ana Hong said:
It is quite easy:

import org.openqa.selenium.Cookie
import org.openqa.selenium.WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory
Cookie ck = new Cookie(“name”, “value”);
WebDriver driver = DriverFactory.getWebDriver()
driver.manage().addCookie(ck)

Thank you

hello! I have some issue. I made as you offer and I get this

FAILED because (of) org.openqa.selenium.WebDriverException: unable to set cookie

(Session info: chrome=68.0.3440.84)

(Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.12.6 x86_64) (WARNING: The server did not provide any stacktrace information)

How to resolve this problem?

is your browser up&running?

yes

I am having the same problem:

FAILED because (of) org.openqa.selenium.WebDriverException: unable to set cookie

(Session info: chrome=68.0.3440.84)

(Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.12.6 x86_64) (WARNING: The server did not provide any stacktrace information)

Any solutions how to resolve it?

Thank you.

I too am having the same issue.

11-27-2018 10:54:17 AM - [ERROR] - Test Cases/Test FAILED because (of) (Stack trace: org.openqa.selenium.WebDriverException: unable to set cookie

(Session info: headless chrome=70.0.3538.110)

I found that this works only if you have navigated to a page first. Anyone know how to set cookies on a domain before your load it?

1 Like

This might help.

You are creating the cookie before navigating to the site. If you are trying to create a cookie on the domain www.example.com, then you would want to navigate to some page on that domain, create the cookie, and then start your test.

From my reading a while back, the best way to do this is to navigate to some page you know will not exist on the domain, e.g. www.example.com/this404page, then create the cookie. It should load a lot faster since it’s an error page and shouldn’t contain much content. After creating the cookie on the 404 page, start your test.