1

I have 2 test examples and when I run them both at once it seems that there is no time to execute them both till end. When I run them separately, they go through till the end.

I've read that Puppeteer-cluster can help out running multiple tests at once but the process stops right after page.goto() function. I'm not sure if this is the right approach to my issue so feel free to offer other solutions that Puppeteer-cluster.

test1:

const { Cluster } = require('puppeteer-cluster');
const timeout = 100000

const { toMatchImageSnapshot } = require('jest-image-snapshot')
expect.extend({ toMatchImageSnapshot })

describe('login', () => {
    test('test user login', async () => {
        await page.goto(URL + 'login.jsp', { waitUntil: 'domcontentloaded' });
        
        const cluster = await Cluster.launch({
            concurrency: Cluster.CONCURRENCY_CONTEXT,
            maxConcurrency: 2,
        });
    
        await cluster.task(async ({ page, data: url }) => {
            await page.goto(URL + url, { waitUntil: 'domcontentloaded' });
    
            await page.waitForSelector('input[name=username]')
            await page.type('input[name=username]', username)
            await page.type('input[name=password]', password)

            const loginFormFilled = await page.screenshot();
            expect(loginFormFilled).toMatchImageSnapshot({
                failureThreshold: '0.01',
                failureThresholdType: 'percent'
            });

            await page.waitForSelector('.roundButton').then(async () =>{
                await page.evaluateHandle(() => {
                    let button = [...document.querySelectorAll('.roundButton')].find(element => element.textContent === 'Prijavi se');
                    if(button){
                        button.click();
                    }
                });
            })

            await page.waitForSelector(".profilePic")
            const image = await page.screenshot();
            expect(image).toMatchImageSnapshot({
                failureThreshold: '0.10',
                failureThresholdType: 'percent'
            });
        });
    
        cluster.queue('login.jsp');

        await cluster.idle();
        await cluster.close();
    }, timeout);
});

The second test is almost the same just instead of login I'm testing registration process.

I've tried the same examples as here https://www.npmjs.com/package/puppeteer-cluster but the test stops right after page.goto and ends as passed test.

In near future ill have 30-40+ tests similar to test1 and I need to run them with one command instead of one by one.

Angelov
  • 51
  • 5

0 Answers0