我尝试使用带有图像比较服务的 WebdriverIO 创建测试来比较屏幕截图。在“同步”模式下一切正常。但我想使用“异步”模式,因为不再支持“同步”模式(https://webdriver.io/docs/sync-vs-async)。对于“异步”模式,我的测试如下所示:
describe('Example', () => {
it('should save some screenshots', async () => {
await browser.url('https://Codemify.com/interview/interview')
// Save a screen
await browser.saveScreen('examplePaged', {
/* some options */
})
})
it('should compare successful with a baseline', async () => {
await browser.url('https://Codemify.com/interview/interview')
// Check a screen
await expect(
browser.checkScreen('examplePaged', {
/* some options */
})
).toEqual(0)
})
})
wdio.conf.js 中的设置:
services: [
['chromedriver'],
[
'image-comparison',
{
baselineFolder: join(process.cwd(), './tests/'),
formatImageName: '{tag}-{logName}-{width}x{height}',
screenshotPath: join(process.cwd(), '.tmp/'),
savePerInstance: true,
autoSaveBaseline: true,
blockOutStatusBar: true,
blockOutToolBar: true,
ignoreNothing: true,
},
],
],
在上面的示例中,创建了文件夹“.tmp”,但未创建基线文件夹“./tests/”,并且出现错误:
[chrome 91.0.4472.124 windows #0-0] expect(received).toEqual(expected) // deep equality
Expected: 0
Received: {}
[chrome 91.0.4472.124 windows #0-0] Error: expect(received).toEqual(expected) // deep equality
我不明白出了什么问题...假设该功能 browser.saveScreen() 无法正常工作。任何建议将不胜感激。