> For the complete documentation index, see [llms.txt](https://abi.gitbook.io/net-core/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://abi.gitbook.io/net-core/14.-introduccion-a-postman/14.2-instrucciones-basicas-para-probar-con-postman.md).

# 13.2 Instrucciones básicas para probar con Postman

Postman cuenta con algunas funciones ya definidas y algunas librerías javascript para probar tus servicios.

La sintaxis básica es:

```javascript
pm.test("Descripción del caso de prueba", function() {
    //código para la prueba
    pm.expect("valor esperado").to.equal("valor")
});
```

Para indicar que quieres agregar un nuevo caso de prueba es con el objeto **pm** luego **.** luego la función **test** entre paréntesis el primer parámetro es la **descripción del test**, luego una función.&#x20;

Por lo general el código para probar es con **pm** luego **.** luego la función **expect** como parámetro agregas el **valor esperado** y luego el **valor** y la **condición** que deseas probar en el ejemplo se prueba que sea igual a un valor.

### Instrucciones básicas

| Prueba                                                 | Código                                                                                                                                                                              |
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Revisar el status                                      | <p><code>pm.response.to.have.status(200);</code></p><p><code>pm.expect(pm.response.code).to.be.oneOf(\[201,202]);</code></p>                                                        |
| Revisar tiempo de respuesta                            | <p><code>pm.expect(pm.response.responseTime).to.be.below(200);</code></p><p><code>pm.response.to.have.status("Created");</code></p>                                                 |
| Revisar un header                                      | `pm.response.to.have.header("Content-Type");`                                                                                                                                       |
| Comparar el tipo de dato                               | <p><code>pm.expect('Postman').to.be.a('string');</code></p><p><code>pm.expect({a: 1}).to.be.an('object');</code></p><p><code>pm.expect(undefined).to.be.an('undefined');</code></p> |
| Revisar que el body tenga un texto                     | `pm.expect(pm.response.text()).to.include("string a buscar");`                                                                                                                      |
| Obtener el json                                        | `var jsonData = pm.response.json(`);                                                                                                                                                |
| Convertir un xml a json                                | `var jsonObject = xml2Json(responseBody);`                                                                                                                                          |
| Revisar que un valor en el json sea igual a otro valor | <p><code>var jsonData = pm.response.json();</code></p><p><code>pm.expect(jsonData.value).to.eql(100);</code></p>                                                                    |
| Revisa que exista una cadena en otra cadena            | `pm.expect('Cadena').to.have.string('de');`                                                                                                                                         |
| Revisar que un array o cadena este vacío               | <p><code>pm.expect(\[]).to.be.empty;</code></p><p><code>pm.expect('').to.be.empty;</code></p>                                                                                       |
| Revisar todas las propiedades de un objeto             | <p><code>pm.expect({a: 1, b: 2}).to.have.all.keys('a', 'b');</code></p><p>    <code>});</code></p>                                                                                  |
| Revisar que tenga solo algunas propiedades             | <p><code>pm.expect({a: 1, b: 2}).to.have.any.keys('a', 'b');</code></p><p>    <code>});</code></p>                                                                                  |
| Revisar que un objeto no tenga alguna propiedad        | <p><code>pm.expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');</code></p><p>    <code>});</code></p>                                                                              |
| Revisar la longitud de una cadena                      | `pm.expect('foo').to.have.lengthOf(3);`                                                                                                                                             |
| Revisar el número de elementos array                   | `pm.expect([1, 2, 3]).to.have.lengthOf(3);`                                                                                                                                         |
| Revisar que exista un elemento en un array             | `pm.expect([1, 2, 3]).to.include(2);`                                                                                                                                               |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://abi.gitbook.io/net-core/14.-introduccion-a-postman/14.2-instrucciones-basicas-para-probar-con-postman.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
