Skip to content

Commit 0588a5f

Browse files
polish(webdriverio): expose contentVisibilityAuto, opacityProperty and visibilityProperty to waitForDisplayed (#14659)
* polish(webdriverio): expose contentVisibilityAuto, opacityProperty and visibilityProperty to waitForDisplayed * polish(webdriverio): expose contentVisibilityAuto, opacityProperty and visibilityProperty to waitForDisplayed * polish(webdriverio): expose contentVisibilityAuto, opacityProperty and visibilityProperty to waitForDisplayed
1 parent fc1d857 commit 0588a5f

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

packages/webdriverio/src/commands/element/waitForDisplayed.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
import type { WaitForOptions } from '../../types.js'
22

3+
interface WaitForDisplayedParams extends WaitForOptions {
4+
/**
5+
* `true` to check if the element is within the viewport. false by default.
6+
*/
7+
withinViewport?: boolean
8+
/**
9+
* `true` to check if the element content-visibility property has (or inherits) the value auto,
10+
* and it is currently skipping its rendering. `true` by default.
11+
* @default true
12+
*/
13+
contentVisibilityAuto?: boolean
14+
/**
15+
* `true` to check if the element opacity property has (or inherits) a value of 0. `true` by default.
16+
* @default true
17+
*/
18+
opacityProperty?: boolean
19+
/**
20+
* `true` to check if the element is invisible due to the value of its visibility property. `true` by default.
21+
* @default true
22+
*/
23+
visibilityProperty?: boolean
24+
}
25+
326
/**
427
*
528
* Wait for an element for the provided amount of milliseconds to be displayed or not displayed.
@@ -18,6 +41,9 @@ import type { WaitForOptions } from '../../types.js'
1841
* @param {String=} options.timeoutMsg if exists it overrides the default error message
1942
* @param {Number=} options.interval interval between checks (default: `waitforInterval`)
2043
* @param {Boolean=} options.withinViewport set to `true` to wait until element is displayed within viewport (default: `false`)
44+
* @param {Boolean=} options.contentVisibilityAuto set to `true` to check if the element content-visibility property has (or inherits) the value auto, and it is currently skipping its rendering. `true` by default.
45+
* @param {Boolean=} options.opacityProperty set to `true` to check if the element opacity property has (or inherits) a value of 0. `true` by default.
46+
* @param {Boolean=} options.visibilityProperty set to `true` to check if the element is invisible due to the value of its visibility property. `true` by default.
2147
* @return {Boolean} true if element is displayed (or doesn't if flag is set)
2248
* @uses utility/waitUntil, state/isDisplayed
2349
* @example https://github.com/webdriverio/example-recipes/blob/0bfb2b8d212b627a2659b10f4449184b657e1d59/waitForDisplayed/index.html#L3-L8
@@ -31,11 +57,15 @@ export function waitForDisplayed (
3157
interval = this.options.waitforInterval,
3258
reverse = false,
3359
withinViewport = false,
60+
contentVisibilityAuto = true,
61+
opacityProperty = true,
62+
visibilityProperty = true,
3463
timeoutMsg = `element ("${this.selector}") still ${reverse ? '' : 'not '}displayed${withinViewport ? ' within viewport' : ''} after ${timeout}ms`,
35-
}: WaitForOptions = {}
64+
}: WaitForDisplayedParams = {}
3665
) {
66+
3767
return this.waitUntil(
38-
async () => reverse !== await this.isDisplayed({ withinViewport }),
68+
async () => reverse !== await this.isDisplayed({ withinViewport, contentVisibilityAuto, opacityProperty, visibilityProperty }),
3969
{ timeout, interval, timeoutMsg }
4070
)
4171
}

packages/webdriverio/tests/commands/element/waitForDisplayed.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('waitForDisplayed', () => {
9090
expect(err.message).toBe(`element ("#foo") still not displayed within viewport after ${timeout}ms`)
9191
}
9292

93-
expect(elem.isDisplayed).toBeCalledWith({ withinViewport: true })
93+
expect(elem.isDisplayed).toBeCalledWith({ withinViewport: true, contentVisibilityAuto: true, opacityProperty: true, visibilityProperty: true })
9494
})
9595

9696
it('should not call isDisplayed and return false if never found', async () => {

0 commit comments

Comments
 (0)