3.1 KiB
3.1 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
5f8884f4c46685731aabfc41 | 使用 無頭瀏覽器 II 運行功能測試 | 2 | 301594 | run-functional-tests-using-a-headless-browser-ii |
--description--
請注意,本項目在這個 Replit 項目的基礎上進行開發。你也可以從 GitHub 上克隆。
--instructions--
在 tests/2_functional-tests.js
中,'submit "surname" : "Vespucci" - write your e2e test...'
測試(// #6
),自動化填寫和提交表單:
- 在表單中填寫
Vespucci
的surname
。 - 點擊
'submit'
按鈕提交表單
在回調中:
- 斷言狀態是正常的
200
- 斷言元素
span#name
中的文本是'Amerigo'
- 斷言元素
span#surname
元素中的文本是'Vespucci'
- 斷言有
span#dates
元素,它們的計數是1
不要忘記刪除 assert.fail()
調用。
--hints--
應通過所有測試。
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
應斷言無頭瀏覽器成功執行請求。
(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);
}
);
應斷言元素 “span#surname” 中的文本爲 “Vespucci”。
(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”。
(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” 存在,且它的值爲 1。
(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);
}
);
--solutions--
/**
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.
*/