I tried to use page.url(), but apparently it is not working.
See my script below:
import { chromium } from ‘k6/x/browser’;
import { sleep } from ‘k6’;
var URL = ‘http://ecommerce.test.k6.io/’;
export default function () {
const browser = chromium.launch({ headless: false, slowMo: ‘500ms’ });
const context = browser.newContext();
const page = context.newPage();
page
.goto(URL, {
waitUntil: 'networkidle',
waitUntil: 'load',
}).then(() => {
page.$('img[src="http://ecommerce.test.k6.io/wordpress/wp-content/uploads/2021/02/album-1.jpg"]').click();
var currentURL = page.url();
console.log(currentURL);
sleep(1000);
}).finally(() =>{
page.close();
browser.close();
});
}
For this I got the error:
ERRO[0008] process with PID 19956 unexpectedly ended: exit status 1 category=browser elapsed=“0 ms” goroutine=15
ERRO[0008] cleaning up the user data directory: remove C:\Users\FD1DF~1.GAR\AppData\Local\Temp\xk6-browser-data-2390913065\Default\Affiliation Database: The process cannot access the file because it is being used by another process. category=“Browser:Close” elapsed=“1 ms” goroutine=60
ERRO[0008] Uncaught (in promise) GoError: evaluating JS: execution context changed; most likely because of a navigation
running at github.com/grafana/xk6-browser/api.Page.URL-fm (native)
default at file:///C:/Users/f.gardin/k6/har_files/xk6-browser/script.js:18:29(10) executor=per-vu-iterations scenario=default
I need to capture the URL after the action as a string, is there another way to do this???