Files
bruno/packages/bruno-tests/collection/scripting/api/bru/cookies/getCookie.bru
2025-08-14 15:31:29 +05:30

45 lines
975 B
Plaintext

meta {
name: getCookie
type: http
seq: 1
}
get {
url: {{host}}/ping
body: none
auth: inherit
}
script:pre-request {
const jar = bru.cookies.jar()
jar.setCookie("https://testbench-sanity.usebruno.com", "name", "value")
}
tests {
const jar = bru.cookies.jar()
jar.getCookie("https://testbench-sanity.usebruno.com", "name", function(error, data) {
if(error) {
console.error("Cookie retrieval error:", error)
throw new Error(`Failed to get cookie: ${error.message || error}`)
}
test("should successfully retrieve cookie data", function() {
expect(data).to.have.property('key');
expect(data).to.have.property('value');
expect(data.key).to.equal("name");
expect(data.value).to.be.a('string');
expect(data.value).to.not.be.empty;
expect(data.domain).to.include('usebruno.com');
console.log("Retrieved cookie:", data);
});
})
jar.clear()
}
settings {
encodeUrl: true
}