运行 在 TestCafe 中测试期间浏览器控制台中的命令
Run command in the browser's console during the test in TestCafe
我想在 TestCafe 的测试中包含这个命令。我发现我可以使用客户端函数和 t.eval 执行 JavaScript 代码,但我不知道如何进行。
测试时需要自动执行的命令:
document.querySelector(".Watchlist--form").submit()
我该怎么做?
如果无法使用test actions to submit your form, you will need to create a Client Function来做:
import { Selector, ClientFunction } from 'testcafe';
const submitAction = ClientFunction(() => {
document.querySelector(".Watchlist--form").submit();
});
fixture `My fixture`
.page `http://example.com`;
test('My test', async t => {
// Some actions and assertions before the submit action
await t
.click(Selector(...))
...
.expect(...).ok();
// Submit action
await submitAction();
// Some actions and assertions after the submit action
await t
.click(Selector(...))
...
.expect(...).ok();
});
我想在 TestCafe 的测试中包含这个命令。我发现我可以使用客户端函数和 t.eval 执行 JavaScript 代码,但我不知道如何进行。
测试时需要自动执行的命令:
document.querySelector(".Watchlist--form").submit()
我该怎么做?
如果无法使用test actions to submit your form, you will need to create a Client Function来做:
import { Selector, ClientFunction } from 'testcafe';
const submitAction = ClientFunction(() => {
document.querySelector(".Watchlist--form").submit();
});
fixture `My fixture`
.page `http://example.com`;
test('My test', async t => {
// Some actions and assertions before the submit action
await t
.click(Selector(...))
...
.expect(...).ok();
// Submit action
await submitAction();
// Some actions and assertions after the submit action
await t
.click(Selector(...))
...
.expect(...).ok();
});