DWA
DWA

Reputation: 530

Testcafe Testcase failing with ReferenceError: testcafe_1 is not defined

I am working on a Testcafe Testcase implementation that should check if it is possible to give consent by clicking on the usual consent layer that allows the user to consent to all or certain Tracking activities from Third parties,in this case for a specific website.

In short: The testcase should check if it is possible to give this consent two times in a row. It should check this also by checking if there are any Cookies before and after giving Consent; that´s how I came up with the following implementation:

test
    .disablePageCaching
    .timeouts({
        pageLoadTimeout:    1000,
        pageRequestTimeout: 1000
    })
    ('should check if it is possible to give Consent two subsequent times', async t => {

        const getAnyCookie = ClientFunction(() => {
            let getCookies = ClientFunction(() => document.cookie.split(";"))

            if (getCookies) {
                return true
            }
            else {
                return false
            }
        })
        await t.wait(3000);

        adobeAnalyticsLogger.clear();
        await t.navigateTo('http://www.anywebsite.com')
        await getAnyCookie;
        await t.expect(getAnyCookie()).ok()
        await consentLayer.clickAcceptButton();
        await t.eval(() => location.reload(true))
        await getAnyCookie;
        await t.expect(getAnyCookie()).ok()
        await consentLayer.clickAcceptButton();
    });

It is failing with the following error message:

 ✖ should check if it is possible to give Consent two subsequent times

   1) An error occurred in ClientFunction code:
      
      ReferenceError: testcafe_1 is not defined

This error message makes no sense to me, as there is no Cookie named testcafe_1 defined somewhere in the code. Where does this derive from? Is this the best way to do it or does someone maybe have a better idea on how to test this Usecase? Any hints or help would be very much appreciated, thanks in advance.

Upvotes: 1

Views: 795

Answers (1)

mlosev
mlosev

Reputation: 5227

Your code has some issues:

  • ClientFunction cannot be nested
  • you didn't call the 'getAnyCookie' as a function
  • duplicated calls of the 'getAnyCookie' expression

Fixed code will look as follows:

('should check if it is possible to give Consent two subsequent times', async t => {

const getAnyCookie = ClientFunction(() => {
return document.cookie.split(";");
});

await t.wait(3000);

adobeAnalyticsLogger.clear();
await t.navigateTo('http://www.anywebsite.com')
await t.expect(getAnyCookie()).ok()
await consentLayer.clickAcceptButton();
await t.eval(() => location.reload(true))
await t.expect(getAnyCookie()).ok()
await consentLayer.clickAcceptButton();
});

Upvotes: 2

Related Questions