webdriverio / visual-testing

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

Can't use @wdio/visual-service via remote options #221

Closed Kiattikhun-W closed 7 months ago

Kiattikhun-W commented 8 months ago

Environment (please complete the following information):

Config of WebdriverIO + @wdio/visual-service

import { remote } from "webdriverio";
import VisualService from "@wdio/visual-service";

let visualService = new VisualService({
  autoSaveBaseline: true,
});

const browser = await remote({
  logLevel: "silent",
  capabilities: {
    browserName: "chrome",
    browserVersion: "dev",
  },
});

await visualService.before(browser.capabilities);
await browser.url("https://webdriver.io/");

// or use this for ONLY saving a screenshot
await browser.saveFullPageScreen("examplePaged", {});

// or use this for validating. Both methods don't need to be combined, see the FAQ
await browser.checkFullPageScreen("examplePaged", {});

await browser.deleteSession();

Describe the bug error at await visualService.before(browser.capabilities);

file:///F:/Wdio-test/node_modules/@wdio/visual-service/dist/utils.js:176
    if (driver.isMobile) {
               ^

TypeError: Cannot read properties of undefined (reading 'isMobile')
    at determineNativeContext (file:///F:/Wdio-test/node_modules/@wdio/visual-service/dist/utils.js:176:16)
    at WdioImageComparisonService.before (file:///F:/Wdio-test/node_modules/@wdio/visual-service/dist/service.js:30:33)
    at file:///F:/Wdio-test/visual-test.js:16:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

To Reproduce Steps to reproduce the behavior:

Expected behavior Able to use the function of visual-testing service.

wswebcreation commented 8 months ago

Hi @Kiattikhun-W

Thanks for submitting an issue, I've already created a Pull Request for this, see https://github.com/webdriverio/visual-testing/pull/219. I'm waiting for a review and hope to release it this week.

wswebcreation commented 7 months ago

Hi @Kiattikhun-W

We've released a new version, please try the latest one and make sure you use it like this

import { remote } from 'webdriverio'
import VisualService from '@wdio/visual-service'

let visualService = new VisualService({
    autoSaveBaseline: true
})

const browser = await remote({
    logLevel: 'silent',
    capabilities: {
        browserName: 'chrome',
    }
})

// "Start" the service to add the custom commands to the `browser`
visualService.remoteSetup(browser)

await browser.url('https://webdriver.io/')

// or use this for ONLY saving a screenshot
await browser.saveFullPageScreen('examplePaged', {})

// or use this for validating. Both methods don't need to be combined, see the FAQ
await browser.checkFullPageScreen('examplePaged', {})

await browser.deleteSession()