Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use test name as screenshot file name? #50

Closed
alisman opened this issue Dec 14, 2020 · 4 comments
Closed

Use test name as screenshot file name? #50

alisman opened this issue Dec 14, 2020 · 4 comments
Labels
enhancement New feature or request Help with a PR wontfix This will not be worked on

Comments

@alisman
Copy link

alisman commented Dec 14, 2020

In an earlier version of WDIO (wdio-visual-regression-service), the framework could pick up the name of the test

it(THIS_THING, ()=>test)

as the name of the screenshot. This was super helpful because it allowed us to easily get from test report back to test spec with code search.

Is there any simple way to achieve this in the new service?

@wswebcreation
Copy link
Member

Hi @alisman

Thanks for your issue. This is not a rewrite of the wdio-visual-regression-service, but a completely different module. Feel free to open a PR for this

@wswebcreation wswebcreation added enhancement New feature or request Help with a PR labels Dec 15, 2020
@sytolk
Copy link

sytolk commented Jan 18, 2021

@alisman to get test name you can write

const filename = `${expect.getState().currentTestName}.png`;

but how can we use this service to get screenshot running programmatically?
this miss me:

wdioImageComparisonService.afterTest(() => takeScreenshot());

This works but screenshots is taken from the next test.. wdio its have afterTest hook that I cannot configure programmatically:

jasmine.getEnv().addReporter({
  specDone: async result => {
    if (result.status !== 'disabled') {
      if (result.status === 'failed') {
        await takeScreenshot();
      }
    }
  }
});
export async function takeScreenshot() {
  await browser.saveFullPageScreen(
      `${expect.getState().currentTestName}`,
      {
        fullPageScrollTimeout: '1500'
      }
    );
}

@stale
Copy link

stale bot commented Apr 27, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Apr 27, 2021
@stale stale bot closed this as completed May 26, 2021
@zbyte64
Copy link

zbyte64 commented Sep 8, 2023

Here's how I did it without rewriting all my tests to invoke such an awkward pattern.

In your wdio.conf.js:

const {default: WdioImageComparisonService} = require('wdio-image-comparison-service');

export.config = {
  // your wdio config
  // add a mocha hook to reregister the browser commands but with a format that includes the test name
  async beforeTest(test) {
    const testName = test.title // may want to include test.parent
    // prefix image snapshots with test name
    const imageService = new WdioImageComparisonService({
      ...imageComparisonOptions,
      formatImageName: `${testName}.{tag}`,
    })
    const capabilities = [
      {
        browserName: 'chrome'
      }
    ];
    imageService.addCommandsToBrowser(capabilities, browser)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Help with a PR wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants