Multi user e2e testing with puppeteer

Viewed 551

I am looking for a product that would allow me simulate/test multiple (more than two) users, each logged in to their account, use a web application.

Having multiple users in the test is not to simulate high load as is the case of stress testing; nor it is to make for shorter test time with parallel testing. The reason is to test if the application behaves correctly when users interact with each other.

So basically each user will have their own session cookie sent with ajax or ordinary GET and POST requests they send.

The users each could live in a separate window or be in an iframe on a single page.

Reading through these issues I could not say for sure if this is possible in the latest version of puppeteer or not. Can this be achieved?

Issues:

1 Answers

If I understand correct, you need some e2e tests for such cases?

I'm using puppeteer as test framework + Jest as test runner ( both updated to the latest version). In some tests-suites I have more than 3 test cases where I need separately logged users in separate browsers + some test cases where 2 different users interacting with each other.

As example, you can create different pages with :

const createIncognitoPage = async () => {
    const newPage = await page
        .browser()
        .createIncognitoBrowserContext()
        .then(c => c.newPage());
    return newPage;
};

After that you can use it in your test suite :

let clientPage: Page;

    it('waitForClientElement', async () => {
        clientPage = await createIncognitoPage();
        clientpage.goto('url')
        clientPage.waitFor(element);
     
    });

let adminPage: Page; 

    it('waitForSomeoneAnotherElement', async () => {
        adminPage = await createIncognitoPage();
        await adminPage.goto('adminpageUrl'
     
    });

// then you can iterate between created pages and close em if needed

It's a very simple example. You can iterate between pages and etc. Also create pages in beforeAll block. Hope this will help!

Related