Skip to content

[BUG] page.screenshot doesn't create folder if needed #2930

@leandromuto

Description

@leandromuto

Context:

  • Playwright Version: 1.2.0
  • Operating System: Mac
  • Node version: 12.13.0
  • Browser: Chromium
  • Extra: using playwright-video plugin

Code Snippet

const { chromium } = require('playwright')
const { saveVideo } = require('playwright-video');

describe('user', function() {

  beforeEach(async function() {
    // await saveVideo(page, `/tmp/video/${this.test.ctx.currentTest.title.replace(' ', '_')}.mp4`);
  })

  afterEach(async function() {
    await page.screenshot({ path: `/tmp/${this.test.ctx.currentTest.title}.png` })
  })

  describe('edit', function() {
    it('user info', async function() {
     ...
    })
  })
}

Describe the bug

I'm using Mocha to run my tests and I'm trying to store the screenshots taken on a tmp folder on the project root. If the folder doesn't exist, page.screenshot returns the following error:

Error: ENOENT: no such file or directory, open 'tmp/user info.png'
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
    -- ASYNC --
      at Page.screenshot (node_modules/playwright/lib/helper.js:78:23)
      at Context.<anonymous> (test/mocha/user.js:62:16)
      at processImmediate (internal/timers.js:439:21)

PoC
In the first run, I had saveVideo function being called, and it created the tmp folder on the root. In the second run, I commented the saveVideo line and removed the previously created folder to see if page.screenshot were able to create a new folder. Recorded a video to demonstrate the scenario. 👇

https://www.loom.com/share/4f6fe2f6289e41d09e27a40d02a7f54d

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions