You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like screenshot matchers to be re-executed until the screenshot matches.
Right now, one screenshot is taken and if it does not match, the test fails.
It may take a while until the browser/element is in the state where I want to take the screenshot.
It is not always useful/possible to wait for other factors that may indicate the page is in the desired state (i.e. existence of a css-class).
I'd like toMatchElementSnapshot and the others to be re-executed (within a configurable timeout) until the screenshot matches.
Prototype
I prototyped a solution where I locally changed toMatchElementSnapshot:
// @file ./extensions/expect_toMatchElementSnapshotSoon.tsimport{WdioCheckElementMethodOptions}from'@wdio/visual-service/dist/types';import{toMatchElementSnapshot}from'@wdio/visual-service/dist/matcher';// not possibleexportasyncfunctiontoMatchElementSnapshotSoon(element: WebdriverIO.Element,tag: string,expectedResultOrOptions?: number|ExpectWebdriverIO.PartialMatcher,optionsOrUndefined?: WdioCheckElementMethodOptions){letcompared;awaitelement.waitUntil(async()=>{compared=awaittoMatchElementSnapshot(element,tag,expectedResultOrOptions,optionsOrUndefined);returncompared.pass;});returncompared;}
But when I want to run the tests, @wdio/config:ConfigParser fails:
2024-12-17T08:52:30.261Z ERROR @wdio/config:ConfigParser: Failed loading configuration file: file:///C:/dev/wdio-visual/mocha-wdio.conf.ts: Package subpath './dist/matcher' is not defined by "exports" in C:\dev\wm-gti-uts\wdio\node_modules\@wdio\visual-service\package.json imported from C:\dev\wm-gti-uts\wdio\extensions\expect_toMatchElementSnapshotSoon.ts
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/matcher' is not defined by "exports" in C:\dev\wm-gti-uts\wdio\node_modules\@wdio\visual-service\package.json imported from C:\dev\wm-gti-uts\wdio\extensions\expect_toMatchElementSnapshotSoon.ts
at exportsNotFound (node:internal/modules/esm/resolve:304:10)
at packageExportsResolve (node:internal/modules/esm/resolve:651:9)
at packageResolve (node:internal/modules/esm/resolve:837:14)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1169:11)
at nextResolve (node:internal/modules/esm/hooks:866:28)
at resolveBase (file:///C:/dev/wdio-visual/node_modules/tsx/dist/esm/index.mjs?1734425546202:2:3212)
at resolveDirectory (file:///C:/dev/wdio-visual/node_modules/tsx/dist/esm/index.mjs?1734425546202:2:3584)
at resolveTsPaths (file:///C:/dev/wdio-visual/node_modules/tsx/dist/esm/index.mjs?1734425546202:2:4073)
at resolve (file:///C:/dev/wdio-visual/node_modules/tsx/dist/esm/index.mjs?1734425546202:2:4447) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
btw. before() seems not to be awaited. I initially tried the dynamic import, but neither the code in the module, nor the code
after the await is executed.
Implementation
I came to the conclusion that this feature needs to be added to @wdio/visual-service.
The wait/timeout and interval should be the same as for the matchers in expect-webdriverio.
It also should be possible to override these per call to toMatchElementSnapshot() etc.
Baseline screenshots should be taken when the test times out - if the page is not in the desired state at that point, the test will fail in the future anyway.
IMO toMatchElementSnapshot and the others can safely be changed to retry the match. I can not think of cases where tests would start to fail or to have false-positives.
The text was updated successfully, but these errors were encountered:
Proposal
I'd like screenshot matchers to be re-executed until the screenshot matches.
Right now, one screenshot is taken and if it does not match, the test fails.
It may take a while until the browser/element is in the state where I want to take the screenshot.
It is not always useful/possible to wait for other factors that may indicate the page is in the desired state (i.e. existence of a css-class).
I'd like
toMatchElementSnapshot
and the others to be re-executed (within a configurable timeout) until the screenshot matches.Prototype
I prototyped a solution where I locally changed
toMatchElementSnapshot
:This has the desired results.
Custom-Matcher (not possible)
I tried to write a custom matcher:
But when I want to run the tests,
@wdio/config:ConfigParser
fails:This is how I setup the custom matcher
btw.
before()
seems not to be awaited. I initially tried the dynamic import, but neither the code in the module, nor the codeafter the
await
is executed.Implementation
I came to the conclusion that this feature needs to be added to
@wdio/visual-service
.The
wait
/timeout
andinterval
should be the same as for the matchers inexpect-webdriverio
.It also should be possible to override these per call to
toMatchElementSnapshot()
etc.Baseline screenshots should be taken when the test times out - if the page is not in the desired state at that point, the test will fail in the future anyway.
IMO
toMatchElementSnapshot
and the others can safely be changed to retry the match. I can not think of cases where tests would start to fail or to have false-positives.The text was updated successfully, but these errors were encountered: