Testcafe data driven testing - how to drive tests with data fetched from API

I'm having trouble figuring out how to drive tests with data fetched from a request. I've read the documentation here: https://testcafe.io/documentation/402804/recipes/best-practices/create-data-driven-tests, and all examples use static json file data available at compile time.

I can't fetch the data in fixture.before hook, because it will only be available inside of the test context, but I need to access the data outside of the test context for iteration, such that the test is inside of a for loop.

I've tried this solution: https://github.com/DevExpress/testcafe/issues/1948, however this fails with testcafe ERROR No tests found in the specified source files. Ensure the sources contain the 'fixture' and 'test' directives., even when I use the flag disable-test-syntax-validation and .run({ disableTestSyntaxValidation: true }); option.

I am looking for suggestions and workarounds so that I can await some data, then run my tests. Even if Testcafe doesn't explicitly support something like this, I figure there must be some workaround... Thanks in advance.

Edit:

file-a.ts

export function tSteps(...args) {
    // some setup

    const testcase = args[args.length - 1];
   
    const testCtx = test(name, async t => {
        ...
    });
    return testCtx;
}

----

file-b.ts


export const parameterizedTest = <T>(..., testcase: (scenario: T) => TestFn) => {
    // some setup...
    // I have also tried awaiting rows data here, which does not work 
    // because tests are not discoverable at compile time 
    ...

    const scenarios: T[] = rows.map(row => {
        ...
    });

    scenarios.forEach((scenario, idx) => {
        return testcase(scenario).meta({
            some metadata
        });
    });
};

----

tests.ts

fixture(...).before(async () => {
    // can't get the data i need here because it needs to be available outside of the fixture context
})

parameterizedTest<MyInterface>(some params, (scenario: MyInterface) => {
        return tSteps('my test',
            async f => {
                // some setup

                // test code goes here which uses scenario.attributex, scenario.attributey, etc.
            }
        ).meta(...);
    }
);


from Recent Questions - Stack Overflow https://ift.tt/IyAqjO6
https://ift.tt/b0mGdeN

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation