Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#68294 Release v0.49.0 changes by @mstoykov
Browse files Browse the repository at this point in the history
* Remove timeout options for isVisible

The timeout options are now no-ops since the k6 browser module doesn't
wait for an element to appear on the page before seeing whether it is
visible or not. If the element is not on the page it is assumed to not
be visible.

* Remove timeout options for isHidden

The timeout options are now no-ops since the k6 browser module doesn't
wait for an element to appear on the page before seeing whether it is
hidden or not. If the element is not on the page, it is assumed to be
hidden.

* Add new clear method to locator class in k6

This adds the new clear method to the locator class which is part of a
change in the browser module in k6.

* Remove confusing text on locator.clear

* Remove strict option from locator API

This remove the strict option from the locator type definitions in the
k6 browser module. The strict option is ignored when working with the
locator API.

* k6: experimental gRPC module graduation

* Bump k6 version to v0.49.0

---------

Co-authored-by: ankur22 <ankur.agarwal@grafana.com>
Co-authored-by: Oleg Bespalov <oleg.bespalov@grafana.com>
  • Loading branch information
3 people authored Jan 29, 2024
1 parent 4bd458d commit 07afa65
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 121 deletions.
108 changes: 41 additions & 67 deletions types/k6/experimental/browser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,15 +1469,15 @@ export interface Frame {
* @param options The options to use.
* @returns `true` if the element is hidden, `false` otherwise.
*/
isHidden(selector: string, options?: TimeoutOptions & StrictnessOptions): boolean;
isHidden(selector: string, options?: StrictnessOptions): boolean;

/**
* Get whether the first element found that matches the selector is visible or not.
* @param selector The selector to use.
* @param options The options to use.
* @returns `true` if the element is visible, `false` otherwise.
*/
isVisible(selector: string, options?: TimeoutOptions & StrictnessOptions): boolean;
isVisible(selector: string, options?: StrictnessOptions): boolean;

/**
* Wait for the given function to return a truthy value.
Expand Down Expand Up @@ -1624,37 +1624,51 @@ export interface Keyboard {
* React, Vue, etc.
*/
export interface Locator {
/**
* Clears text boxes and input fields of any existing values.
*
* **Usage**
*
* ```js
* // Clears the input field matching the selector.
* page.locator('input[name="login"]').clear();
* ```
*
* @param options Options to use.
*/
clear(options?: ElementHandleOptions): void;

/**
* Mouse click on the chosen element.
* @param options Options to use.
* @returns Promise which resolves when the element is successfully clicked.
*/
click(options?: MouseMoveOptions & MouseMultiClickOptions & StrictnessOptions): Promise<void>;
click(options?: MouseMoveOptions & MouseMultiClickOptions): Promise<void>;

/**
* Mouse double click on the chosen element.
* @param options Options to use.
*/
dblclick(options?: MouseMoveOptions & MouseMultiClickOptions & StrictnessOptions): void;
dblclick(options?: MouseMoveOptions & MouseMultiClickOptions): void;

/**
* Use this method to select an `input type="checkbox"`.
* @param options Options to use.
*/
check(options?: ElementClickOptions & StrictnessOptions): void;
check(options?: ElementClickOptions): void;

/**
* Use this method to unselect an `input type="checkbox"`.
* @param options Options to use.
*/
uncheck(options?: ElementClickOptions & StrictnessOptions): void;
uncheck(options?: ElementClickOptions): void;

/**
* Checks to see if the `input type="checkbox"` is selected or not.
* @param options Options to use.
* @returns `true` if the element is checked, `false` otherwise.
*/
isChecked(options?: TimeoutOptions & StrictnessOptions): boolean;
isChecked(options?: TimeoutOptions): boolean;

/**
* Checks if the element is editable.
Expand All @@ -1668,77 +1682,75 @@ export interface Locator {
* @param options Options to use.
* @returns `true` if the element is enabled, `false` otherwise.
*/
isEnabled(options?: TimeoutOptions & StrictnessOptions): boolean;
isEnabled(options?: TimeoutOptions): boolean;

/**
* Checks if the element is `disabled`.
* @param options Options to use.
* @returns `true` if the element is disabled, `false` otherwise.
*/
isDisabled(options?: TimeoutOptions & StrictnessOptions): boolean;
isDisabled(options?: TimeoutOptions): boolean;

/**
* Checks if the element is `visible`.
* @param options Options to use.
* @returns `true` if the element is visible, `false` otherwise.
*/
isVisible(options?: TimeoutOptions & StrictnessOptions): boolean;
isVisible(): boolean;

/**
* Checks if the element is `hidden`.
* @param options Options to use.
* @returns `true` if the element is hidden, `false` otherwise.
*/
isHidden(options?: TimeoutOptions & StrictnessOptions): boolean;
isHidden(): boolean;

/**
* Fill an `input`, `textarea` or `contenteditable` element with the provided value.
* @param value Value to fill for the `input` or `textarea` element.
* @param options Options to use.
*/
fill(value: string, options?: ElementHandleOptions & StrictnessOptions): void;
fill(value: string, options?: ElementHandleOptions): void;

/**
* Focuses the element using locator's selector.
* @param options Options to use.
*/
focus(options?: TimeoutOptions & StrictnessOptions): void;
focus(options?: TimeoutOptions): void;

/**
* Returns the element attribute value for the given attribute name.
* @param name Attribute name to retrieve value for.
* @param options Options to use.
* @returns Attribute value.
*/
getAttribute(name: string, options?: TimeoutOptions & StrictnessOptions): string | null;
getAttribute(name: string, options?: TimeoutOptions): string | null;

/**
* Returns the `element.innerHTML`.
* @param options Options to use.
* @returns Element's innerHTML.
*/
innerHTML(options?: TimeoutOptions & StrictnessOptions): string;
innerHTML(options?: TimeoutOptions): string;

/**
* Returns the `element.innerText`.
* @param options Options to use.
* @returns Element's innerText.
*/
innerText(options?: TimeoutOptions & StrictnessOptions): string;
innerText(options?: TimeoutOptions): string;

/**
* Returns the `element.textContent`.
* @param options Options to use.
* @returns Element's textContent.
*/
textContent(options?: TimeoutOptions & StrictnessOptions): string;
textContent(options?: TimeoutOptions): string;

/**
* Returns `input.value` for the selected `input`, `textarea` or `select` element.
* @param options Options to use.
* @returns The input value of the element.
*/
inputValue(options?: TimeoutOptions & StrictnessOptions): string;
inputValue(options?: TimeoutOptions): string;

/**
* Select one or more options which match the values. If the select has the multiple attribute, all matching options are selected,
Expand All @@ -1749,7 +1761,7 @@ export interface Locator {
*/
selectOption(
values: string | string[] | { value?: string; label?: string; index?: number },
options?: ElementHandleOptions & StrictnessOptions,
options?: ElementHandleOptions,
): string[];

/**
Expand All @@ -1771,27 +1783,27 @@ export interface Locator {
* Hover over the element.
* @param options Options to use.
*/
hover(options?: MouseMoveOptions & StrictnessOptions): void;
hover(options?: MouseMoveOptions): void;

/**
* Tap on the chosen element.
* @param options Options to use.
*/
tap(options?: MouseMoveOptions & StrictnessOptions): void;
tap(options?: MouseMoveOptions): void;

/**
* Dispatches HTML DOM event types e.g. `click`.
* @param type DOM event type.
* @param eventInit Event-specific properties.
* @param options Options to use.
*/
dispatchEvent(type: string, eventInit?: EvaluationArgument, options?: TimeoutOptions & StrictnessOptions): void;
dispatchEvent(type: string, eventInit?: EvaluationArgument, options?: TimeoutOptions): void;

/**
* Wait for the element to be in a particular state e.g. `visible`.
* @param options Wait options.
*/
waitFor(options?: { state?: ElementState } & TimeoutOptions & StrictnessOptions): void;
waitFor(options?: { state?: ElementState } & TimeoutOptions): void;
}

/**
Expand Down Expand Up @@ -2581,64 +2593,26 @@ export interface Page {
): boolean;

/**
* **NOTE** Use locator-based locator.isHidden([options]) instead.
* **NOTE** Use locator-based locator.isHidden() instead.
*
* Returns whether the element is hidden.
*
* @param selector A selector to search for an element. If there are multiple
* elements satisfying the selector, the first will be used.
* @param options
*/
isHidden(
selector: string,
options?: {
/**
* When `true`, the call requires selector to resolve to a single element.
* If given selector resolves to more than one element, the call throws
* an exception. Defaults to `false`.
*/
strict?: boolean;

/**
* Maximum time in milliseconds. Defaults to `30` seconds. Default is
* overridden by the `setDefaultTimeout` option on `BrowserContext` or
* `page` methods.
*
* Setting the value to `0` will disable the timeout.
*/
timeout?: number;
},
): boolean;
isHidden(selector: string, options?: StrictnessOptions): boolean;

/**
* **NOTE** Use locator-based locator.isVisible([options]) instead.
* **NOTE** Use locator-based locator.isVisible() instead.
*
* Returns whether the element is visible.
*
* @param selector A selector to search for an element. If there are multiple
* elements satisfying the selector, the first will be used.
* @param options
*/
isVisible(
selector: string,
options?: {
/**
* When `true`, the call requires selector to resolve to a single element.
* If given selector resolves to more than one element, the call throws
* an exception. Defaults to `false`.
*/
strict?: boolean;

/**
* Maximum time in milliseconds. Defaults to `30` seconds. Default is
* overridden by the `setDefaultTimeout` option on `BrowserContext` or
* `page` methods.
*
* Setting the value to `0` will disable the timeout.
*/
timeout?: number;
},
): boolean;
isVisible(selector: string, options?: StrictnessOptions): boolean;

/**
* Returns the keyboard instance to interact with a virtual keyboard on the
Expand Down
6 changes: 6 additions & 0 deletions types/k6/experimental/grpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ export interface GrpcError {
/**
* This module provides classes for Remote Procedure Calls over HTTP/2.
* https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/grpc/
*
* @deprecated Use the `k6/net/grpc` module instead.
*/
declare namespace grpc {
/**
* gRPC client to interact with a gRPC server.
* https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/grpc/client/
*
* @deprecated Use the `k6/net/grpc` module instead.
*/
class Client {
protected __brand: never;
Expand Down Expand Up @@ -145,6 +149,8 @@ declare namespace grpc {

/**
* Stream allows you to use streaming RPCs.
*
* @deprecated Use the `k6/net/grpc` module instead.
*/
class Stream {
/**
Expand Down
58 changes: 58 additions & 0 deletions types/k6/net/grpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export interface Params {
timeout?: string | number;
}

export interface GrpcError {
code: number;
details: string[] | object[];
message: string;
}

/**
* This module provides a gRPC client for Remote Procedure Calls over HTTP/2.
* https://grafana.com/docs/k6/latest/javascript-api/k6-net-grpc/
Expand Down Expand Up @@ -119,6 +125,58 @@ declare namespace grpc {
close(): void;
}

/**
* StreamEvent describes the possible events that can be emitted
* by a gRPC stream.
*/
type StreamEvent =
/**
* Event fired when data has been received from the server.
*/
| "data"
/**
* Event fired when a stream has been closed due to an error.
*/
| "error"
/**
* Event fired when the stream closes.
*/
| "end";

/**
* Stream allows you to use streaming RPCs.
*/
class Stream {
/**
* The gRPC stream constructor, representing a single gRPC stream.
*
* @param client - the gRPC client to use, it must be connected.
* @param url - the RPC method to call.
* @param params - the parameters to use for the RPC call.
*/
constructor(client: Client, url: string, params?: Params);

/**
* Set up handler functions for various events on the gRPC stream.
*
* @param event - the event to listen for
* @param listener - the callback to invoke when the event is emitted
*/
on(event: StreamEvent, listener: (data: object | GrpcError | undefined) => void): void;

/**
* Writes a request to the stream.
*
* @param request - the request (message) to send to the server
*/
write(request: object): void;

/**
* Signals to the server that the client has finished sending messages.
*/
end(): void;
}

const StatusOK: number;
const StatusCanceled: number;
const StatusUnknown: number;
Expand Down
2 changes: 1 addition & 1 deletion types/k6/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/k6",
"version": "0.48.9999",
"version": "0.49.9999",
"projects": [
"https://grafana.com/docs/k6/latest/"
],
Expand Down
Loading

0 comments on commit 07afa65

Please sign in to comment.