Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
How to access response body correctly when using Playwright?

I am new to Playwright and js so I'm a bit lost here. I want to be able to send a request and then check status, content of response, headers, etc.

I thought I would be able to do something like

  test('blah', async ({ request }) => {
    await request.get('http://localhost:444').then(res => {
      expect(res.status()).toBe(200)
      expect(res.headers()['content-type']).toBe('application/octet-stream')
      expect(res.json()).toContain('foo')
    })
  })

but this doesn't work and the expect sees res.json() as "{}" and if I try to print the response to console with console.log(res.json()) I get back Promise { <pending> }

I eventually got my test working properly by using the below code but it seems messy to me and I dont know why I have to do this? am I doing this correctly? or am I way off?

test('blah', async ({ request }) => {
    await request.get('http://localhost:4444/')
      .then(res => {
        expect(res.status()).toBe(200)
        return res.json()
      })
      .then(json => {
        expect(JSON.stringify(json)).toContain('foo')
      })
  })
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!