Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

322
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda