2021-06-15 00:49:18 -07:00
---
id: 5f8884f4c46685731aabfc41
2021-07-30 23:57:21 +09:00
title: Executar testes funcionais usando um navegador headless II
2021-06-15 00:49:18 -07:00
challengeType: 2
forumTopicId: 301594
dashedName: run-functional-tests-using-a-headless-browser-ii
---
# --description--
2021-07-30 23:57:21 +09:00
Lembrando que este projeto está sendo construído a partir do [Replit ](https://replit.com/github/freeCodeCamp/boilerplate-mochachai ), ou pose ser clonado no [GitHub ](https://github.com/freeCodeCamp/boilerplate-mochachai/ ).
2021-06-15 00:49:18 -07:00
# --instructions--
2021-08-20 00:00:51 -07:00
Em `tests/2_functional-tests.js` , no teste `'Submit the surname "Vespucci" in the HTML form'` (`// #5` ), automatize o seguinte:
2021-06-15 00:49:18 -07:00
2021-08-20 00:00:51 -07:00
1. Preencha o formulário com o surname `Vespucci`
2. Pressione o botão Submit
2021-06-15 00:49:18 -07:00
2021-08-20 00:00:51 -07:00
Na callback `pressButton` :
2021-06-15 00:49:18 -07:00
2021-08-20 00:00:51 -07:00
1. Avalie se o status é OK `200`
2. Avalie se o texto dentro do elemento `span#name` é `'Amerigo'`
3. Avalie se o texto dentro do elemento `span#surname` é `'Vespucci'`
4. Avalie se o(s) elemento(s) `span#dates` existe(m) e sua contagem é `1`
2021-06-15 00:49:18 -07:00
2021-07-30 23:57:21 +09:00
Não se esqueça de remover a chamada `assert.fail()` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-30 23:57:21 +09:00
Todos os testes devem passar.
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
2021-08-20 00:00:51 -07:00
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-06-15 00:49:18 -07:00
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2021-07-30 23:57:21 +09:00
Você deve avaliar se a solicitação do navegador headless foi bem-sucedida.
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
2021-08-20 00:00:51 -07:00
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-06-15 00:49:18 -07:00
(data) => {
assert.equal(data.assertions[0].method, 'browser.success');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2021-08-20 00:00:51 -07:00
Você deve avaliar se o texto dentro do elemento `span#name` é `'Amerigo'` .
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
2021-08-20 00:00:51 -07:00
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-06-15 00:49:18 -07: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);
}
);
```
2021-08-20 00:00:51 -07:00
Você deve avaliar se o texto dentro do elemento `span#surname` é `'Vespucci'` .
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
2021-08-20 00:00:51 -07:00
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-06-15 00:49:18 -07: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);
}
);
```
2021-08-20 00:00:51 -07:00
Você deve avaliar se o elemento `span#dates` existe e que sua contagem é 1.
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
2021-08-20 00:00:51 -07:00
$.get(getUserInput('url') + '/_api/get-tests?type=functional& n=6').then(
2021-06-15 00:49:18 -07:00
(data) => {
assert.equal(data.assertions[3].method, 'browser.elements');
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.
*/
```