Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

335
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda