SSL error with k6-browser

Hi
I have a site which need a ssl certificate to install on machine.

i am trying to setup test on linux vm ( GCP ).

I have installed certificate at /usr/local/share/ca-certificates/ dir
verified by running puppeeter test script successfully

const puppeteer = require('puppeteer');
const fs = require('fs');

async function run () {

  const browser = await puppeteer.launch({
    defaultViewport: {width: 1920, height: 1080},
     args: [ '--ignore-certificate-errors' ]
  });  

  const page = await browser.newPage();
  await page.goto('siteUrl', {timeout: 60000});
  await sleep(15000);
  
  await page.screenshot({path: 'screenshot.png'});
  const html = await page.content();
  fs.writeFileSync('source.htm', html);
  
  browser.close();
}
run();

function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}  

Now i have tried run k6 script

import { chromium } from 'k6/experimental/browser';
import { check, sleep, expect } from 'k6';
import exec from 'k6/execution';
import { htmlReport } from "./report_bundle.js";
import { textSummary } from "./report_summery_index.js";
import { Trend } from 'k6/metrics';

const users = new Trend('user jurney time', true);

export const options = {
insecureSkipTLSVerify: true,
scenarios: {
    browser: {
      executor: 'per-vu-iterations',
      exec: 'browser',
      vus: 1,
      iterations: '1'
      //duration: '5s',
    }
  }
};

export async function browser() {

const browser = chromium.launch({ 
  headless: true,
  //timeout: '2m',
  args: [ '--ignore-certificate-errors' ],
 // executablePath: '/snap/bin/chromium',
//  userDataDir: "'./chromeProfiles/'"+ exec.vu.idInTest ,
});

const context = browser.newContext(); //one browser instance
//context.setDefaultTimeout(180);
const page = context.newPage(); // one tab

await page.goto('testsite');
console.log('page  loaded');

page.screenshot({ path: './actual_page_screenshot333.png'});
page.waitForSelector("div[class$='overlay-box']");

sleep(2);
page.close();
browser.close();
} 

Error :

communicating with browser: websocket: close 1006 (abnormal closure): unexpected EOF  category=cdp elapsed="0 ms" goroutine=40
ERRO[0030] Uncaught (in promise) GoError: waiting for selector "div[class$='overlay-box']": waiting for selector "div[class$='overlay-box']" did not result in any nodes
browser at github.com/grafana/xk6-browser/browser.mapPage.func11 (native)

i checked screenshot and its very small size blank white page

i checked similar thread and verified steps

Hi @arvind_patel,

Can you confirm that your puppeteer script works if you do a similar wait for selector on "div[class$='overlay-box']"?

It’s difficult to pinpoint the issue without being able to test against the same website that you are testing against. Could you point your script against a publicly accessible website and replicate the issue?

I’ve ran the following script and it worked:

import { chromium } from 'k6/experimental/browser';

export const options = {
    insecureSkipTLSVerify: true,
    scenarios: {
        browser: {
            executor: 'per-vu-iterations',
            exec: 'browser',
            vus: 1,
            iterations: '1'
        }
    }
};

export async function browser() {
    const browser = chromium.launch({
        headless: true,
        args: ['--ignore-certificate-errors'],
    });

    const context = browser.newContext(); //one browser instance
    const page = context.newPage(); // one tab

    await page.goto('https://test.k6.io');
    console.log('page loaded');

    page.screenshot({ path: './actual_page_screenshot333.png' });
    console.log('screenshot taken');

    page.waitForSelector("div[class$='logo']");
    console.log('wait complete');

    page.close();
    browser.close();
} 

At the moment I can only guess that the selector is incorrect or the element never becomes visible when the page loads.

Cheers,
Ankur

for public website its working. for internal website i have install certificate on linux vm. i tried similar script with puppeteer its working with ignore-cert flat.
when i run k6 test with same flag its giving me blank page only

Hi @arvindpatel5788,

Sorry for the delay in getting back to you. I noticed that in my previous reply I made a mistake with the argument, it should be ignore-certificate-errors without the --:

    const browser = chromium.launch({
        headless: true,
        args: ['ignore-certificate-errors'],
    });

Let me know if that works.

Cheers,
Ankur