Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

326
Views
How to check the value of a cookie Testcafe & JS?

For the purpose of an automated test I need to write a piece of Javascript/Typescript code that on a given website, after giving consent to all cookie, will check two things:

  • the presence of a specific cookie (I know the name of this cookie)
  • the value of this specific cookie

I started like below but have no idea how to go further:

import { Selector, RequestLogger, ClientFunction } from 'testcafe';
const getValueOfCookie = ClientFunction(() => document.cookie)
... ?

Is anyone able to help me with it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since document.cookie is a string, you have to parse it in order to check for the desired cookie and/or get its value.

The following code will return undefined if the cookie does not exist:

const getValueOfCookie = ClientFunction(() => {
  return document.cookie
    .split('; ')
    .find(row => row.startsWith('cookieName='))
    ?.split('=')[1];
});

See https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie for more information.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!