2021-02-06 04:42:36 +00:00
---
id: 5f8884f4c46685731aabfc41
2022-01-07 13:19:06 +05:30
title: Ejecuta pruebas funcionales usando un navegador sin interfaz gráfica II
2021-02-06 04:42:36 +00:00
challengeType: 2
forumTopicId: 301594
dashedName: run-functional-tests-using-a-headless-browser-ii
---
# --description--
2022-01-07 13:19:06 +05:30
Como recordatorio, este proyecto está siendo construido con base en el siguiente proyecto inicial [Replit ](https://replit.com/github/freeCodeCamp/boilerplate-mochachai ), o clonado desde [GitHub ](https://github.com/freeCodeCamp/boilerplate-mochachai/ ).
2021-02-06 04:42:36 +00:00
# --instructions--
2022-01-07 13:19:06 +05:30
Dentro `tests/2_functional-tests.js` , en `'Submit the surname "Vespucci" in the HTML form'` prueba (`// #5` ), automatiza lo siguiente:
2021-02-06 04:42:36 +00:00
2022-01-07 13:19:06 +05:30
1. Rellena el formulario con el apellido `Vespucci`
2. Presiona el botón enviar
2021-02-06 04:42:36 +00:00
2022-01-07 13:19:06 +05:30
Y dentro del callback de `pressButton` :
2021-02-06 04:42:36 +00:00
2022-01-07 13:19:06 +05:30
1. Comprueba que el status es OK `200`
2. Comprueba que el texto dentro del elemento `span#name` es `'Amerigo'`
3. Comprueba que el texto dentro del elemento `span#surname` es `'Vespucci'`
4. Comprueba que existen elemento(s) `span#dates` y su contador es `1`
2021-02-06 04:42:36 +00:00
2022-01-07 13:19:06 +05:30
No olvides eliminar la llamada `assert.fail()` .
2021-02-06 04:42:36 +00:00
# --hints--
2022-01-07 13:19:06 +05:30
Todas las pruebas deben pasar.
2021-02-06 04:42:36 +00:00
```js
(getUserInput) =>
2022-01-07 13:19:06 +05:30
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-02-06 04:42:36 +00:00
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2022-01-07 13:19:06 +05:30
Debes asegurarte que la petición del navegador sin interfaz gráfica ha sido exitosa.
2021-02-06 04:42:36 +00:00
```js
(getUserInput) =>
2022-01-07 13:19:06 +05:30
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-02-06 04:42:36 +00:00
(data) => {
assert.equal(data.assertions[0].method, 'browser.success');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2022-01-07 13:19:06 +05:30
Debes comprobar que el texto dentro del elemento `span#name` es `'Amerigo'` .
2021-02-06 04:42:36 +00:00
```js
(getUserInput) =>
2022-01-07 13:19:06 +05:30
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-02-06 04:42:36 +00:00
(data) => {
assert.equal(data.assertions[1].method, 'browser.text');
assert.match(data.assertions[1].args[0], /('|")span#name \1/);
assert.match(data.assertions[1].args[1], /('|")Amerigo\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2022-01-07 13:19:06 +05:30
Debes comprobar que el texto dentro del elemento `span#surname` es `'Vespucci'` .
2021-02-06 04:42:36 +00:00
```js
(getUserInput) =>
2022-01-07 13:19:06 +05:30
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-02-06 04:42:36 +00:00
(data) => {
assert.equal(data.assertions[2].method, 'browser.text');
assert.match(data.assertions[2].args[0], /('|")span#surname \1/);
assert.match(data.assertions[2].args[1], /('|")Vespucci\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2022-01-07 13:19:06 +05:30
Debes comprobar que el elemento `span#dates` existe y su contador es 1.
2021-02-06 04:42:36 +00:00
```js
(getUserInput) =>
2022-01-07 13:19:06 +05:30
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-02-06 04:42:36 +00:00
(data) => {
2021-07-09 21:23:54 -07:00
assert.equal(data.assertions[3].method, 'browser.elements');
2021-02-06 04:42:36 +00:00
assert.match(data.assertions[3].args[0], /('|")span#dates \1/);
assert.equal(data.assertions[3].args[1], 1);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--
```js
/**
Backend challenges don't need solutions,
because they would need to be tested against a full working project.
Please check our contributing guidelines to learn more.
*/
```