我是 Testcafé 的新手,正在研究一个 Testcase 以检查是否事先不存在 Cookie,如果有 Cookie,则删除 Cookie。我已经检查了这个和这个帖子,但没有看到任何关于如何检查 cookie 是否存在或不存在的选项,因为帖子描述了如何设置 Cookie。
我的第一个实现如下所示:
import { ClientFunction } from 'testcafe';
const setCookie = ClientFunction(() => {
if (document.cookie.length!==0)
{
document.cookie = 'COOKIE_NAME=; Max-Age=0; path=/; domain=' + location.host;
}
});
fixture `fixture`
.page `http://google.com`;
test(`1`, async t => {
await setCookie();
await t.typeText('input[type=text]', 'test');
await t.debug();
});
我检查了Testcafé API,但没有找到任何对应的方法;因此,非常感谢任何帮助或提示,谢谢。