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

693
Visualizações
Playwright throws aPIRequestContext.get: Request context disposed

I have a code that needs to loop the json file. However it throws this error:

aPIRequestContext.get: Request context disposed.

And I have no idea why. Here's how I implemented it: enter image description here

When I try to put the block of code outside the base.loopJsonData, it works... but not when inside. I tried to print the json details and I'm getting an output but not when I'm using request.get()

Here's the loopJsonData:

public loopJsonData(json, data, callback) {
        const inputData = this.loadJSONData(json, data);
        inputData.forEach((val, i) => {
            ((item, index) => {
                callback(item, index, inputData);
            })(val, i);
        });
    }

Here's the loadJSONData:

public loadJSONData(path: string, testData: string) {
        let jsonPath;

        this.contentPath = join(process.cwd(), path);
        this.contentPath = normalizer.normalize(this.contentPath);
        this.contentPath = JSON.parse(fs.readFileSync(this.contentPath, "utf8"));
        jsonPath = this.contentPath;
        return jsonPath[testData];
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

loopJsonData takes async function but doesn't await it inside (just calls it synchronously for each data item inputData.forEach((val, i) => {). With such approach inner request.get() will run after the test method finishes and it will race with tear down logic which disposes the request (essentially you call request.get() after request.dispose() has been called).

To fix this you should ensure that all async callbacks are waited for, something like this:

async loopJsonData(json, data, callback) {
    const inputData = this.loadJSONData(json, data);
    const promises = [];
    inputData.forEach((val, i) => {
        promises.push(callback(val, i, inputData));
    });
    await Promise.all(promises);
}
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