WebdriverIO - Take full-page screenshot

两盒软妹~` 提交于 2019-12-03 16:47:07

This can probably be done in quite a handful of ways, but the most straight forward way would be via the wdio-screenshot WebdriverIO plugin.

  1. Install the plugin: npm install --save-dev wdio-screenshot
  2. Enable the plugin in the wdio.conf.js file in the plugings object: plugins: { 'wdio-screenshot': {} }
  3. Inside your test, add the following step (for a document(full-page screenshot): browser.saveDocumentScreenshot('<screenShotsPath>/screenshotName.png');

> The full-page screenshot looks like this for an Instagram feed attempt. (left the screenshot inline for obvious reasons)

  • !Note-001: If you don't want your screenshot to look like that, then I recommend you use some waitUntil to guarantee your content has loaded & rendered successfully.

  • !Note-002: wdio-screenshot supports 3 types of screenshots (viewport (standard), document (full-page) & element (element-targeted)).

@mags : I see that you need screenshots to understand the failure points. I would like to share what i use for screenshots.

  1. Integrate allure report to the wdio.conf file like this reporterOptions: { allure: { outputDir: "allure-results" },

  2. Install allure using npm install @wdio/allure-reporter --save-dev

  3. After you execute your test suite, run this command to generate allure results allure generate ./allure-results --clean

  4. Once the above command execution is complete, run the command allure open.

  5. Now for any test failed, allure will also show you the screenshot captured. Please see a sample screenshot attached

have you tried passing a higher div id and take a screen shot of that

browser
    .init()
    .url("https://search.yahoo.com")
    .webdrivercss('startpage',[
            {
                name: 'fullpage',
                elem: '#purple-syc'
            }

edit: I am also able to see full page screenhot when doing

.saveScreenshot('./webdrivercss.png');

use .scroll('#myElement') to scroll and take screen shot again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!