Skip to content

Commit

Permalink
Add test_driver.bidi.log.entry_added doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Nov 7, 2024
1 parent 0d4f507 commit a721d08
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
40 changes: 40 additions & 0 deletions docs/writing-tests/testdriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,43 @@ Note that if an action uses an element reference, the context will be
derived from that element, and must match any explicitly set
context. Using elements in multiple contexts in a single action chain
is not supported.


### BiDi ###

Represents [WebDriver BiDi](https://w3c.github.io/webdriver-bidi>) protocol.

<!-- sphinx-js doesn't support documenting types so we have to copy in the Context
documentation by hand -->

```eval_rst
:Context: (*String|Window*) Represents a browsing context either with the browsing
context id equals to the given string value, or one with the given Window
object.
```


#### Log ####

Represents WebDriver BiDi [Log](https://w3c.github.io/webdriver-bidi/#module-log)
module.


##### Entry added #####

Allows subscribing and listening to the
[`log.entryAdded`](https://w3c.github.io/webdriver-bidi/#event-log-entryAdded) event.

Example:
```javascript
await test_driver.bidi.log.entry_added.subscribe();
const log_entry_promise = test_driver.bidi.log.entry_added.once();
console.log("some message");
const event = await log_entry_promise;
```

```eval_rst
.. js:autofunction:: test_driver.bidi.log.entry_added.subscribe
.. js:autofunction:: test_driver.bidi.log.entry_added.on
.. js:autofunction:: test_driver.bidi.log.entry_added.once
```
49 changes: 32 additions & 17 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
Represents `WebDriver BiDi <https://w3c.github.io/webdriver-bidi>`_ protocol.
*/
bidi: {
/**
* @typedef {(String|Window)} Context Represents a browsing context
* either with the browsing context id equals to the given string
* value, or one with the given Window object.
*/

/**
* `log <https://w3c.github.io/webdriver-bidi/#module-log>`_ module.
*/
Expand All @@ -62,32 +68,41 @@
*/
entry_added: {
/**
* Subscribe to the `log.entryAdded` event. This does not
* add actual listeners. To listen to the event, use the
* `on` or `once` methods.
* @param {{contexts?: null | (string | Window)[]}} params - Parameters for the subscription.
* * `contexts`: an array of window proxies or browsing
* context ids to listen to the event. If not provided, the
* event subscription is done for the current window's
* browsing context. `null` for the global subscription.
* @return {Promise<void>}
* Subscribes to the event. The events will be emitted only
* if `subscribe` is called.
*
* This method does not add actual listeners. To listen to
* the event, use the `on` or `once` methods.
*
* @param {object} [params] Parameters for the subscription.
* @param {null|Array.<(Context)>} [params.contexts] An array of
* window proxies or browsing context IDs to listen to the event on.
* If provided `null`, the subscription will be set on all
* the browsing contexts.
* @returns {Promise<void>} Resolves when the subscription is successful.
*/
subscribe: async function (params = {}) {
return window.test_driver_internal.bidi.log.entry_added.subscribe(params);
},
/**
* Add an event listener for the `log.entryAdded
* <https://w3c.github.io/webdriver-bidi/#event-log-entryAdded>`_ event. Make sure `subscribe` is
* called before using this method.
*
* @param callback {function(event): void} - The callback
* to be called when the event is fired.
* @returns {function(): void} - A function to call to
* remove the event listener.
* Add an event listener for the event.
* @param callback {function(event): void} The callback
* to be called when the event is emitted. The callback is
* called with the event object as a parameter.
* @returns {function(): void} A function for removing the
* listener.
*/
on: function (callback) {
return window.test_driver_internal.bidi.log.entry_added.on(callback);
},
/**
* Add an event listener for the event that is only called
* once and removed afterward.
* @param callback {function(event): void} The callback to
* be called when the event is fired.
* @return {Promise<Event>} The promise which is resolved
* with the Event object when the event is emitted.
*/
once: function () {
return new Promise(resolve => {
const remove_handler = window.test_driver_internal.bidi.log.entry_added.on(
Expand Down

0 comments on commit a721d08

Please sign in to comment.