grafana / xk6-browser

k6 extension that adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol
https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/browser/
GNU Affero General Public License v3.0
326 stars 41 forks source link

SSO/AAD Login feature #1256

Open mridiniveni opened 3 months ago

mridiniveni commented 3 months ago

Feature Description

Hi, I am new to k6 browser and i have experience with playwright i am just wondering how can we achieve SSO /AAD login in k6 browser , I can able to acheive in playwright by setting the arguments as launchOptions.setArgs(Arrays.asList(“–auth-server-allowlist”,“–auth-server-whitelist=‘_’,”) and also added HTTPCredentials in browser new context options. Similarly i tried in k6 browser but iam unable to login the application and its a blocker for me.Below code i have added in k6 browser and i noticed though we mention browser type as chromium but still the test is running on browser chrome , on chrome browser . Can we strictly run on chromium ?

Version: V0.50.0

import { browser } from ‘k6 / experimental / browser’;
import { check } from ‘k6’;

export const options = {
    scenarios: {
        ui: {
            executor: 'shared-iterations',
            vus: 2,
            iterations: 2,
            options: {
                browser: {
                    type: 'chromium',
                },
            },
        },
    },
    thresholds: {
        checks: ['rate==1.0'],
    },
};

export default async function () {
    const context = browser.newContext({
        httpCredentials: {
            username: 'username',
            password: 'password',
        },
        ignoreHTTPSErrors: true,
    });

    const page = context.newPage();

    try {
        await page.goto('mfaurl');
        page.waitForTimeout(6000);
    } finally {
        page.close();
    }
}

Suggested Solution (optional)

No response

Already existing or connected issues / PRs (optional)

No response

ankur22 commented 2 months ago

Hi @mridiniveni,

Thanks for opening a new feature request. We usually prefer it if you first create a new post in our k6 browser community forum so that we can identify exactly what new feature we might need to help with your issue.

The httpCredentials option in browser.newContext works for basic auth, what authentication mechanism is your website using?

Passing extra arguments to chrome can be done with the environment variable K6_BROWSER_ARGS, for example K6_BROWSER_ARGS="–auth-server-allowlist,–auth-server-whitelist='_'".

The k6 browser module will look for an installed version of chrome or chromium. Take a look at the code here and you should be able to find the order for your specific OS. You can override the default by using the environment variable K6_BROWSER_EXECUTABLE_PATH, for example K6_BROWSER_EXECUTABLE_PATH=/Applications/Chromium.app/Contents/MacOS/Chromium.

Hope this information helps. Please create a new issue in our community forum if you need more assistance.