0

I'm wanting to log into an app, run several searches from test data, then log out. I don't want to login and out for each item in the data set, which would be the case if I coded this way...

dataSet.forEach(data =>{ test('Search Test', async t => {......

I would like to be able to...

test('Search Test', async t => {...... foreeach(data in Data set) call a function to search call a function to verify search return.

Something like this...

test('Simple Search Test', async t => {
    //await t       
    await loginPage.login(loginName, password);
    await t
        .expect(getURL()).contains('home')

        // Check logged in user display...
        .expect(pageHeader.userName.withText(data.loggedInUser).visible).ok()

        dataSet.forEach(data =>{               
            leftSidebar.searchWithCriteria(data.criteria, 'Filename');
            recordNav.verifyTotal(data.srchresult);  
        });
       
    // Log out
    await pageHeader.logout();
    await t
        .expect(loginPage.copyRight.visible).ok(); 
});
enter code here

I've tried everything, but can't get it to work. Is this possible or does the entire test have to be run for each data record in the set?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47

2 Answers2

1

TestCafe allows you to loop through test code in any manner, including iterating through custom data.

To help us determine why this does not work for you, please provide an example that I can run on my machine (including the test code, page object, and the tested page's URL).

  • What I've posted is the example. Instead of the entire test block wrapped in a foreach, I would like to cycle through some data within a single test. So, the above test would log in once, then cycle through data as opposed to logging in, run a test for the first item in the data set, logout, login, run test for second item in data set, etc. – Superfreak3 Apr 27 '21 at 11:45
1

I got it to work using this...

for (var i = 0; i < dataSet.length; i++){
    leftSidebar.searchWithCriteria(dataSet[i].criteria, 'Filename');
    recordNav.verifyTotal(dataSet[i].srchResult);
}