testinginstallationautomated-teststestcafeteardown

Call external URL to setup and teardown in Testcafe


I'm using Testcafe with an application that has a database driven backend (no API, but MVC).

I would like to Setup and Teardown settings in the database prior to running the tests. This can be down by calling an URL on my application (e.g. https://myapp.local/setup?foo=bar or https://myapp.local/teardown?foo=bar)

I would like to call these URLS from within Testcafe, prior to running the test. I have looked at the module testcafe-once-hook(https://github.com/DevExpress/testcafe-once-hook) and the accompanying examples (https://github.com/AlexKamaev/testcafe-once-hook-example)

import { oncePerFixture } from 'testcafe-once-hook';

const setupDb = oncePerFixture(async t => {
    await t.navigateTo('https://myapp.local/setup?foo=bar');
});


fixture `Setup db`
    .before(() => {
        setupDb;
    })

    test('Test1', async t => {
        /* Test 1 Code */
    });

but the URL in setupDb is never called as I can see from my Apache logfiles.

I also looked at https://github.com/DevExpress/testcafe/issues/1345#issuecomment-338796731, but here also the URL is never called as I can see from my Apache logfiles.

fixture `Setup db`
    .before(async ctx => {
        ctx.hasSetup = false;
        // Server-side actions
    })
    .beforeEach( async t => {
        if (!t.fixtureCtx.hasSetup) {
            await t.navigateTo('https://myapp.local/setup?foo=bar');
            t.fixtureCtx.hasSetup = true;
        }
        else {
            return t;
        }
    })

How can I achieve that https://myapp.local/setup?foo=bar is called beforehand?


Solution

  • At the moment I'm running testcafe@6.14.11 and testcafe-once-hook@0.0.4 and this has solved my issues.