---id: writing-teststitle: Writing Tests---import Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';## Testrunner Framework Support`@wdio/visual-service` is test-runner framework agnostic, which means that you can use it with all the frameworks WebdriverIO supports like:- [`Mocha`](https://webdriver.io/docs/frameworks#using-mocha)- [`Jasmine`](https://webdriver.io/docs/frameworks#using-jasmine)- [`CucumberJS`](https://webdriver.io/docs/frameworks#using-cucumber)Within your tests, you can _save_ screenshots or match the current visual state of your application under test with a baseline. For that, the service provides [custom matcher](/docs/api/expect-webdriverio#visual-matcher), as well as _check_ methods:<TabsdefaultValue="mocha"values={[{label: 'Mocha', value: 'mocha'},{label: 'Jasmine', value: 'jasmine'},{label: 'CucumberJS', value: 'cucumberjs'},]}><TabItem value="mocha">```tsdescribe('Mocha Example', () => {beforeEach(async () => {await browser.url('https://webdriver.io')})it('using visual matchers to assert against baseline', async () => {// Check screen to exactly match with baselineawait expect(browser).toMatchScreenSnapshot('partialPage')// check an element to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchScreenSnapshot('partialPage', 5)// check an element with options for `saveScreen` commandawait expect(browser).toMatchScreenSnapshot('partialPage', {/* some options */})// Check an element to exactly match with baselineawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement')// check an element to have a mismatch percentage of 5% with the baselineawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement', 5)// check an element with options for `saveElement` commandawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement', {/* some options */})// Check a full page screenshot match with baselineawait expect(browser).toMatchFullPageSnapshot('fullPage')// Check a full page screenshot to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchFullPageSnapshot('fullPage', 5)// Check a full page screenshot with options for `checkFullPageScreen` commandawait expect(browser).toMatchFullPageSnapshot('fullPage', {/* some options */})// Check a full page screenshot with all tab executionsawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable')// Check a full page screenshot to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable', 5)// Check a full page screenshot with options for `checkTabbablePage` commandawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable', {/* some options */})})it('should save some screenshots', async () => {// Save a screenawait browser.saveScreen('examplePage', {/* some options */})// Save an elementawait browser.saveElement(await $('#element-id'),'firstButtonElement',{/* some options */})// Save a full page screenshotawait browser.saveFullPageScreen('fullPage', {/* some options */})// Save a full page screenshot with all tab executionsawait browser.saveTabbablePage('save-tabbable', {/* some options, use the same options as for saveFullPageScreen */})})it('should compare successful with a baseline', async () => {// Check a screenawait expect(await browser.checkScreen('examplePage', {/* some options */})).toEqual(0)// Check an elementawait expect(await browser.checkElement(await $('#element-id'),'firstButtonElement',{/* some options */})).toEqual(0)// Check a full page screenshotawait expect(await browser.checkFullPageScreen('fullPage', {/* some options */})).toEqual(0)// Check a full page screenshot with all tab executionsawait expect(await browser.checkTabbablePage('check-tabbable', {/* some options, use the same options as for checkFullPageScreen */})).toEqual(0)})})```</TabItem><TabItem value="jasmine">```tsdescribe('Jasmine Example', () => {beforeEach(async () => {await browser.url('https://webdriver.io')})it('using visual matchers to assert against baseline', async () => {// Check screen to exactly match with baselineawait expect(browser).toMatchScreenSnapshot('partialPage')// check an element to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchScreenSnapshot('partialPage', 5)// check an element with options for `saveScreen` commandawait expect(browser).toMatchScreenSnapshot('partialPage', {/* some options */})// Check an element to exactly match with baselineawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement')// check an element to have a mismatch percentage of 5% with the baselineawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement', 5)// check an element with options for `saveElement` commandawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement', {/* some options */})// Check a full page screenshot match with baselineawait expect(browser).toMatchFullPageSnapshot('fullPage')// Check a full page screenshot to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchFullPageSnapshot('fullPage', 5)// Check a full page screenshot with options for `checkFullPageScreen` commandawait expect(browser).toMatchFullPageSnapshot('fullPage', {/* some options */})// Check a full page screenshot with all tab executionsawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable')// Check a full page screenshot to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable', 5)// Check a full page screenshot with options for `checkTabbablePage` commandawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable', {/* some options */})})it('should save some screenshots', async () => {// Save a screenawait browser.saveScreen('examplePage', {/* some options */})// Save an elementawait browser.saveElement(await $('#element-id'),'firstButtonElement',{/* some options */})// Save a full page screenshotawait browser.saveFullPageScreen('fullPage', {/* some options */})// Save a full page screenshot with all tab executionsawait browser.saveTabbablePage('save-tabbable', {/* some options, use the same options as for saveFullPageScreen */})})it('should compare successful with a baseline', async () => {// Check a screenawait expect(await browser.checkScreen('examplePage', {/* some options */})).toEqual(0)// Check an elementawait expect(await browser.checkElement(await $('#element-id'),'firstButtonElement',{/* some options */})).toEqual(0)// Check a full page screenshotawait expect(await browser.checkFullPageScreen('fullPage', {/* some options */})).toEqual(0)// Check a full page screenshot with all tab executionsawait expect(await browser.checkTabbablePage('check-tabbable', {/* some options, use the same options as for checkFullPageScreen */})).toEqual(0)})})```</TabItem><TabItem value="cucumberjs">```tsimport { When, Then } from '@wdio/cucumber-framework'When('I save some screenshots', async function () {// Save a screenawait browser.saveScreen('examplePage', {/* some options */})// Save an elementawait browser.saveElement(await $('#element-id'), 'firstButtonElement', {/* some options */})// Save a full page screenshotawait browser.saveFullPageScreen('fullPage', {/* some options */})// Save a full page screenshot with all tab executionsawait browser.saveTabbablePage('save-tabbable', {/* some options, use the same options as for saveFullPageScreen */})})Then('I should be able to match some screenshots with a baseline', async function () {// Check screen to exactly match with baselineawait expect(browser).toMatchScreenSnapshot('partialPage')// check an element to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchScreenSnapshot('partialPage', 5)// check an element with options for `saveScreen` commandawait expect(browser).toMatchScreenSnapshot('partialPage', {/* some options */})// Check an element to exactly match with baselineawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement')// check an element to have a mismatch percentage of 5% with the baselineawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement', 5)// check an element with options for `saveElement` commandawait expect($('#element-id')).toMatchElementSnapshot('firstButtonElement', {/* some options */})// Check a full page screenshot match with baselineawait expect(browser).toMatchFullPageSnapshot('fullPage')// Check a full page screenshot to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchFullPageSnapshot('fullPage', 5)// Check a full page screenshot with options for `checkFullPageScreen` commandawait expect(browser).toMatchFullPageSnapshot('fullPage', {/* some options */})// Check a full page screenshot with all tab executionsawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable')// Check a full page screenshot to have a mismatch percentage of 5% with the baselineawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable', 5)// Check a full page screenshot with options for `checkTabbablePage` commandawait expect(browser).toMatchTabbablePageSnapshot('check-tabbable', {/* some options */})})Then('I should be able to compare some screenshots with a baseline', async function () {// Check a screenawait expect(await browser.checkScreen('examplePage', {/* some options */})).toEqual(0)// Check an elementawait expect(await browser.checkElement(await $('#element-id'),'firstButtonElement',{/* some options */})).toEqual(0)// Check a full page screenshotawait expect(await browser.checkFullPageScreen('fullPage', {/* some options */})).toEqual(0)// Check a full page screenshot with all tab executionsawait expect(await browser.checkTabbablePage('check-tabbable', {/* some options, use the same options as for checkFullPageScreen */})).toEqual(0)})```</TabItem></Tabs>:::note IMPORTANTThis service provides `save` and `check` methods. If you run your tests for the first time you **SHOULD NOT** combine `save` and `compare` methods, the `check`-methods will automatically create a baseline image for you```sh#####################################################################################INFO:Autosaved the image to/Users/wswebcreation/sample/baselineFolder/desktop_chrome/examplePage-chrome-latest-1366x768.png#####################################################################################```When you've [disabled to automatically save baseline images](service-options#autosavebaseline), the Promise will be rejected with the following warning.```sh#####################################################################################Baseline image not found, save the actual image manually to the baseline.The image can be found here:/Users/wswebcreation/sample/.tmp/actual/desktop_chrome/examplePage-chrome-latest-1366x768.png#####################################################################################```This means that the current screenshot is saved in the actual folder and you **manually need to copy it to your baseline**. If you instantiate `@wdio/visual-service` with [`autoSaveBaseline: true`](./service-options#autosavebaseline) the image will automatically be saved into the baseline folder.:::