Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documentation for performing data driven testing using testCafe?

Data Driven testing is an important aspect of writing automated test cases for any tool. I have been experimenting with testcafe lately and haven't been able to find a convincing way of doing data-driven tests i.e. executing a test for different inputs.

I came across this example: https://testcafe-discuss.devexpress.com/t/multiple-execution-of-one-test-with-different-data/219 but in the above example, we are dealing with different login usernames as inputs. If I imagine a scenario where I have to check a list of elements appear on the page or not, I would surely have some steps leading to the validation; in which case I may not want to execute the leading steps each time a new input is passed. In the above example looks like the input is at a test case level and not at a test step level because we put the test case inside the for loop and therefore all the validation/navigational points will be executed whether I want to repeat them or not

Since, I am new to testcafe, and going over scattered documentation, my question is - for data-driven testing is that the only approach we have in test cafe? or there is something more convincing, non-verbose approach in testcafe- if yes could someone point me to the documentation for it?

like image 822
Monnie_tester Avatar asked Dec 28 '18 04:12

Monnie_tester


People also ask

How do I create a data driven test?

Some tips for good data-driven tests: Create automated test scripts that can easily be modified for various data scenarios. Place test data in one storage format for all test cases, be it an excel spreadsheet or a table.


1 Answers

The main concept of the data-driven testing is that you pass some data contained parameters and test the expected values to the.

The example provided in the Multiple execution of one test with different data topic's comment is a good start point:

const users = [
    { login: 'System', password: 'System' }, { login: 'Admin', password: 'Admin' }
]
for (let i = 0; i < users.length; i++) {
    let user = users[i];    test(`Login with user '${user.login}'`, async t => {
        await t.typeText(page.login.userEdit, user.login);
        // ...
    });
}

Next, you may be required to load your test data from a database, a csv file or anything else. In this case, you can use an appropriate standard Node.js module (see FAQ).

To give any further recommendations, please clarify your requirements and the task you are trying to accomplish in greater detail. Also, I've created an issue in the TestCafe repository to extend its documentation with an example of the data-driven testing.

like image 197
Alex Skorkin Avatar answered Oct 18 '22 08:10

Alex Skorkin