Skip to content

Error: Snapshot service is not initialized #1943

@trymeouteh

Description

@trymeouteh

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions