通过Nightwatch-VRT进行视觉测试:通过测试,元素是捕获的,但看不到图片

发布于 2025-01-21 12:06:54 字数 1962 浏览 3 评论 0原文

我在项目中在本地安装了Nightwatch-vrt。 NPM向我展示了我忽略的多个漏洞。 带有以下内容的

const path = require('path');
const baseConfig = require('./nightwatch.conf.js');

const config = {
    ...baseConfig,
    custom_commands_path: ['node_modules/nightwatch-vrt/commands'],
    custom_assertions_path: ['node_modules/nightwatch-vrt/assertions']
};

function generateScreenshotFilePath(nightwatchClient, basePath, fileName) {
    const moduleName = nightwatchClient.currentTest.module,
        testName = nightwatchClient.currentTest.name;
 
    return path.join(process.cwd(), basePath, moduleName, testName, fileName);
};

config.test_settings.default.globals = {
    "visual_regression_settings": {
        "generate_screenshot_path": generateScreenshotFilePath,
        "latest_screenshots_path": "vrt/latest",
        "latest_suffix": "",
        "baseline_screenshots_path": "vrt/baseline",
        "baseline_suffix": "",
        "diff_screenshots_path": "vrt/diff",
        "diff_suffix": "",
        "threshold": 0.5,
        "prompt": false,
        "always_save_diff_screenshot": true
    }
}

module.exports = config;

Nightwatch.vrt.conf.js

module.exports = {

    tags: ['x'],

    'visual testing':function(browser) {
        browser
            .url('https://www.kraeuter-und-duftpflanzen.de')
            .maximizeWindow()
            .assert.visible('.header-main')
            .pause(1000)
            .assert.screenshotIdenticalToBaseline('.header-main')
            //.saveScreenshot('./tests_output/image.png')
            .end();
    }
}

我创建了一个 那里,但是我只能看到一个带有芯片板模式的字段(例如捕获元素的大小)。 在这样的测试报告消息显示之前:

[32644:26476:0414/082519.134:ERROR:device_event_log_impl.cc(214)] [08:25:19.134] 
USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: 
Ein an das System angeschlossenes Gerõt funktioniert nicht. (0x1F)

如果我让NightWatch本身进行屏幕截图,则将正确显示。 有人知道吗,错误在哪里?

I installed nightwatch-vrt locally in my project. Npm showed me multiple vulnerities which I ignored.
I created a nightwatch.vrt.conf.js with the following content:

const path = require('path');
const baseConfig = require('./nightwatch.conf.js');

const config = {
    ...baseConfig,
    custom_commands_path: ['node_modules/nightwatch-vrt/commands'],
    custom_assertions_path: ['node_modules/nightwatch-vrt/assertions']
};

function generateScreenshotFilePath(nightwatchClient, basePath, fileName) {
    const moduleName = nightwatchClient.currentTest.module,
        testName = nightwatchClient.currentTest.name;
 
    return path.join(process.cwd(), basePath, moduleName, testName, fileName);
};

config.test_settings.default.globals = {
    "visual_regression_settings": {
        "generate_screenshot_path": generateScreenshotFilePath,
        "latest_screenshots_path": "vrt/latest",
        "latest_suffix": "",
        "baseline_screenshots_path": "vrt/baseline",
        "baseline_suffix": "",
        "diff_screenshots_path": "vrt/diff",
        "diff_suffix": "",
        "threshold": 0.5,
        "prompt": false,
        "always_save_diff_screenshot": true
    }
}

module.exports = config;

My test (simple, just to see if it works) looks like:

module.exports = {

    tags: ['x'],

    'visual testing':function(browser) {
        browser
            .url('https://www.kraeuter-und-duftpflanzen.de')
            .maximizeWindow()
            .assert.visible('.header-main')
            .pause(1000)
            .assert.screenshotIdenticalToBaseline('.header-main')
            //.saveScreenshot('./tests_output/image.png')
            .end();
    }
}

Now the test passes, no assertions failed, a folder is created and the file is correctly named placed there, but I can only see an field with checkerboard pattern (like the transparent background in vector graphics) in the size of the captured element.
Before the test report messages like this are shown:

[32644:26476:0414/082519.134:ERROR:device_event_log_impl.cc(214)] [08:25:19.134] 
USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: 
Ein an das System angeschlossenes Gerõt funktioniert nicht. (0x1F)

If I let Nightwatch take a screenshot itself, it is displayed correctly.
Does anyone know, where's the mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾其所爱 2025-01-28 12:06:54

看来该软件包被打破了,很长一段时间内都没有更新。我建议您更新到此 https:// https:///www.npmjs.com/ppackage/ppackage /@bbc/nightwatch-vrt

it seems that this package is broken and not updated for a very very long time. I advise you to update to this one https://www.npmjs.com/package/@bbc/nightwatch-vrt

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文