mardi 2 février 2021

testcafe - Using both role and data driven test

I just discovered that testcafe can handle loop for data-driven testing https://devexpress.github.io/testcafe/documentation/recipes/best-practices/create-data-driven-tests.html

I've been using role to handle my logins for a while now https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/authentication.html#user-roles

And, now I am trying to use both at the same time, with something like :

import { Selector } from 'testcafe';

const dataSet = require('./data.json');

fixture `Data-Driven Tests`
    .page `https:/xxx`;

dataSet.forEach(data => {
    test(`login`, async t => {
        await t.useRole(data.role)      
            .expect(Selector('#user-name').textContent).eql(data.userName);
    });
});

but I get the error The "role" argument is expected to be a Role instance, but it was string.

I could rewrite the login process in this test using only the data.json file, but as I'm using roles in other tests, I'd like to avoid that.

Any idea on how I can use both role and data-driven loop in my test ?

Aucun commentaire:

Enregistrer un commentaire