

The k6 Browser API aims to provide a rough compatibility with the Playwright API for NodeJS, meaning k6 users don't have to learn an entirely new API.Īt the moment, the k6 API is synchronous. To run the test, simply use the following command.

Since there are two asynchronous operations, we need to use Promise.all() to wait for the two promises to be resolved before continuing to avoid any race conditions.Clicking the submit button also causes page navigation which we need to wait to load, so page.waitForNavigation(), another asynchronous operation, is needed because the page won't be ready until the navigation completes. To click the login button, we use the click method, which is an asynchronous operation.
Browser benchmark test password#
We use the type method to type the name and password into the fields. One for the login name and another one for the login password. In the example, we are creating two locators. Once the operation completes, we use page.locator to interact with the elements we want.page.goto is also an asynchronous operation, so we need to wait for this to finish and use the await keyword. We are also waiting for the network to be idle, which will succeed if there are no network connections for at least 500 ms. We visit the page by using page.goto and pass the test application URL.
Browser benchmark test code#
There are a lot of things happening in the preceding code especially the introduction of asynchronous operations so let’s break it down again. You can copy one of our example scripts to get started as part of our k6 browser module documentation. It also offers a simplified experience and aggregated view of performance metrics. The browser module offers a unique solution as you don’t have to use separate tools to test your frontend and backend systems. This can simulate the bulk of your traffic from your protocol-level tests and run one or two virtual users on a browser level to mimic how a user interacts with your website, thus leveraging a hybrid approach to performance testing. You can now mix browser-level and protocol-level tests in a single and unified script using k6. It enables you to get insights from your front-end application during performance testing. The browser module brings browser automation and end-to-end web testing to k6 while supporting core k6 features. This is where the k6 browser module comes in. Here at k6, we want to start expanding our performance testing use case and also test beyond the protocol level. Your users interact with the browser, so it's also vital to test the browser's performance to get an end-to-end perspective of what's happening when interacting with your web applications.īoth frontend and backend performance testing has its pros and cons when done in isolation, which we discussed in more detail as part of the video below. Most load-testing tools focus on testing API endpoints, but it's different from what your users normally interact with. In that case, you need to drive some of your performance testing efforts from a browser perspective and consider a more realistic end-to-end test of the user flow. Suppose you test the user experience of your website and verify that there are no performance issues on a specific user journey. Our comprehensive load testing guide recommends keeping users in mind, and backend performance testing only addresses half of your performance testing efforts. Most of our efforts have focused on providing a tool that helps test your servers or backend systems. Over the years, k6 has become known as a performance testing tool that provides the best developer experience.
