Script working with xk6 is not working with k6

Hi ,
I have installed k6 and using import { chromium } from 'k6/experimental/browser';
and it is working well.

Now we wanted to run some shell scripts b/w script so we have installed

Install xk6 : go install go.k6.io/xk6/cmd/xk6@latest
Install xk6-browser : xk6 build --with github.com/grafana/xk6-browser@latest
Install xk6-exec : xk6 build --with github.com/grafana/xk6-exec@latest

when i run script via ./k6 run test.js
in test.js we have to change import { chromium } from 'k6/x/browser';

i am getting ERRO[0000] could not initialize ‘…/load-site-test.js’: could not load JS test ‘file:///mnt/hgfs/nn-loadtest/load-site-test.js’: file:///mnt/hgfs/nn-loadtest/load-site-test.js: Line 31:7 Unexpected token function (and 3 more errors)

1 Like

Hi @arvind_patel,

You should only need to do the following since k6 is now bundled with xk6-browser:

go install go.k6.io/xk6/cmd/xk6@latest
xk6 build latest --with github.com/grafana/xk6-exec@latest

Once you have the binary remember to work with the environment variable K6_BROWSER_ENABLED=true.

Could you provide us with a sample shell script, the test script and the full error output?

Cheers,
Ankur

EDIT: Updated the build command to add latest flag.

1 Like

@ankur

i followed your steps installation and a grab a test file testfile .
then ran test with
k6 run testfile.js

i am still getting following error

ERRO[0000] could not initialize 'testfile.js': could not load JS test 'file:///C:/Users/***/Documents/testfile.js': json: unknown field "options"

note : i set K6_BROWSER_ENABLED=true

when i install

xk6 build --with github.com/grafana/xk6-exec@latest

existing scripts starts failing with

 Line 40:7 Unexpected token function (and 15 more errors)

Hi @arvind_patel,

Apologies, I gave you the wrong command. This should work:

xk6 build latest --with github.com/grafana/xk6-exec@latest

Without the latest flag, it would use the minimum version of k6 which is dictated by the extension that you are building with. With the latest flag, it works with the latest tagged version of k6.

I’ll update my reply from before too.

Cheers,
Ankur