Hello everyone, I am writing a script for testing the page. An error appears when using the type method in headless mode to enter data in input.
ERRO[0034] Uncaught (in promise) GoError: typing "0100AM" in "input[name=\"start-time\"]": pressing key: dispatching key event up: read tcp 127.0.0.1:55163->127.0.0.1:55162: wsarecv: An existing connection was forcibly closed by the remote host.
An interesting fact is that when logging into the account, I use the same method, but the error does not appear. Tell me what I’m doing wrong or what the error is.
I also noticed that a similar error occurs when using methods that perform actions on the keyboard.
Thanks in advance for any help.
My script:
import { check, group } from 'k6';
import { chromium } from 'k6/x/browser';
export function CreateNotification() {
const url = 'url';
const email = 'email';
const password = 'password';
const browser = chromium.launch({
headless: true,
});
const context = browser.newContext({
ignoreHTTPSErrors: true,
});
const page = context.newPage();
const startTime = "0100AM";
const endTime = "1200PM";
page.goto(url, { waitUntil: 'networkidle' })
.then(() => {
group('Description', function () {
page.waitForSelector('input[name="email"]');
page.locator('input[name="email"]').type(email); //normal typing
page.locator('input[name="password"]').type(password); //normal typing
return Promise.all([
page.waitForNavigation(),
page.locator('button[type="submit"]').click(),
]);
});
})
.then(() => {
group('Description', function () {
page.waitForSelector('div[aria-label="selector"]');
return Promise.all([
page.waitForNavigation(),
page.locator('a[href="selector"]').click(),
]);
});
})
.then(() => {
group('Description', function () {
page.waitForSelector('div[class="selector"]');
page.locator('div[aria-hidden="selector"]').click();
page.waitForSelector('div[id="selector"]');
page.locator('div[id="selector"] >> nth=0').click();
page.waitForTimeout(1000);
page.locator('div[aria-hidden="selector"] >> nth=-1').click();
page.waitForTimeout(1000);
});
group('Description', function () {
page.locator('button[name="selector"]').click();
page.waitForSelector('div[class="selector"]');
page.locator('button.rdrDayStartOfMonth').click();
page.waitForTimeout(500);
page.locator('button.rdrDayEndOfMonth').click();
page.waitForTimeout(500);
page.locator('input[name="start-time"]').type(startTime); //typing error
page.waitForTimeout(250);
page.locator('input[name="end-time"]').type(endTime); //typing error
page.waitForTimeout(250);
page.locator('button[name="selector"]').click();
});
})
.finally(() => {
page.close();
browser.close();
});
}