webdriverio / webdriverio/expect-webdriverio

Error: Snapshot service is not initialized

Open
#1,943 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
86
Forks
61
Avg merge
19h 12m
Merged PRs (30d)
15

Description

How does one import the snapshot service from the expect-webdriverio package into your test? I tried the following and I still get the following error in the terminal. Am I doing this wrong or is the snapshot service broken?

$node test
file:///home/john/Desktop/webdriverio/node_modules/expect-webdriverio/lib/matchers/snapshot.js:53
        throw new Error('Snapshot service is not initialized');
              ^

Error: Snapshot service is not initialized
    at toMatchSnapshotHelper (file:///home/john/Desktop/webdriverio/node_modules/expect-webdriverio/lib/matchers/snapshot.js:53:15)
    at Object.toMatchSnapshot (file:///home/john/Desktop/webdriverio/node_modules/expect-webdriverio/lib/matchers/snapshot.js:63:12)
    at __EXTERNAL_MATCHER_TRAP__ (/home/john/Desktop/webdriverio/node_modules/expect/build/index.js:2240:22)
    at Object.throwingMatcher [as toMatchSnapshot] (/home/john/Desktop/webdriverio/node_modules/expect/build/index.js:2241:6)
    at file:///home/john/Desktop/webdriverio/test.js:16:39
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v22.12.0

test.js

import { remote } from 'webdriverio';
import { expect, SnapshotService } from 'expect-webdriverio';

const browser = await remote({
	capabilities: {
		browserName: 'firefox',
	},
	services: [SnapshotService],
});

const filePath = 'file:///' + import.meta.dirname + '/test.html';

await browser.url(filePath);

await expect(browser.$('#my-button')).toMatchSnapshot();

await browser.deleteSession();

test.html

<button id="my-button">My Button</button>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the test.js reproduction and inspect expect-webdriverio/lib/matchers/snapshot.js at the SnapshotService initialization check. Trace how services: [SnapshotService] is registered with webdriverio, then run the example to determine why toMatchSnapshot cannot access the service. Done means the provided test can capture the button snapshot without throwing the initialization error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.