Skip to content

Commit

Permalink
Merge pull request #21 from gemini-testing/TESTPLANE-71.autoscreensho…
Browse files Browse the repository at this point in the history
…tSelector

feat: add ability to specify autoscreenshotSelector in story-files
  • Loading branch information
KuznetsovRoman authored Jun 7, 2024
2 parents 4cc828d + cedfd90 commit 1306694
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const meta: WithTestplane<Meta<typeof Button>> = {
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
Expand Down
1 change: 1 addition & 0 deletions src/storybook/story-test-runner/extend-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/storybook/story-test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/storybook/story-test-runner/open-story/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
1 change: 1 addition & 0 deletions src/storybook/story-test-runner/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface StorybookStoryExtended extends StorybookStory {
assertViewOpts: AssertViewOpts;
browserIds: Array<string | RegExp> | null;
extraTests?: Record<string, TestplaneTestFunction>;
autoscreenshotSelector: string | null;
}

export type ExecutionContextExtended = WebdriverIO.Browser["executionContext"] & {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type TestplaneMetaConfig<T = void> = Combined<
skip?: boolean;
assertViewOpts?: AssertViewOpts;
browserIds?: Array<string | RegExp>;
autoscreenshotSelector?: string;
}>,
T
>;
Expand Down

0 comments on commit 1306694

Please sign in to comment.