Testcafe - пример удаления куки - PullRequest
0 голосов
/ 19 марта 2020

Может ли кто-нибудь предоставить мне рабочий пример удаления файлов cookie в testcafe.

Я нашел
Как удалить все файлы cookie для текущего сеанса в testcafe? который говорит использовать функцию клиента и ссылки на SO Очистка всех куки с помощью JavaScript

Я проверил пример удаления куки из SO работает в браузере.

Но когда я пытаюсь добавить функцию клиента в мой тест, куки-файлы не удаляются, а вошедший в систему пользователь остается в системе.

Любая помощь приветствуется

пример кода ниже

import { Selector } from 'testcafe';
import { ClientFunction } from 'testcafe';
import {testData} from "../../_Config/testDataDetails";
import moment from "moment";
const testdata = new testData();


const getURL = ClientFunction(() => window.location.href);

 const deleteAllCookies = ClientFunction(() => {
     const cookies = document.cookie.split(";");
     for (let i = 0; i < cookies.length; i++) {
     const cookie = cookies[i];
     const eqPos = cookie.indexOf("=");
     const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
     document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
 }
 });
fixture`Session Timeout`
    .page`testdata.url`
    .beforeEach( async t => {
    t.maximizeWindow();
})
     test('Verify deleting session cookies logs user out ', async t => {
     await t
     .typeText(Selector('#Email'), testdata.un)
     .typeText(Selector('#Password'), testdata.pw)
     .click(Selector('button').withText('Log in'))
     .click(Selector('a').withText('Create Application'))
     const url = await getURL();
     console.log(url);
     await deleteAllCookies();
     await t.eval(() => location.reload(true));
     console.log(`Should have just refreshed page after deleting cookies `);
     await t.expect(await Selector('label').withText('for the applicant').visible).ok();
     await t.click(Selector('label').withText('for the applicant'))
     .click( Selector('.btn.btn-info').nth(1).find('strong').withText('Start'))
     await t .expect(await Selector('button').withText('Save and continue later ').visible).ok();
 });
...