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

213
Visualizações
Cartero: establezca una variable de una matriz para cada solicitud

Estoy tratando de establecer pruebas para mi colección de API. La prueba debe llamar tres veces, con tres parámetros diferentes para cada solicitud de la colección.

He agregado un script de solicitud previa a mi colección, que contiene dos solicitudes:

 let countryIso3List = pm.collectionVariables.get("CountryIso3List"); if(!countryIso3List || countryIso3List.length == 0) { countryIso3List = ["AFG", "SYR", "IDN"]; } let countryIso3 = countryIso3List.shift(); pm.collectionVariables.set("CountryIso3", countryIso3); pm.collectionVariables.set("CountryIso3List", countryIso3List);

Luego en la prueba de las solicitudes tengo el siguiente código:

 const currentCountryIso3List = pm.collectionVariables.get("CountryIso3List"); if (currentCountryIso3List && currentCountryIso3List.length > 0){ postman.setNextRequest(request.name); } else { postman.setNextRequest(null); } pm.test("Status code is 200", function () { pm.response.to.have.status(200); });

Funciona bien solo para la primera llamada, poniendo "AFG" en la variable CountryIso3 que luego se usa para hacer la solicitud.

Después de esta ejecución inicial, veo que CountryIso3List contiene "SYR, IDN" como cadena y no puede ejecutar el comando shift() y se detiene.

Intenté modificar el script de solicitud previa agregando una división en la variable de colección:

 let countryIso3List = pm.collectionVariables.get("CountryIso3List"); if(!countryIso3List || countryIso3List.length == 0) { countryIso3List = ["AFG", "SYR", "IDN"]; } else{ countryIso3List = pm.collectionVariables.get("CountryIso3List").split(','); } let countryIso3 = countryIso3List.shift(); pm.collectionVariables.set("CountryIso3", countryIso3); pm.collectionVariables.set("CountryIso3List", countryIso3List);

pero funciona bien en el primer ciclo, luego si repito la prueba se rompe diciendo:

TypeError: pm.collectionVariables.get(...).split no es una función

¿Cómo puedo arreglarlo?

about 4 years ago · Juan Pablo Isaza
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