0

我是 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,但没有找到任何对应的方法;因此,非常感谢任何帮助或提示,谢谢。

4

1 回答 1

2

请参考此线程:使用 JavaScript 清除所有 cookie 它有一个很好的代码示例,演示了如何解析 \ clear cookie。您可以在 ClientFunction 中使用此代码作为检测和清除特定 cookie 的起点。

于 2021-07-01T08:24:00.373 回答