vendredi 26 mars 2021

Run setup before each fixture using before

I would like to run a fixture or a set of testController methods before each fixture using testcafe's before function

fixture I want to run before each fixture extracted into a separate function

// testSetup.ts
export async function initialiseTestEnv(t: testController) {

    console.log("Initialise working env");
    
    const docNameInput =  Selector('input#documentName');
    const createBtn =  Selector('button.ui.primary.button');

    await t
        .useRole(roles.adminUser)
        .maximizeWindow()
        .navigateTo(testConfig.standardListPage)
        .typeText(docNameInput, testConfig.repoName)
        .click(createBtn);

And I would like to to run this before each fixture like:

// tests.ts
// Tests that rely on env init
fixture `Tests that rely on init event`

    .before(async t => {
        
            await initialiseTestEnv(t)
    })
    .requestHooks(logger)
    .beforeEach(async t => {
        cookies.setCookies;
        await t
            .useRole(roles.adminUser)
        })

    test('Test that relies on test env init', async t => {...}

The problem is that before does not have a test controller that I could parse to the init function. Is there another way maybe to run this init event before each fixture I run (I don't want to run in before each test, just before a fixture)

Aucun commentaire:

Enregistrer un commentaire