Hi everyone!! I’m new to k6. I just tried implementing the below code but I am getting
ERRO[0000] Uncaught (in promise) TypeError: Cannot read property ‘launch’ of undefined or null at file:///D:/K6/K6_REPO/FRONT_END_PERFORMANCE_TEST/Specs/sampleTest.js:6:14(3) executor=per-vu-iterations scenario=default
How to solve this, what am I missing???
Browser is not launching
Hi @umaisummer!
Try it this way:
import {browser} from 'k6/experimental/browser';
import {sleep} from 'k6';
export const options = {
scenarios: {
perftest: {
executor: 'per-vu-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}
export default async function(){
const page = browser.newPage();
try{
const response = await page.goto('https://testorg.stotte.no',{waitUntil:'networkidle'});
sleep(4);
console.log('Status Code:', response.status());
}finally{
page.close();
}
}
If you want to run it with visible browser, just run with K6_BROWSER_HEADLESS=false k6 run script.js
Hey @umaisummer , welcome to the forum!
@bandorko is right! That is the correct syntax for the latest version. Give it a try.
The syntax that you were using in your implementation corresponds to a previous version (<v0.46). k6 v0.46 introduced a few breaking changes for the browser module, you can see more details in this migration guide.
The syntax is not working for me now. It says
K6_BROWSER_HEADLESS=false : The term ‘K6_BROWSER_HEADLESS=false’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
- K6_BROWSER_HEADLESS=false k6 run script.js
-
+ CategoryInfo : ObjectNotFound: (K6_BROWSER_HEADLESS=false:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Is there any new syntax to run it with visible browser?
Hi @saivignesh0303,
I believe you’re running tests on Windows. Did you try the following:
set "K6_BROWSER_HEADLESS=false" && k6 run script.js
Yes @inancgumus I am running tests on windows and I tried that command too and I received the following error
At line:1 char:33
- set “K6_BROWSER_HEADLESS=false” && k6 run script.js
-
~~
The token ‘&&’ is not a valid statement separator in this version.
+ CategoryInfo : ParserError: ( , ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine
Thank you, @bandorko. It worked. Thanks a lot again. Could you please tell me what are the selectors supported by the xk6 browser to select an element in a web page like CSS selector, XPath,… that could be used with page.locator()?
According to this document: Selecting elements it supports css and xpath selectors
Hi @francoesteves,
You need to update your script and migrate to the new version using this migration guide.
when I tried with this, code mentioned by @bandorko , i got below error:
ERRO[0000] process with PID 27964 unexpectedly ended: exit status 126 category=browser elapsed=“0 ms” source=browser
and not getting how to deal with this