webdriverio / visual-testing

Image comparison / visual regression testing for WebdriverIO
https://webdriver.io/docs/visual-testing
MIT License
110 stars 41 forks source link

Code sample how can we takeScreenshot on failed tests #54

Closed sytolk closed 3 years ago

sytolk commented 3 years ago

https://github.com/wswebcreation/wdio-image-comparison-service/issues/50#issuecomment-762427915

wswebcreation commented 3 years ago

Hi @sytolk

Thanks for filing an issue, can you please explain what you need from this module. Looking at your title I would say there is no link with this module but something related to how you implement this in WebdriverIO itself and thus a WDIO question.

sytolk commented 3 years ago

Hi @wswebcreation To take screenshot I have use browser.saveFullPageScreen from image-comparison-service like this: https://github.com/tagspaces/tagspaces/blob/develop/tests/e2e/hook.js#L180

but the right place to take screenshot is in WDIO afterTest hook. The problem is that I cannot set here in WDIO options this hook (it is ignored... maybe it work only from wdio.conf.js): https://github.com/tagspaces/tagspaces/blob/develop/tests/e2e/hook.js#L112

image-comparison-service have great example to running programmatically this miss me for WDIO (specially hooks). And I think that this hook: afterTest(() => browser.saveFullPageScreen()) can be handled internally from image-comparison-service in programming-configuration?

The question is: can we set a WDIO hook option from this service ?

wswebcreation commented 3 years ago

Hi @sytolk

Ok, I now understand. The afterTest hook in this service should behave the same as the afterTest hook in WDIO-config. If it's not working from the config then something else in your code might be wrong. For now I'm not planning in adding an extra hook to create screenshots on error that's why I'm closing this issue. It's still open for further discussion

sytolk commented 3 years ago

Thanks for the answer @wswebcreation but I'm not expecting that image-comparison-service will support screenshots on error (source code changes). I want to extend running-programmatically example usage i README.md only.

"The afterTest hook in this service should behave the same as the afterTest hook in WDIO-config."

Ok this means that we can add WDIO hooks in programing-configuration example? The main goal is to skip WDIO-config usage and run WDIO progammatically.

zbyte64 commented 1 year ago

If you want to run this service programmatically then call these commands directly: https://github.com/wswebcreation/webdriver-image-comparison/blob/main/lib/commands/saveElement.ts