Load Test a Webpage with SSO

I am trying to test a webpage with SSO login. Whenever the url is hit and if the user is already logged in as SSO it redirects the user to the actual page. Until then the user is shown Loading Page msg.

I scripted a GET request in the script as below:

export function opsPortal_TenantsOverview() {
    let response

    response = http.get('https://my_url', {
        headers: {
                'Bearer MYTOKEN', //To simulate user login using JWT tokens
    check(response, { 'status equals 200': response => response.status.toString() === '200' })

    const doc = parseHTML(response.body); // equivalent to res.html()
    const pageTitle = doc.find('head title').text();
    console.log('Page Title - ' + pageTitle);
    // Automatically added sleep

When I run the script, it can verify that response code is 200.
But it cannot check whether the next screen post user authentication. I need to simulate the user SSO which redirects the user to a new screen with actual data where I need to measure the page loading time…Any ideas pls??

Hi @21.prash

I think the example we document in How to Load Test OAuth secured APIs with k6? could help you. In the test setup() function you can authenticate the VU. Once you have the bearer token for that VU, you should be able to use it in the VU code section.

There is a script example in the final section of the blog: “Test Script Template with OAuth Authentication”.

In our test lifecycle docs you’ll find more detailed explanations for the different test phases, like setup() and teardown().

Kindly update this thread if I misunderstood your questions or if you have further doubts.


1 Like