From cedfd904cb3e105d4cfa361a1505da7ed83ba343 Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Fri, 7 Jun 2024 01:16:35 +0300 Subject: [PATCH] feat: add ability to specify autoscreenshotSelector in story-files --- README.md | 1 + src/storybook/story-test-runner/extend-stories.ts | 1 + src/storybook/story-test-runner/index.ts | 2 +- src/storybook/story-test-runner/open-story/index.ts | 2 +- src/storybook/story-test-runner/types.ts | 1 + src/types.ts | 1 + 6 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ffb620..24f692f 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ const meta: WithTestplane> = { component: Button, testplane: { skip: false, // if true, skips all Testplane tests from this story file + autoscreenshotSelector: ".my-selector", // Custom selector to auto-screenshot elements browserIds: ["chrome"], // Testplane browsers to run tests from this story file assertViewOpts: { // override default assertView options for tests from this file ignoreDiffPixelCount: 5 diff --git a/src/storybook/story-test-runner/extend-stories.ts b/src/storybook/story-test-runner/extend-stories.ts index 98f1887..6bc66c1 100644 --- a/src/storybook/story-test-runner/extend-stories.ts +++ b/src/storybook/story-test-runner/extend-stories.ts @@ -44,6 +44,7 @@ export function extendStoriesFromStoryFile(stories: StorybookStory[]): Storybook story.skip = testplaneStoryOpts.skip || false; story.assertViewOpts = testplaneStoryOpts.assertViewOpts || {}; story.browserIds = testplaneStoryOpts.browserIds || null; + story.autoscreenshotSelector = testplaneStoryOpts.autoscreenshotSelector || null; }); continue; diff --git a/src/storybook/story-test-runner/index.ts b/src/storybook/story-test-runner/index.ts index acab718..5298423 100644 --- a/src/storybook/story-test-runner/index.ts +++ b/src/storybook/story-test-runner/index.ts @@ -24,7 +24,7 @@ function createTestplaneTests(story: StorybookStoryExtended, { autoScreenshots } const result = await openStoryStep(ctx.browser, story); - await autoScreenshotStep(ctx.browser, result.rootSelector); + await autoScreenshotStep(ctx.browser, story.autoscreenshotSelector || result.rootSelector); }); } diff --git a/src/storybook/story-test-runner/open-story/index.ts b/src/storybook/story-test-runner/open-story/index.ts index dc16a7b..147af40 100644 --- a/src/storybook/story-test-runner/open-story/index.ts +++ b/src/storybook/story-test-runner/open-story/index.ts @@ -34,7 +34,7 @@ export async function openStory(browser: WebdriverIO.Browser, story: StorybookSt throw new PlayFunctionError(storyLoadResult.playFunctionError); } - if (!storyLoadResult.rootSelector) { + if (!story.autoscreenshotSelector && !storyLoadResult.rootSelector) { throw new Error("Story root selector is not found"); } diff --git a/src/storybook/story-test-runner/types.ts b/src/storybook/story-test-runner/types.ts index 0ddcd7b..f4ce3c0 100644 --- a/src/storybook/story-test-runner/types.ts +++ b/src/storybook/story-test-runner/types.ts @@ -7,6 +7,7 @@ export interface StorybookStoryExtended extends StorybookStory { assertViewOpts: AssertViewOpts; browserIds: Array | null; extraTests?: Record; + autoscreenshotSelector: string | null; } export type ExecutionContextExtended = WebdriverIO.Browser["executionContext"] & { diff --git a/src/types.ts b/src/types.ts index 051e843..7df3030 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,6 +22,7 @@ export type TestplaneMetaConfig = Combined< skip?: boolean; assertViewOpts?: AssertViewOpts; browserIds?: Array; + autoscreenshotSelector?: string; }>, T >;