Skip to content

Commit 49ad91c

Browse files
inancgumusankur22
andauthored
🤖 Merge PR DefinitelyTyped#74295 Type updates for v1.5.0 k6 release by @inancgumus
Co-authored-by: Ankur <akahank@gmail.com>
1 parent bfb29db commit 49ad91c

File tree

3 files changed

+176
-1
lines changed

3 files changed

+176
-1
lines changed

types/k6/browser/index.d.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,6 +3231,29 @@ export interface Locator {
32313231
*/
32323232
press(key: string, options?: KeyboardPressOptions): Promise<void>;
32333233

3234+
/**
3235+
* Focuses the element and then sends a `keydown`, `keypress`/`input`, and
3236+
* `keyup` event for each character in the text.
3237+
*
3238+
* This method is useful for simulating real user typing behavior when the page
3239+
* has special keyboard event handling, such as input validation or autocomplete.
3240+
* For simple text input without special keyboard handling, use {@link fill | fill()}
3241+
* instead as it's faster and more reliable.
3242+
*
3243+
* @example
3244+
* ```js
3245+
* // Type text instantly
3246+
* await locator.pressSequentially('Hello World');
3247+
*
3248+
* // Type text with delay between keypresses (like a real user)
3249+
* await locator.pressSequentially('Hello World', { delay: 100 });
3250+
* ```
3251+
*
3252+
* @param text Text to type into the focused element character by character.
3253+
* @param options Typing options.
3254+
*/
3255+
pressSequentially(text: string, options?: KeyboardPressOptions): Promise<void>;
3256+
32343257
/**
32353258
* Type a text into the input field.
32363259
* @param text Text to type into the input field.
@@ -5693,6 +5716,120 @@ export interface Page {
56935716
},
56945717
): Promise<Request | null>;
56955718

5719+
/**
5720+
* Waits for the specified event to be emitted.
5721+
*
5722+
* This method blocks until the event is captured or the timeout is reached.
5723+
* Supported event types are `console`, `request`, or `response`.
5724+
*
5725+
* @example
5726+
* ```js
5727+
* // Wait for a console message containing 'hello'
5728+
* const msgPromise = page.waitForEvent('console', msg => msg.text().includes('hello'));
5729+
* await page.evaluate(() => console.log('hello world'));
5730+
* const msg = await msgPromise;
5731+
* ```
5732+
*
5733+
* @param event Event name to wait for: `'console'`.
5734+
* @param optionsOrPredicate Either a predicate function or an options object.
5735+
*/
5736+
waitForEvent(
5737+
event: "console",
5738+
optionsOrPredicate?:
5739+
| ((msg: ConsoleMessage) => boolean)
5740+
| {
5741+
/**
5742+
* Predicate function that returns `true` when the expected event is received.
5743+
*/
5744+
predicate?: (msg: ConsoleMessage) => boolean;
5745+
/**
5746+
* Maximum time to wait in milliseconds. Defaults to `30` seconds.
5747+
* The default value can be changed via the
5748+
* browserContext.setDefaultTimeout(timeout) or
5749+
* page.setDefaultTimeout(timeout) methods.
5750+
*
5751+
* Setting the value to `0` will disable the timeout.
5752+
*/
5753+
timeout?: number;
5754+
},
5755+
): Promise<ConsoleMessage>;
5756+
5757+
/**
5758+
* Waits for the specified event to be emitted.
5759+
*
5760+
* This method blocks until the event is captured or the timeout is reached.
5761+
* It can wait for any page event such as `console`, `request`, or `response`.
5762+
*
5763+
* @example
5764+
* ```js
5765+
* // Wait for a request to a specific URL
5766+
* const reqPromise = page.waitForEvent('request', req => req.url().includes('/api'));
5767+
* await page.click('button');
5768+
* const req = await reqPromise;
5769+
* ```
5770+
*
5771+
* @param event Event name to wait for: `'request'`.
5772+
* @param optionsOrPredicate Either a predicate function or an options object.
5773+
*/
5774+
waitForEvent(
5775+
event: "request",
5776+
optionsOrPredicate?:
5777+
| ((req: Request) => boolean)
5778+
| {
5779+
/**
5780+
* Predicate function that returns `true` when the expected event is received.
5781+
*/
5782+
predicate?: (req: Request) => boolean;
5783+
/**
5784+
* Maximum time to wait in milliseconds. Defaults to `30` seconds.
5785+
* The default value can be changed via the
5786+
* browserContext.setDefaultTimeout(timeout) or
5787+
* page.setDefaultTimeout(timeout) methods.
5788+
*
5789+
* Setting the value to `0` will disable the timeout.
5790+
*/
5791+
timeout?: number;
5792+
},
5793+
): Promise<Request>;
5794+
5795+
/**
5796+
* Waits for the specified event to be emitted.
5797+
*
5798+
* This method blocks until the event is captured or the timeout is reached.
5799+
* It can wait for any page event such as `console`, `request`, or `response`.
5800+
*
5801+
* @example
5802+
* ```js
5803+
* // Wait for a response from a specific URL
5804+
* const resPromise = page.waitForEvent('response', res => res.url().includes('/api'));
5805+
* await page.click('button');
5806+
* const res = await resPromise;
5807+
* ```
5808+
*
5809+
* @param event Event name to wait for: `'response'`.
5810+
* @param optionsOrPredicate Either a predicate function or an options object.
5811+
*/
5812+
waitForEvent(
5813+
event: "response",
5814+
optionsOrPredicate?:
5815+
| ((res: Response) => boolean)
5816+
| {
5817+
/**
5818+
* Predicate function that returns `true` when the expected event is received.
5819+
*/
5820+
predicate?: (res: Response) => boolean;
5821+
/**
5822+
* Maximum time to wait in milliseconds. Defaults to `30` seconds.
5823+
* The default value can be changed via the
5824+
* browserContext.setDefaultTimeout(timeout) or
5825+
* page.setDefaultTimeout(timeout) methods.
5826+
*
5827+
* Setting the value to `0` will disable the timeout.
5828+
*/
5829+
timeout?: number;
5830+
},
5831+
): Promise<Response>;
5832+
56965833
/**
56975834
* **NOTE** Use web assertions that assert visibility or a locator-based
56985835
* locator.waitFor([options]) instead.

types/k6/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/k6",
4-
"version": "1.4.9999",
4+
"version": "1.5.9999",
55
"type": "module",
66
"projects": [
77
"https://grafana.com/docs/k6/latest/"

types/k6/test/browser.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,31 @@ async function test() {
10541054
// $ExpectType Promise<Request | null>
10551055
page.waitForRequest("https://example.com", { timeout: 10000 });
10561056

1057+
// @ts-expect-error
1058+
page.waitForEvent();
1059+
// $ExpectType Promise<ConsoleMessage>
1060+
page.waitForEvent("console");
1061+
// $ExpectType Promise<ConsoleMessage>
1062+
page.waitForEvent("console", (msg) => msg.text().includes("hello"));
1063+
// $ExpectType Promise<ConsoleMessage>
1064+
page.waitForEvent("console", { predicate: (msg) => msg.text().includes("hello") });
1065+
// $ExpectType Promise<ConsoleMessage>
1066+
page.waitForEvent("console", { timeout: 10000 });
1067+
// $ExpectType Promise<ConsoleMessage>
1068+
page.waitForEvent("console", { predicate: (msg) => msg.text().includes("hello"), timeout: 10000 });
1069+
// $ExpectType Promise<Request>
1070+
page.waitForEvent("request");
1071+
// $ExpectType Promise<Request>
1072+
page.waitForEvent("request", (req) => req.url().includes("/api"));
1073+
// $ExpectType Promise<Request>
1074+
page.waitForEvent("request", { predicate: (req) => req.url().includes("/api"), timeout: 10000 });
1075+
// $ExpectType Promise<Response>
1076+
page.waitForEvent("response");
1077+
// $ExpectType Promise<Response>
1078+
page.waitForEvent("response", (res) => res.url().includes("/api"));
1079+
// $ExpectType Promise<Response>
1080+
page.waitForEvent("response", { predicate: (res) => res.url().includes("/api"), timeout: 10000 });
1081+
10571082
// @ts-expect-error
10581083
page.waitForSelector();
10591084
// $ExpectType Promise<ElementHandle>
@@ -1434,6 +1459,19 @@ async function test() {
14341459
// $ExpectType Promise<void>
14351460
locator.setChecked(true, { position: { x: 0, y: 0 } });
14361461

1462+
// @ts-expect-error
1463+
locator.pressSequentially();
1464+
// @ts-expect-error
1465+
locator.pressSequentially({ timeout: 10000 });
1466+
// $ExpectType Promise<void>
1467+
locator.pressSequentially("text");
1468+
// $ExpectType Promise<void>
1469+
locator.pressSequentially("text", { delay: 100 });
1470+
// $ExpectType Promise<void>
1471+
locator.pressSequentially("text", { noWaitAfter: true });
1472+
// $ExpectType Promise<void>
1473+
locator.pressSequentially("text", { timeout: 10000 });
1474+
14371475
// @ts-expect-error
14381476
locator.type();
14391477
// @ts-expect-error

0 commit comments

Comments
 (0)