Chat room front end & back end simulation

Hi I’m a K6 rookie,
I want to know if K6 can be used in chat rooms.
Can I use K6 vus simulation many users incoming line?
Simulate real person incoming line.
ex: I want make 20 VUS and I want see these 20 VUS in my back end.
I hope in my back end can see my K6 vus incoming line and send message.

Before that, I used chrome Driver+ selenium to simulate the action of real person clicking the button to enter the chat room.
But executing multiple browsers is too taxing on my computer…

Best regards

Yes, you can, assuming your chat uses HTTP or websockets? A k6 VU is an independent (parallel) JavaScript runtime, so you can simulate real users with them on the protocol (e.g. HTTP, WebSockets) level.

Before that, I used chrome Driver+ selenium to simulate the action of real person clicking the button to enter the chat room.

If you don’t want to work on the protocol level, we also have the xk6-browser extension, see https://github.com/grafana/xk6-browser and https://k6.io/docs/javascript-api/xk6-browser/ for details.

1 Like

First I using xk6-browser testing now,
thanks your reply.
Best regards

Can I ask you a question here?
I using xk6-browser and set like k6 load testing options = {vus:10,iterations}
But I have a problem.
My first Vus(first open browser) process success other browser will then close.
I want all browser process success than close.
Is it not supported?
or maybe I can setting where.
tks.

Hi Louis,

Unfortunately, multiple browsers and VUs support are experimental at this moment. We recommend you to use a single browser and VU.

Thanks.

1 Like

ok,that sounds bad.
I’m looking for a better way to simulate browser multiplayer.
Thanks.
good luck

@Louis What specific errors are you having with more than 1 VU? Could you share your script here?

While support for it is currently experimental, from my limited testing it should work as expected. There’s currently no way to reuse a browser instance across iterations, so every VU will launch a new browser process for each iteration, but that might be desired anyway. If you run with headless: true you can avoid the browser windows popping up to make it more manageable, and running with many VUs will require a lot of system resources, but otherwise you shouldn’t run into any issues. And if you do, this might be a good starting point for us to fix it so it can eventually have better support. :smiley:

Hi
I’m not sure where have specific errors
but I guess is my page load fail so page.waitForSelector can find it
(wait for selector “div[class="flex-grow-1 overflow-auto ctc-msg-layout pb-5"]> div:nth-child(1) > div:nth-child(6)> div” did not result in any nodes at reflect.methodValueCall (native))
maybe not this problem
English is not my native language.
so I didn’t explain clearly enough
I’m awfully sorry.

This is my k6 script
But website is private so I can’t support it.

import launcher from "k6/x/browser";
import {sleep} from 'k6';

export const options= {
    vus: 10,
    iterations:10
}

export default function() {
    const browser = launcher.launch('chromium', { headless: false,timeout:'5m' });
    const context = browser.newContext({viewport: { width: 800, height: 600 }});
    const page = context.newPage();

    page.goto('https://private/website',{waitUntil:'networkidle'}); //example can't open
    page.waitForSelector('p[class="d-inline-block text-break-all my-2 p-3 bg-gray100 border rounded"]');
    sleep(3);

    let openIVRlist = page.$('div[class="flex-shrink-0"]>button:nth-child(1)');
    openIVRlist.click();
    page.waitForSelector('div[class="flex-grow-1 overflow-auto ctc-msg-layout pb-5"]> div:nth-child(1) > div:nth-child(6)> div');
    sleep(3);

    let selectIVR = page.$('div[class="flex-grow-1 overflow-auto ctc-msg-layout pb-5"] > div:nth-child(1) > div:nth-child(6)> div');
    selectIVR.click();
    sleep(3);

    let clickInput = page.$('textarea[id="textarea"]').type('haha');
    sleep(5);
    
    let sendMessage = page.$('div[class="flex-shrink-0"]>div>a:nth-child(3)>span');
    sendMessage.click();
    sleep(30);

}
	

@Louis, I should add that we can’t guarantee anything about running multiple browsers and VUs at this moment. However, as @imiric mentioned, it might work to some extent. The downside is that it may use a lot of system resources. Then again, it would be good to learn from your experience so we can improve the extension :heart_eyes:

@Louis If it’s a wrong selector that fails occasionally it’s difficult to help you without being able to test against your site.

Try using less specific selectors, and particularly avoid :nth-child() or immediate child (>) as that can break easily if your layout is dynamic. Instead, see if you can use just one ID or class name, which would have less chances of breaking.

Also, consider using XPath selectors, which can be more powerful than CSS selectors. They can allow you to, for example, locate an element with a class containing a name, or an element with specific inner text. E.g.: page.waitForSelector('//a[contains(@class, "common__SidebarMenuLink") and text()="Options"]').

Also, try running with headless: true. See how it’s specified here. In my tests it avoids a Cannot find context with specified id error, and it might help in your case.

PS: Your English is fine, no worries. :slight_smile:

@inanc @imiric
Thank you for your reply.
Wish K6 grow in the future :muscle:

1 Like