2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: 587d8250367417b2b2512c5d
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 使用 headless 浏览器运行功能测试 (2)
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 2
|
2020-09-17 03:50:23 -07:00
|
|
|
forumTopicId: 301594
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: run-functional-tests-using-a-headless-browser-ii
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
|
|
|
|
|
|
|
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
|
2020-09-17 03:50:23 -07:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --instructions--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-09-17 03:50:23 -07:00
|
|
|
此挑战与之前的挑战十分类似。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
2020-09-17 03:50:23 -07:00
|
|
|
请阅读此挑战给出的代码指引,按顺序书写断言。顺序错误会影响此挑战的判定。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
|
|
|
|
|
|
|
不应有未通过的测试
|
|
|
|
|
|
|
|
```js
|
|
|
|
(getUserInput) =>
|
|
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
|
|
|
|
(data) => {
|
|
|
|
assert.equal(data.state, 'passed');
|
|
|
|
},
|
|
|
|
(xhr) => {
|
|
|
|
throw new Error(xhr.responseText);
|
|
|
|
}
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
Headless browser 应成功执行请求
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
(getUserInput) =>
|
|
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
|
|
|
|
(data) => {
|
|
|
|
assert.equal(data.assertions[0].method, 'browser.success');
|
|
|
|
},
|
|
|
|
(xhr) => {
|
|
|
|
throw new Error(xhr.responseText);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
元素 'span#name' 中的文字应为 'Amerigo'.
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
(getUserInput) =>
|
|
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
|
|
|
|
(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);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
|
|
|
元素 'span#surname' 中的文字应为 'Vespucci'.
|
|
|
|
|
|
|
|
```js
|
|
|
|
(getUserInput) =>
|
|
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
|
|
|
|
(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);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
|
|
|
元素 'span#dates' 应存在,并且只有一个
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
(getUserInput) =>
|
|
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
|
|
|
|
(data) => {
|
|
|
|
assert.equal(data.assertions[3].method, 'browser.element');
|
|
|
|
assert.match(data.assertions[3].args[0], /('|")span#dates\1/);
|
|
|
|
assert.equal(data.assertions[3].args[1], 1);
|
|
|
|
},
|
|
|
|
(xhr) => {
|
|
|
|
throw new Error(xhr.responseText);
|
|
|
|
}
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
```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.
|
|
|
|
*/
|
|
|
|
```
|