Continuing the discussion from Can't run browser tests with K6_BROWSER_ENABLED=true k6 run script.js:
PS C:\K6-Scripts\specs> $env:K6_BROWSER_ENABLED=true ; k6 run .\BrowserTest.js efault
true : The term ‘true’ 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:25
-
$env:K6_BROWSER_ENABLED=true ; k6 run .\BrowserTest.js
-
~~~~
-
CategoryInfo : ObjectNotFound: (true:String) , CommandNotFoundException
-
FullyQualifiedErrorId : CommandNotFoundException
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ / \ | ( / ‾‾
/ \ | |\ \ | (‾) |
/ __________ \ |__| _\ ____/ .ioexecution: local
script: .\BrowserTest.js
output: -scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s) -
ERRO[0000] Uncaught (in promise) TypeError: Cannot read property ‘launch’ of undefined or null
at browserTest (file:///C:/K6-Scripts/specs/BrowserTest.js:6:18(7)) executor=per-vu-iterations scenario=default
data_received........: 0 B 0 B/s
data_sent............: 0 B 0 B/s
iteration_duration...: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
iterations...........: 1 0/s
running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m00.0s/10m0s 1/1 iters, 1 per VU
------------------------------ find the program —
import {chromium} from ‘k6/experimental/browser’
import {check} from ‘k6’
export default async function browserTest(){
const browser=chromium.launch({headless:false})
const page= browser.newPage()
await page.goto('https://stage-lcm.ehs.edison.gehealthcare.com/')
const userName=page.locator("//input[@id='usernameUserInput']")
text.type('sb_test_lcm2@hc.ge.com');
check (page, {
'headerOfthePage' : page =>page.locator("//legend[@class='heading-30 u-mb+ u-pb text-align--center noMobileMarginAuto noMobilePadding']").isVisible()===true
})
page.close(
browser.close()
)
}