diff --git a/README.md b/README.md index a71cc090..00c9ad3e 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,8 @@ const chromeless = new Chromeless({ - [`click(selector: string)`](docs/api.md#api-click) - [`wait(timeout: number)`](docs/api.md#api-wait-timeout) - [`wait(selector: string)`](docs/api.md#api-wait-selector) -- [`wait(fn: (...args: any[]) => boolean, ...args: any[])`] - Not implemented yet +- [`wait(selectors: string[])`](docs/api.md#api-wait-selectors) +- [`wait(fn: (...args: any[]) => boolean, ...args: any[])`](docs/api.md#api-wait-function) - [`clearCache()`](docs/api.md#api-clearcache) - [`focus(selector: string)`](docs/api.md#api-focus) - [`press(keyCode: number, count?: number, modifiers?: any)`](docs/api.md#api-press) diff --git a/docs/api.md b/docs/api.md index 31c00ba0..f6604f94 100644 --- a/docs/api.md +++ b/docs/api.md @@ -24,7 +24,8 @@ Chromeless provides TypeScript typings. - [`click(selector: string)`](#api-click) - [`wait(timeout: number)`](#api-wait-timeout) - [`wait(selector: string, timeout?: number)`](#api-wait-selector) -- [`wait(fn: (...args: any[]) => boolean, ...args: any[])`] - Not implemented yet +- [`wait(selectors: string[], timeout?: number)`](#api-wait-selectors) +- [`wait(fn: (...args: any[]) => boolean, ...args: any[])`](#api-wait-function) - [`clearCache()`](docs/api.md#api-clearcache) - [`focus(selector: string)`](#api-focus) - [`press(keyCode: number, count?: number, modifiers?: any)`](#api-press) @@ -157,13 +158,30 @@ await chromeless.wait('div#loaded', 1000) --------------------------------------- - + -### wait(fn: (...args: any[]) => boolean, ...args: any[]): Chromeless +### wait(selectors: string[], timeout?: number): Chromeless -Not implemented yet +Wait until one of the elements appears. + +__Arguments__ +- `selectors` - Array of DOM selectors to wait for +- `timeout` - How long to wait for any of the element to appear (default is value of waitTimeout option) + +__Example__ + +```js +await chromeless.wait(['div#error', 'div#success']) +await chromeless.wait(['div#error', 'div#success'], 1000) +``` + +--------------------------------------- + + + +### wait(fn: (...args: any[]) => boolean, ...args: any[]): Chromeless -Wait until a function returns. +Wait until a function returns truthy value. Note that the function is run in headless browser. __Arguments__ - `fn` - Function to wait for @@ -172,7 +190,9 @@ __Arguments__ __Example__ ```js -await chromeless.wait(() => { return console.log('@TODO: put a better example here') }) +await chromeless.wait((divId) => { + return !!document.getElementById(divId) +}, 'div#loaded') ``` --------------------------------------- diff --git a/src/__tests__/test.html b/src/__tests__/test.html index c4075a23..61ecfe1a 100644 --- a/src/__tests__/test.html +++ b/src/__tests__/test.html @@ -3,6 +3,7 @@ Title + @@ -10,6 +11,17 @@ This is a test page for Chromeless unit tests + Click me! + + -
This is a test page for Chromeless unit tests